fix(tools): allow striker-manage-vnc-pipes to be executed as a job

main
Tsu-ba-me 3 years ago
parent 0935b9a990
commit 7d9013a60b
  1. 8
      share/words.xml
  2. 147
      tools/striker-manage-vnc-pipes

@ -424,6 +424,11 @@ The attempt to start the servers appears to have failed. The return code '0' was
<key name="error_0310">I tried to remove the fence delay from the node: [#!variable!node!#], but it doesn't appear to have worked. The preferred node is: [#!variable!current!#] ('--' means there is no preferred node)</key> <key name="error_0310">I tried to remove the fence delay from the node: [#!variable!node!#], but it doesn't appear to have worked. The preferred node is: [#!variable!current!#] ('--' means there is no preferred node)</key>
<key name="error_0311">Failed to find the UUID column for the table: [#!variable!table!#].</key> <key name="error_0311">Failed to find the UUID column for the table: [#!variable!table!#].</key>
<key name="error_0312">The 'set_to' parameter: [#!variable!set_to!#] is invalid. It must be 'yes' or 'no'.</key> <key name="error_0312">The 'set_to' parameter: [#!variable!set_to!#] is invalid. It must be 'yes' or 'no'.</key>
<key name="error_0313">While opening VNC pipe, failed to get server VM information with [#!variable!server_uuid!#] and [#!variable!host_uuid!#].</key>
<key name="error_0314">While opening VNC pipe, failed to get server VM VNC information with [#!variable!server_uuid!#] and [#!variable!host_uuid!#].</key>
<key name="error_0315">While opening VNC pipe, failed to get websockify instance information with [#!variable!server_uuid!#] and [#!variable!host_uuid!#].</key>
<key name="error_0316">While opening VNC pipe, failed to get SSH tunnel instance information with [#!variable!server_uuid!#] and [#!variable!host_uuid!#].</key>
<key name="error_0317">While closing VNC pipe, failed to get VNC pipe information with [#!variable!server_uuid!#] and [#!variable!host_uuid!#].</key>
<key name="error_0318">The server UUID: [#!variable!server_uuid!#] is not valid or was not found in the database.</key> <key name="error_0318">The server UUID: [#!variable!server_uuid!#] is not valid or was not found in the database.</key>
<key name="error_0319">The Anvil! name: [#!variable!anvil_name!#] was not found in the database.</key> <key name="error_0319">The Anvil! name: [#!variable!anvil_name!#] was not found in the database.</key>
<key name="error_0320">The Anvil! UUID: [#!variable!anvil_uuid!#] is not valid or was not found in the database.</key> <key name="error_0320">The Anvil! UUID: [#!variable!anvil_uuid!#] is not valid or was not found in the database.</key>
@ -2223,6 +2228,9 @@ Are you sure that you want to delete the server: [#!variable!server_name!#]? [Ty
<key name="message_0256">[ #!variable!number!# ]- #!variable!server_name!# - (Current state: [#!variable!server_state!#])</key> <key name="message_0256">[ #!variable!number!# ]- #!variable!server_name!# - (Current state: [#!variable!server_state!#])</key>
<key name="message_0257">-=] Please select the Anvil! hosting the server you want to manage [=-</key> <key name="message_0257">-=] Please select the Anvil! hosting the server you want to manage [=-</key>
<key name="message_0258">[ #!variable!number!# ]- #!variable!anvil_name!# - #!variable!anvil_description!#</key> <key name="message_0258">[ #!variable!number!# ]- #!variable!anvil_name!# - #!variable!anvil_description!#</key>
<key name="message_0259">Preparing to manage VNC pipes.</key>
<key name="message_0260">Finished [#!variable!operation!#] VNC pipe for server UUID [#!variable!server_uuid!#] from host UUID [#!variable!host_uuid!#].</key>
<key name="message_0261">Finished dropping VNC pipes table.</key>
<!-- Success messages shown to the user --> <!-- Success messages shown to the user -->
<key name="ok_0001">Saved the mail server information successfully!</key> <key name="ok_0001">Saved the mail server information successfully!</key>

@ -798,16 +798,22 @@ sub open_vnc_pipe
{ {
my $parameters = shift; my $parameters = shift;
my $server_uuid = $parameters->{server_uuid}; my $server_uuid = $parameters->{server_uuid};
my $host_uuid = $anvil->Get->host_uuid(); my $host_uuid = $parameters->{host_uuid};
my $vnc_pipe_info; my $vnc_pipe_info;
my $server_info = get_server_info({ server_uuid => $server_uuid }); my $server_info = get_server_info({ server_uuid => $server_uuid });
if (not defined $server_info) if (not defined $server_info)
{ {
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 1, key => "error_0313", variables => {
message => "Failed to get server VM information." server_uuid => $server_uuid,
host_uuid => $host_uuid
} }); } });
$anvil->Job->update_progress({
progress => 100,
message => "error_0313,!!server_uuid!".$server_uuid."!!,!!host_uuid!".$host_uuid."!!",
job_status => "failed"
});
return; return;
} }
@ -816,9 +822,15 @@ sub open_vnc_pipe
if (not defined $vnc_info) if (not defined $vnc_info)
{ {
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 1, key => "error_0314", variables => {
message => "Failed to get server VM VNC information." server_uuid => $server_uuid,
host_uuid => $host_uuid
} }); } });
$anvil->Job->update_progress({
progress => 100,
message => "error_0314,!!server_uuid!".$server_uuid."!!,!!host_uuid!".$host_uuid."!!",
job_status => "failed"
});
return; return;
} }
@ -832,9 +844,15 @@ sub open_vnc_pipe
if (not defined $ws_info) if (not defined $ws_info)
{ {
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 1, key => "error_0315", variables => {
message => "Failed to get websockify instance information." server_uuid => $server_uuid,
host_uuid => $host_uuid
} }); } });
$anvil->Job->update_progress({
progress => 100,
message => "error_0315,!!server_uuid!".$server_uuid."!!,!!host_uuid!".$host_uuid."!!",
job_status => "failed"
});
return; return;
} }
@ -849,9 +867,15 @@ sub open_vnc_pipe
if (not defined $ssh_tunnel_info) if (not defined $ssh_tunnel_info)
{ {
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 1, key => "error_0316", variables => {
message => "Failed to get SSH tunnel instance information." server_uuid => $server_uuid,
host_uuid => $host_uuid
} }); } });
$anvil->Job->update_progress({
progress => 100,
message => "error_0316,!!server_uuid!".$server_uuid."!!,!!host_uuid!".$host_uuid."!!",
job_status => "failed"
});
return; return;
} }
@ -893,7 +917,12 @@ sub open_vnc_pipe
} }
} }
$vnc_pipe_info = { forward_port => $ssh_tunnel_info->{forward_port} }; $anvil->Job->update_progress({
progress => 100,
message => "message_0257,!!operation!opening!!,!!server_uuid!".$server_uuid."!!,!!host_uuid!".$host_uuid."!!"
});
$vnc_pipe_info = { forward_port => defined $ssh_tunnel_info->{forward_port} ? $ssh_tunnel_info->{forward_port} : "" };
return $vnc_pipe_info; return $vnc_pipe_info;
} }
@ -902,14 +931,20 @@ sub close_vnc_pipe
{ {
my $parameters = shift; my $parameters = shift;
my $server_uuid = $parameters->{server_uuid}; my $server_uuid = $parameters->{server_uuid};
my $vnc_pipe_parameters = { server_uuid => $server_uuid, host_uuid => $anvil->Get->host_uuid() }; my $host_uuid = $parameters->{host_uuid};
my $vnc_pipe_info = get_vnc_pipe($vnc_pipe_parameters); my $vnc_pipe_info = get_vnc_pipe($parameters);
if (not defined $vnc_pipe_info) if (not defined $vnc_pipe_info)
{ {
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 1, key => "error_0317", variables => {
message => "Failed to get VNC pipe information." server_uuid => $server_uuid,
host_uuid => $host_uuid
} }); } });
$anvil->Job->update_progress({
progress => 100,
message => "error_0317,!!server_uuid!".$server_uuid."!!,!!host_uuid!".$host_uuid."!!",
job_status => "failed"
});
return; return;
} }
@ -921,7 +956,12 @@ sub close_vnc_pipe
stop_ssh_tunnel({ ssh_tunnel_pid => $vnc_pipe_info->{ssh_tunnel_pid} }); stop_ssh_tunnel({ ssh_tunnel_pid => $vnc_pipe_info->{ssh_tunnel_pid} });
delete_vnc_pipe($vnc_pipe_parameters); delete_vnc_pipe($parameters);
$anvil->Job->update_progress({
progress => 100,
message => "message_0257,!!operation!closing!!,!!server_uuid!".$server_uuid."!!,!!host_uuid!".$host_uuid."!!"
});
} }
$anvil->Get->switches; $anvil->Get->switches;
@ -935,37 +975,90 @@ if (not $anvil->data->{sys}{database}{connections})
$anvil->nice_exit({ exit_code => 1 }); $anvil->nice_exit({ exit_code => 1 });
} }
# Try to get a job UUID if not given.
if (not $anvil->data->{switches}{'job-uuid'})
{
$anvil->data->{switches}{'job-uuid'} = $anvil->Job->get_job_uuid({ program => $THIS_FILE });
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
"switches::job-uuid" => $anvil->data->{switches}{'job-uuid'}
} });
}
# Handle this script as a job when job UUID is provided.
if ($anvil->data->{switches}{'job-uuid'})
{
$anvil->Job->clear();
$anvil->Job->get_job_details();
$anvil->Job->update_progress({
progress => 1,
job_picked_up_by => $$,
job_picked_up_at => time,
message => "message_0256"
});
foreach my $line (split/\n/, $anvil->data->{jobs}{job_data})
{
if ($line =~ /server-uuid=(.*?)$/)
{
$anvil->data->{switches}{'power-off'} = $1;
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
'switches::server-uuid' => $anvil->data->{switches}{'server-uuid'}
} });
}
if ($line =~ /open=(.*?)$/)
{
$anvil->data->{switches}{'open'} = $1;
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
'switches::open' => $anvil->data->{switches}{'open'}
} });
}
if ($line =~ /drop-table=(.*?)$/)
{
$anvil->data->{switches}{'drop-table'} = $1;
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
'switches::drop-table' => $anvil->data->{switches}{'drop-table'}
} });
}
}
}
$anvil->Database->get_hosts(); $anvil->Database->get_hosts();
$anvil->Database->get_anvils(); $anvil->Database->get_anvils();
my $server_uuid = $anvil->data->{switches}{'server-uuid'};
my $is_open = $anvil->data->{switches}{'open'};
my $is_drop_table = $anvil->data->{switches}{'drop-table'};
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
server_uuid => $server_uuid, server_uuid => $anvil->data->{switches}{'server-uuid'},
is_open => $is_open, is_open => $anvil->data->{switches}{'open'},
is_drop_table => $is_drop_table is_drop_table => $anvil->data->{switches}{'drop-table'}
} }); } });
if ($server_uuid) if ($anvil->data->{switches}{'server-uuid'})
{ {
create_vnc_pipes_table(); create_vnc_pipes_table();
my $vnc_pipe_parameters = { server_uuid => $server_uuid }; my $vnc_pipe_parameters = {
server_uuid => $anvil->data->{switches}{'server-uuid'},
host_uuid => $anvil->Get->host_uuid()
};
if ($is_open) if ($anvil->data->{switches}{'open'})
{ {
my $vnc_pipe_info = open_vnc_pipe($vnc_pipe_parameters); my $vnc_pipe_info = open_vnc_pipe($vnc_pipe_parameters);
print "protocol:ws,forward_port:".$vnc_pipe_info->{forward_port}."\n"; if (not $anvil->data->{switches}{'job-uuid'})
{
print "protocol:ws,forward_port:".$vnc_pipe_info->{forward_port}."\n";
}
} }
else else
{ {
close_vnc_pipe($vnc_pipe_parameters); close_vnc_pipe($vnc_pipe_parameters);
} }
} }
elsif ($is_drop_table) elsif ($anvil->data->{switches}{'drop-table'})
{ {
drop_vnc_pipes_table(); drop_vnc_pipes_table();
$anvil->Job->update_progress({ progress => 100, message => "message_0258" });
} }

Loading…
Cancel
Save