* Updated Database->get_server_definitions() to take a specific server UUID, allowing just the one definition to be loaded. Also had it clear previous loads.

* Updated Server->parse_definition() to call DRBD->get_devices() so that referenced LVs can be loaded properly.
* Continued WIP in anvil-manage-server

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 3 years ago
parent c8f0a20e31
commit 28865780f8
  1. 24
      Anvil/Tools/Database.pm
  2. 3
      Anvil/Tools/Server.pm
  3. 2
      share/words.xml
  4. 550
      tools/anvil-manage-server

@ -4344,7 +4344,11 @@ And;
server_definitions::server_definition_server_uuid::<server_definition_server_uuid>::server_definition_xml server_definitions::server_definition_server_uuid::<server_definition_server_uuid>::server_definition_xml
server_definitions::server_definition_server_uuid::<server_definition_server_uuid>::unix_modified_time server_definitions::server_definition_server_uuid::<server_definition_server_uuid>::unix_modified_time
This method takes no parameters. Parameters;
=head3 server_uuid (optional)
If passed, the definition for the specific server is loaded. Without this, all are loaded.
=cut =cut
sub get_server_definitions sub get_server_definitions
@ -4355,11 +4359,14 @@ sub get_server_definitions
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->get_server_definitions()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->get_server_definitions()" }});
# We're going to include the alert levels for this host based on overrides that might exist in the my $server_uuid = defined $parameter->{server_uuid} ? $parameter->{server_uuid} : "";
# 'notifications' table. If the data hasn't already been loaded, we'll load it now. $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
if (not $anvil->data->{notifications}{notification_uuid}) server_uuid => $server_uuid,
}});
if (exists $anvil->data->{server_definitions})
{ {
$anvil->Database->get_notifications({debug => $debug}); delete $anvil->data->{server_definitions};
} }
my $host_uuid = $anvil->Get->host_uuid(); my $host_uuid = $anvil->Get->host_uuid();
@ -4371,6 +4378,13 @@ SELECT
round(extract(epoch from modified_date)) AS mtime round(extract(epoch from modified_date)) AS mtime
FROM FROM
server_definitions server_definitions
";
if ($server_uuid)
{
$query .= "WHERE
server_definition_server_uuid = ".$anvil->Database->quote($server_uuid)." ";
}
$query .= "
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});

@ -1307,6 +1307,9 @@ sub parse_definition
#print Dumper $server_xml; #print Dumper $server_xml;
#die; #die;
# Get the DRBD data that this server will almost certainly be using.
$anvil->DRBD->get_devices({debug => $debug});
# Pull out some basic server info. # Pull out some basic server info.
$anvil->data->{server}{$target}{$server}{$source}{info}{uuid} = $server_xml->{uuid}->[0]; $anvil->data->{server}{$target}{$server}{$source}{info}{uuid} = $server_xml->{uuid}->[0];
$anvil->data->{server}{$target}{$server}{$source}{info}{name} = $server_xml->{name}->[0]; $anvil->data->{server}{$target}{$server}{$source}{info}{name} = $server_xml->{name}->[0];

@ -1118,6 +1118,8 @@ It should be provisioned in the next minute or two.</key>
<key name="job_0349">Loading the new corosync config exited with return code: [#!variable!return_code!#] and output: [#!variable!output!#]</key> <key name="job_0349">Loading the new corosync config exited with return code: [#!variable!return_code!#] and output: [#!variable!output!#]</key>
<key name="job_0352">Manage a server menu:</key> <key name="job_0352">Manage a server menu:</key>
<key name="job_0353">* Please enter the name of the server you want to manage</key>
<key name="job_0354">-=] Servers available to manage on the Anvil! [#!variable!anvil_name!#] [=-</key>
<!-- Log entries --> <!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key> <key name="log_0001">Starting: [#!variable!program!#].</key>

@ -240,25 +240,166 @@ sub interactive_question
$anvil->data->{target_server}{anvil_dr1_host_uuid} = "" if not defined $anvil->data->{target_server}{anvil_dr1_host_uuid}; $anvil->data->{target_server}{anvil_dr1_host_uuid} = "" if not defined $anvil->data->{target_server}{anvil_dr1_host_uuid};
$anvil->data->{target_server}{anvil_dr1_host_name} = "" if not defined $anvil->data->{target_server}{anvil_dr1_host_name}; $anvil->data->{target_server}{anvil_dr1_host_name} = "" if not defined $anvil->data->{target_server}{anvil_dr1_host_name};
### Anvil
# If 'switches::anvil' is set, see if it's a UUID and then set either 'anvil-uuid' or 'anvil-name'.
if ($anvil->data->{switches}{anvil})
{
if ($anvil->Validate->uuid({uuid => $anvil->data->{switches}{anvil}}))
{
$anvil->data->{target_server}{anvil_uuid} = $anvil->data->{switches}{anvil};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid},
}});
}
else
{
$anvil->data->{target_server}{anvil_name} = $anvil->data->{switches}{anvil};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::anvil_name" => $anvil->data->{target_server}{anvil_name},
}});
}
}
# Do we know or can we find the Anvil! UUID?
$anvil->data->{target_server}{anvil_uuid} = $anvil->data->{switches}{'anvil-uuid'} ? $anvil->data->{switches}{'anvil-uuid'} : "";
$anvil->data->{target_server}{anvil_name} = $anvil->data->{switches}{'anvil-name'} ? $anvil->data->{switches}{'anvil-name'} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::anvil_name" => $anvil->data->{target_server}{anvil_name},
"target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid},
}});
if ((not $anvil->data->{target_server}{anvil_uuid}) && (not $anvil->data->{target_server}{anvil_name}))
{
# Nothing given. Is this host a node, perhaps?
my $anvil_uuid = $anvil->Cluster->get_anvil_uuid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }});
if ($anvil_uuid)
{
$anvil->data->{target_server}{anvil_uuid} = $anvil_uuid;
$anvil->data->{target_server}{anvil_name} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::anvil_name" => $anvil->data->{target_server}{anvil_name},
"target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid},
}});
}
else
{
# If there is only one Anvil!, choose it
my $known_anvils = keys %{$anvil->data->{anvils}{anvil_name}};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { known_anvils => $known_anvils }});
if (not $known_anvils)
{
my $variables = { server_uuid => $anvil->data->{target_server}{server_uuid} };
$anvil->Jobs->update_progress({
progress => 100,
message => "error_0321",
job_status => "failed",
log_level => 1,
priority => "err",
});
$anvil->nice_exit({exit_code => 1});
}
elsif ($known_anvils == 1)
{
foreach my $anvil_name (keys %{$anvil->data->{anvils}{anvil_name}})
{
$anvil->data->{target_server}{anvil_name} = $anvil_name;
$anvil->data->{target_server}{anvil_uuid} = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::anvil_name" => $anvil->data->{target_server}{anvil_name},
"target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid},
}});
}
}
}
}
elsif (not $anvil->data->{target_server}{anvil_uuid})
{
# We have a name, get the UUID.
$anvil->data->{target_server}{anvil_uuid} = $anvil->Cluster->get_anvil_uuid({anvil_name => $anvil->data->{target_server}{anvil_name}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid} }});
# If the name is bad, error out if not interactive
if (not $anvil->data->{target_server}{anvil_uuid})
{
# Bad server UUID. If it's a job, abort. Otherwise, clear and go back to
my $variables = { anvil_name => $anvil->data->{target_server}{anvil_name} };
$anvil->Jobs->update_progress({
progress => 100,
message => "error_0319",
variables => $variables,
job_status => "failed",
log_level => 1,
priority => "err",
});
if ($anvil->data->{switches}{'job-uuid'})
{
$anvil->nice_exit({exit_code => 1});
}
$anvil->data->{target_server}{anvil_name} = "";
}
}
elsif (not $anvil->data->{target_server}{anvil_name})
{
$anvil->data->{target_server}{anvil_name} = $anvil->Cluster->get_anvil_name({anvil_uuid => $anvil->data->{target_server}{anvil_uuid}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "target_server::anvil_name" => $anvil->data->{target_server}{anvil_name} }});
# If the name is bad, error out if not interactive
if (not $anvil->data->{target_server}{anvil_name})
{
# Bad server UUID. If it's a job, abort. Otherwise, clear and go back to
my $variables = { anvil_uuid => $anvil->data->{target_server}{anvil_uuid} };
$anvil->Jobs->update_progress({
progress => 100,
message => "error_0320",
variables => $variables,
job_status => "failed",
log_level => 1,
priority => "err",
});
if ($anvil->data->{switches}{'job-uuid'})
{
$anvil->nice_exit({exit_code => 1});
}
$anvil->data->{target_server}{anvil_uuid} = "";
}
}
### Server ### Server
# First, has the user specified a server? If so, and if it's by name, make sure it's unique. If the # First, has the user specified a server? If so, and if it's by name, make sure it's unique. If the
# name exists on two or more Anvil! systems, we'll need an Anvil! name as well. If it's unique, we # name exists on two or more Anvil! systems, we'll need an Anvil! name as well. If it's unique, we
# can devine the Anvil! UUID. # can devine the Anvil! UUID.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"switches::server" => $anvil->data->{switches}{server},
}});
if ($anvil->data->{switches}{server}) if ($anvil->data->{switches}{server})
{ {
if ($anvil->Validate->uuid({uuid => $anvil->data->{switches}{server}})) my $server = $anvil->data->{switches}{server};
if ($anvil->Validate->uuid({uuid => $server}))
{ {
$anvil->data->{target_server}{server_uuid} = $anvil->data->{switches}{server}; $anvil->data->{target_server}{server_uuid} = $server;
$anvil->data->{target_server}{server_name} = exists $anvil->data->{servers}{server_uuid}{$server} ? $anvil->data->{servers}{server_uuid}{$server}{server_name} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::server_uuid" => $anvil->data->{target_server}{server_uuid}, "target_server::server_uuid" => $anvil->data->{target_server}{server_uuid},
"target_server::server_name" => $anvil->data->{target_server}{server_name},
}}); }});
} }
else else
{ {
$anvil->data->{target_server}{server_name} = $anvil->data->{switches}{server}; $anvil->data->{target_server}{server_name} = $server;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::server_name" => $anvil->data->{target_server}{server_name}, "target_server::server_name" => $anvil->data->{target_server}{server_name},
}}); }});
if ($anvil->data->{target_server}{anvil_uuid})
{
my $anvil_uuid = $anvil->data->{target_server}{anvil_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }});
$anvil->data->{target_server}{server_uuid} = exists $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server} ? $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server}{server_uuid} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::server_uuid" => $anvil->data->{target_server}{server_uuid},
}});
}
} }
} }
@ -267,18 +408,28 @@ sub interactive_question
{ {
# Pull up the server data. # Pull up the server data.
my $server_uuid = $anvil->data->{target_server}{server_uuid}; my $server_uuid = $anvil->data->{target_server}{server_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_uuid => $server_uuid }});
if (exists $anvil->data->{servers}{server_uuid}{$server_uuid}) if (exists $anvil->data->{servers}{server_uuid}{$server_uuid})
{ {
# We can divine everthing from this. # We can divine everthing from this.
my $anvil_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_anvil_uuid}; my $anvil_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_anvil_uuid};
my $server_name = $anvil->data->{target_server}{server_name};
my $server_host_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_host_uuid}; my $server_host_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_host_uuid};
my $node1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}; my $node1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid};
my $node2_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}; my $node2_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid};
my $dr1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid}; my $dr1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
anvil_uuid => $anvil_uuid,
server_name => $server_name,
server_host_uuid => $server_host_uuid,
node1_host_uuid => $node1_host_uuid,
node2_host_uuid => $node2_host_uuid,
dr1_host_uuid => $dr1_host_uuid,
}});
$anvil->data->{target_server}{anvil_uuid} = $anvil_uuid;
$anvil->data->{target_server}{server_name} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_name}; $anvil->data->{target_server}{server_name} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_name};
$anvil->data->{target_server}{server_state} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state}; $anvil->data->{target_server}{server_state} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->data->{target_server}{anvil_uuid} = $anvil_uuid;
$anvil->data->{target_server}{anvil_name} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name}; $anvil->data->{target_server}{anvil_name} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name};
$anvil->data->{target_server}{anvil_description} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_description}; $anvil->data->{target_server}{anvil_description} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_description};
$anvil->data->{target_server}{anvil_node1_host_uuid} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}; $anvil->data->{target_server}{anvil_node1_host_uuid} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid};
@ -287,10 +438,26 @@ sub interactive_question
$anvil->data->{target_server}{anvil_node2_host_name} = $anvil->data->{hosts}{host_uuid}{$node2_host_uuid}{host_name}; $anvil->data->{target_server}{anvil_node2_host_name} = $anvil->data->{hosts}{host_uuid}{$node2_host_uuid}{host_name};
$anvil->data->{target_server}{anvil_dr1_host_uuid} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}; $anvil->data->{target_server}{anvil_dr1_host_uuid} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid};
$anvil->data->{target_server}{anvil_dr1_host_name} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}; $anvil->data->{target_server}{anvil_dr1_host_name} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid},
"target_server::server_name" => $anvil->data->{target_server}{server_name},
"target_server::server_state" => $anvil->data->{target_server}{server_state},
"target_server::anvil_description" => $anvil->data->{target_server}{anvil_description},
"target_server::anvil_node1_host_uuid" => $anvil->data->{target_server}{anvil_node1_host_uuid},
"target_server::anvil_node1_host_name" => $anvil->data->{target_server}{anvil_node1_host_name},
"target_server::anvil_node2_host_uuid" => $anvil->data->{target_server}{anvil_node2_host_uuid},
"target_server::anvil_node2_host_name" => $anvil->data->{target_server}{anvil_node2_host_name},
"target_server::anvil_dr1_host_uuid" => $anvil->data->{target_server}{anvil_dr1_host_uuid},
"target_server::anvil_dr1_host_name" => $anvil->data->{target_server}{anvil_dr1_host_name},
}});
if ($dr1_host_uuid) if ($dr1_host_uuid)
{ {
$anvil->data->{target_server}{anvil_dr1_host_uuid} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid}; $anvil->data->{target_server}{anvil_dr1_host_uuid} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid};
$anvil->data->{target_server}{anvil_dr1_host_name} = $anvil->data->{hosts}{host_uuid}{$dr1_host_uuid}{host_name};; $anvil->data->{target_server}{anvil_dr1_host_name} = $anvil->data->{hosts}{host_uuid}{$dr1_host_uuid}{host_name};;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::anvil_dr1_host_uuid" => $anvil->data->{target_server}{anvil_dr1_host_uuid},
"target_server::anvil_dr1_host_name" => $anvil->data->{target_server}{anvil_dr1_host_name},
}});
} }
### Pull out details of the server. ### Pull out details of the server.
@ -298,57 +465,174 @@ sub interactive_question
$anvil->data->{target_server}{server_ram_in_use} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_ram_in_use}; $anvil->data->{target_server}{server_ram_in_use} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_ram_in_use};
$anvil->data->{target_server}{server_host_uuid} = $server_host_uuid; $anvil->data->{target_server}{server_host_uuid} = $server_host_uuid;
$anvil->data->{target_server}{server_host_name} = $anvil->data->{hosts}{host_uuid}{$server_host_uuid}{host_name}; $anvil->data->{target_server}{server_host_name} = $anvil->data->{hosts}{host_uuid}{$server_host_uuid}{host_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::server_ram_in_use" => $anvil->Convert->add_commas({number => $anvil->data->{target_server}{server_ram_in_use}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{target_server}{server_ram_in_use}}).")",
"target_server::server_host_uuid" => $anvil->data->{target_server}{server_host_uuid},
"target_server::server_host_name" => $anvil->data->{target_server}{server_host_name},
}});
if ($anvil->data->{target_server}{server_state} eq "shut off") if ($anvil->data->{target_server}{server_state} eq "shut off")
{ {
$anvil->data->{target_server}{server_ram_in_use} = 0; $anvil->data->{target_server}{server_ram_in_use} = 0;
$anvil->data->{target_server}{server_host_uuid} = ""; $anvil->data->{target_server}{server_host_uuid} = "";
$anvil->data->{target_server}{server_host_name} = ""; $anvil->data->{target_server}{server_host_name} = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::server_ram_in_use" => $anvil->Convert->add_commas({number => $anvil->data->{target_server}{server_ram_in_use}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{target_server}{server_ram_in_use}}).")",
"target_server::server_host_uuid" => $anvil->data->{target_server}{server_host_uuid},
"target_server::server_host_name" => $anvil->data->{target_server}{server_host_name},
}});
} }
$anvil->data->{target_server}{server_configured_ram} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_configured_ram}; $anvil->data->{target_server}{server_configured_ram} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_configured_ram};
$anvil->data->{target_server}{server_start_after_server_uuid} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_start_after_server_uuid}; $anvil->data->{target_server}{server_start_after_server_uuid} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_start_after_server_uuid};
$anvil->data->{target_server}{server_start_after_server_name} = ""; $anvil->data->{target_server}{server_start_after_server_name} = "";
$anvil->data->{target_server}{server_start_delay} = 0; $anvil->data->{target_server}{server_start_delay} = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::server_configured_ram" => $anvil->Convert->add_commas({number => $anvil->data->{target_server}{server_configured_ram}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{target_server}{server_configured_ram}}).")",
"target_server::server_start_after_server_uuid" => $anvil->data->{target_server}{server_start_after_server_uuid},
}});
if ($anvil->data->{target_server}{server_start_after_server_uuid}) if ($anvil->data->{target_server}{server_start_after_server_uuid})
{ {
my $server_start_after_server_uuid = $anvil->data->{target_server}{server_start_after_server_uuid}; my $server_start_after_server_uuid = $anvil->data->{target_server}{server_start_after_server_uuid};
$anvil->data->{target_server}{server_start_after_server_name} = $anvil->data->{servers}{server_uuid}{$server_start_after_server_uuid}{server_name}; $anvil->data->{target_server}{server_start_after_server_name} = $anvil->data->{servers}{server_uuid}{$server_start_after_server_uuid}{server_name};
$anvil->data->{target_server}{server_start_delay} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_start_delay}; $anvil->data->{target_server}{server_start_delay} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_start_delay};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::server_start_after_server_name" => $anvil->data->{target_server}{server_start_after_server_name},
"target_server::server_start_delay" => $anvil->data->{target_server}{server_start_delay},
}});
} }
# Get a list of files on this Anvil! # Get a list of files on this Anvil!
foreach my $file_uuid (keys %{$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}}) foreach my $file_uuid (keys %{$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}})
{ {
my $file_name = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_name}; my $file_name = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_name};
my $file_directory = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_directory}; my $file_type = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_type};
my $file_size = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_size}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
my $file_md5sum = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_md5sum}; file_uuid => $file_uuid,
my $file_type = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_type}; file_name => $file_name,
file_type => $file_type,
}});
$anvil->data->{files}{$file_type}{name}{$file_name}{directory} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_directory};
$anvil->data->{files}{$file_type}{name}{$file_name}{file_size} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_size};
$anvil->data->{files}{$file_type}{name}{$file_name}{md5sum} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_md5sum};
$anvil->data->{files}{$file_type}{name}{$file_name}{file_uuid} = $file_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"files::${file_type}::name::${file_name}::directory" => $anvil->data->{files}{$file_type}{name}{$file_name}{directory},
"files::${file_type}::name::${file_name}::file_size" => $anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->Convert->add_commas({number => $anvil->data->{files}{$file_type}{name}{$file_name}{file_size}})})." (".$anvil->data->{files}{$file_type}{name}{$file_name}{file_size}.")",
"files::${file_type}::name::${file_name}::md5sum" => $anvil->data->{files}{$file_type}{name}{$file_name}{md5sum},
"files::${file_type}::name::${file_name}::file_uuid" => $anvil->data->{files}{$file_type}{name}{$file_name}{file_uuid},
}});
}
# Get and parse the server's definition.
$anvil->Database->get_server_definitions({
debug => 2,
server_uuid => $server_uuid,
});
my $short_host_name = $anvil->Get->short_host_name();
my $definition_uuid = $anvil->data->{server_definitions}{server_definition_server_uuid}{$server_uuid}{server_definition_uuid};
my $definition_xml = $anvil->data->{server_definitions}{server_definition_server_uuid}{$server_uuid}{server_definition_xml};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
's1:short_host_name' => $short_host_name,
's2:definition_uuid' => $definition_uuid,
's3:definition_xml' => $definition_xml,
}});
$anvil->Server->parse_definition({
debug => 2,
source => "from_db",
server => $anvil->data->{target_server}{server_name},
definition => $definition_xml,
host => $short_host_name,
});
my $cpu_sockets = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{cpu}{sockets};
my $cpu_threads = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{cpu}{threads};
my $ram_bytes = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{memory};
my $say_ram = $anvil->Convert->bytes_to_human_readable({'bytes' => $ram_bytes});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:cpu_sockets' => $cpu_sockets,
's2:cpu_threads' => $cpu_threads,
's3:ram_bytes' => $ram_bytes,
's4:say_ram' => $say_ram,
}});
$anvil->data->{target_server}{server_cpu_sockets} = $cpu_sockets if not defined $anvil->data->{target_server}{server_cpu_sockets};
$anvil->data->{target_server}{server_cpu_cores} = $cpu_threads if not defined $anvil->data->{target_server}{server_cpu_cores};
$anvil->data->{target_server}{server_ram} = $say_ram if not defined $anvil->data->{target_server}{server_ram};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:target_server::server_cpu_sockets' => $anvil->data->{target_server}{server_cpu_sockets},
's2:target_server::server_cpu_cores' => $anvil->data->{target_server}{server_cpu_cores},
's3:target_server::server_ram' => $anvil->data->{target_server}{server_ram},
}});
# server::an-a02n01::srv02-c8s-fujitsu:: from_db::device::disk::target::vda
foreach my $target (sort {$a cmp $b} keys %{$anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{disk}{target}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { target => $target }});
$anvil->data->{target_server}{disk}{$target}{device_bus} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{disk}{target}{$target}{device_bus};
$anvil->data->{target_server}{disk}{$target}{boot_order} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{disk}{target}{$target}{boot_order} ? $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{disk}{target}{$target}{boot_order} : 0;
$anvil->data->{target_server}{disk}{$target}{cache} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{disk}{target}{$target}{driver}{cache};
$anvil->data->{target_server}{disk}{$target}{io} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{disk}{target}{$target}{driver}{io};
$anvil->data->{target_server}{disk}{$target}{path} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{disk}{target}{$target}{path};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
file_name => $file_name, "target_server::disk::${target}::device_bus" => $anvil->data->{target_server}{disk}{$target}{device_bus},
file_directory => $file_directory, "target_server::disk::${target}::boot_order" => $anvil->data->{target_server}{disk}{$target}{boot_order},
file_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $file_size})." (".$anvil->Convert->add_commas({number => $file_size}).")", "target_server::disk::${target}::cache" => $anvil->data->{target_server}{disk}{$target}{cache},
file_md5sum => $file_md5sum, "target_server::disk::${target}::io" => $anvil->data->{target_server}{disk}{$target}{io},
file_type => $file_type, "target_server::disk::${target}::path" => $anvil->data->{target_server}{disk}{$target}{path},
}}); }});
if ($file_type eq "iso") if ($anvil->data->{target_server}{disk}{$target}{boot_order})
{ {
# ISO image my $boot_order = $anvil->data->{target_server}{disk}{$target}{boot_order};
$anvil->data->{target_server}{boot}{$boot_order}{$target} = $anvil->data->{target_server}{disk}{$target}{path};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::boot::${boot_order}::${target}" => $anvil->data->{target_server}{boot}{$boot_order}{$target},
}});
} }
else }
foreach my $target (sort {$a cmp $b} keys %{$anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{cdrom}{target}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { target => $target }});
$anvil->data->{target_server}{cdrom}{$target}{device_bus} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{cdrom}{target}{$target}{device_bus};
$anvil->data->{target_server}{cdrom}{$target}{boot_order} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{cdrom}{target}{$target}{boot_order} ? $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{cdrom}{target}{$target}{boot_order} : 0;
$anvil->data->{target_server}{cdrom}{$target}{path} = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{cdrom}{target}{$target}{path};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::cdrom::${target}::device_bus" => $anvil->data->{target_server}{cdrom}{$target}{device_bus},
"target_server::cdrom::${target}::boot_order" => $anvil->data->{target_server}{cdrom}{$target}{boot_order},
"target_server::cdrom::${target}::path" => $anvil->data->{target_server}{cdrom}{$target}{path},
}});
if ($anvil->data->{target_server}{cdrom}{$target}{boot_order})
{ {
# (Potential) script my $boot_order = $anvil->data->{target_server}{cdrom}{$target}{boot_order};
$anvil->data->{target_server}{boot}{$boot_order}{$target} = $anvil->data->{target_server}{cdrom}{$target}{path};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::boot::${boot_order}::${target}" => $anvil->data->{target_server}{boot}{$boot_order}{$target},
}});
} }
} }
=cut
# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 2021/07/20 22:08:12:Server.pm:1664; Variables:
# "anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_name" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_name}, |- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::address::bus: [0]
# "anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_directory" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_directory}, |- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::address::type: [drive]
# "anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_size" => $anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_size}})." (".$anvil->Convert->add_commas({number => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_size}}).")", |- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::alias: ....... [sata0-0-0]
# "anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_md5sum" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_md5sum}, |- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::boot_order: .. [2]
# "anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_type" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_type}, |- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::device_bus: .. [sata]
# }}); |- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::driver::name: [qemu]
# |- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::driver::type: [raw]
\- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::type: ........ [file]
2021/07/20 22:08:12:Server.pm:1751; Variables:
|- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::address::controller: [0]
|- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::address::target: ... [0]
|- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::address::unit: ..... [0]
\- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::path: .............. [/mnt/shared/files/CentOS-Stream-8-x86_64-20201211-dvd1.iso]
=cut
# "servers::server_uuid::${server_uuid}::server_pre_migration_file_uuid" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_pre_migration_file_uuid}, # "servers::server_uuid::${server_uuid}::server_pre_migration_file_uuid" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_pre_migration_file_uuid},
# "servers::server_uuid::${server_uuid}::server_pre_migration_arguments" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_pre_migration_arguments}, # "servers::server_uuid::${server_uuid}::server_pre_migration_arguments" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_pre_migration_arguments},
# "servers::server_uuid::${server_uuid}::server_post_migration_file_uuid" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_post_migration_file_uuid}, # "servers::server_uuid::${server_uuid}::server_post_migration_file_uuid" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_post_migration_file_uuid},
@ -415,126 +699,6 @@ sub interactive_question
} }
} }
### Anvil
# If 'switches::anvil' is set, see if it's a UUID and then set either 'anvil-uuid' or 'anvil-name'.
if ($anvil->data->{switches}{anvil})
{
if ($anvil->Validate->uuid({uuid => $anvil->data->{switches}{anvil}}))
{
$anvil->data->{target_server}{anvil_uuid} = $anvil->data->{switches}{anvil};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid},
}});
}
else
{
$anvil->data->{target_server}{anvil_name} = $anvil->data->{switches}{anvil};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::anvil_name" => $anvil->data->{target_server}{anvil_name},
}});
}
}
# Do we know or can we find the Anvil! UUID?
$anvil->data->{target_server}{anvil_uuid} = $anvil->data->{switches}{'anvil-uuid'} ? $anvil->data->{switches}{'anvil-uuid'} : "";
$anvil->data->{target_server}{anvil_name} = $anvil->data->{switches}{'anvil-name'} ? $anvil->data->{switches}{'anvil-name'} : "";
if ((not $anvil->data->{target_server}{anvil_uuid}) && (not $anvil->data->{target_server}{anvil_name}))
{
# Nothing given. Is this host a node, perhaps?
my $anvil_uuid = $anvil->Cluster->get_anvil_uuid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }});
if ($anvil_uuid)
{
$anvil->data->{target_server}{anvil_uuid} = $anvil_uuid;
$anvil->data->{target_server}{anvil_name} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::anvil_name" => $anvil->data->{target_server}{anvil_name},
"target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid},
}});
}
else
{
# If there is only one Anvil!, choose it
my $known_anvils = keys %{$anvil->data->{anvils}{anvil_name}};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { known_anvils => $known_anvils }});
if (not $known_anvils)
my $variables = { server_uuid => $anvil->data->{target_server}{server_uuid} };
$anvil->Jobs->update_progress({
progress => 100,
message => "error_0321",
job_status => "failed",
log_level => 1,
priority => "err",
});
$anvil->nice_exit({exit_code => 1});
}
elsif ($known_anvils == 1)
{
foreach my $anvil_name (keys %{$anvil->data->{anvils}{anvil_name}})
{
$anvil->data->{target_server}{anvil_name} = $anvil_name;
$anvil->data->{target_server}{anvil_uuid} = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::anvil_name" => $anvil->data->{target_server}{anvil_name},
"target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid},
}});
}
}
}
}
elsif (not $anvil->data->{target_server}{anvil_uuid})
{
# We have a name, get the UUID.
$anvil->data->{target_server}{anvil_uuid} = $anvil->Cluster->get_anvil_uuid({anvil_name => $anvil->data->{target_server}{anvil_name}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid} }});
# If the name is bad, error out if not interactive
if (not $anvil->data->{target_server}{anvil_uuid})
{
# Bad server UUID. If it's a job, abort. Otherwise, clear and go back to
my $variables = { anvil_name => $anvil->data->{target_server}{anvil_name} };
$anvil->Jobs->update_progress({
progress => 100,
message => "error_0319",
variables => $variables,
job_status => "failed",
log_level => 1,
priority => "err",
});
if ($anvil->data->{switches}{'job-uuid'})
{
$anvil->nice_exit({exit_code => 1});
}
$anvil->data->{target_server}{anvil_name} = "";
}
}
elsif (not $anvil->data->{target_server}{anvil_name})
{
$anvil->data->{target_server}{anvil_name} = $anvil->Cluster->get_anvil_name({anvil_uuid => $anvil->data->{target_server}{anvil_uuid}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "target_server::anvil_name" => $anvil->data->{target_server}{anvil_name} }});
# If the name is bad, error out if not interactive
if (not $anvil->data->{target_server}{anvil_name})
{
# Bad server UUID. If it's a job, abort. Otherwise, clear and go back to
my $variables = { anvil_uuid => $anvil->data->{target_server}{anvil_uuid} };
$anvil->Jobs->update_progress({
progress => 100,
message => "error_0320",
variables => $variables,
job_status => "failed",
log_level => 1,
priority => "err",
});
if ($anvil->data->{switches}{'job-uuid'})
{
$anvil->nice_exit({exit_code => 1});
}
$anvil->data->{target_server}{anvil_uuid} = "";
}
}
# If we don't have an Anvil! UUID at this point, we need to ask the user. # If we don't have an Anvil! UUID at this point, we need to ask the user.
my $termios = new POSIX::Termios; my $termios = new POSIX::Termios;
$termios->getattr; $termios->getattr;
@ -547,6 +711,10 @@ sub interactive_question
{ {
interactive_ask_anvil_name($anvil, $terminal); interactive_ask_anvil_name($anvil, $terminal);
} }
if (not $anvil->data->{target_server}{server_uuid})
{
interactive_ask_server_name($anvil, $terminal);
}
return(0); return(0);
} }
@ -558,6 +726,11 @@ sub interactive_ask_anvil_name
my $retry = 0; my $retry = 0;
while(1) while(1)
{ {
my $default = "";
if ($anvil->data->{target_server}{anvil_name})
{
$default = $anvil->data->{target_server}{anvil_name};
}
print $terminal->Tputs('cl'); print $terminal->Tputs('cl');
print $anvil->Words->string({key => "job_0352"})."\n"; print $anvil->Words->string({key => "job_0352"})."\n";
print $anvil->Words->string({key => "job_0151", variables => { anvil_name => $anvil->data->{target_server}{anvil_name} }})."\n\n\n"; print $anvil->Words->string({key => "job_0151", variables => { anvil_name => $anvil->data->{target_server}{anvil_name} }})."\n\n\n";
@ -578,9 +751,9 @@ sub interactive_ask_anvil_name
chomp $answer; chomp $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }});
if ((not $answer) && ($default_anvil)) if ((not $answer) && ($default))
{ {
$answer = $default_anvil; $answer = $default;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }});
} }
@ -615,35 +788,26 @@ sub interactive_ask_server_name
### TODO: Figure out how many rows we have and break the server list into columns if too long. ### TODO: Figure out how many rows we have and break the server list into columns if too long.
my $retry = 0; my $retry = 0;
my $duplicate = ""; my $not_found = "";
while(1) while(1)
{ {
my $default = ""; my $default = "";
if ($anvil->data->{switches}{name}) if ($anvil->data->{target_server}{server_name})
{ {
$default = $anvil->data->{switches}{name}; $default = $anvil->data->{target_server}{server_name};
} }
print $terminal->Tputs('cl'); print $terminal->Tputs('cl');
print $anvil->Words->string({key => "job_0150"})."\n"; print $anvil->Words->string({key => "job_0352"})."\n";
print $anvil->Words->string({key => "job_0151", variables => { anvil_name => $anvil->data->{target_server}{anvil_name} }})."\n"; print $anvil->Words->string({key => "job_0151", variables => { anvil_name => $anvil->data->{target_server}{anvil_name} }})."\n";
print $anvil->Words->string({key => "job_0157", variables => { server_name => $anvil->data->{target_server}{name} }})."\n\n\n"; print $anvil->Words->string({key => "job_0157", variables => { server_name => $anvil->data->{target_server}{server_name} }})."\n\n\n";
# Show all the current server names. # Show all the current server names.
if ($retry) if ($retry)
{ {
if ($duplicate) print $anvil->Words->string({key => "job_0353"})."\n\n";
{
print $anvil->Words->string({key => "job_0219", variables => { server_name => $duplicate }})."\n\n";
$duplicate = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { duplicate => $duplicate }});
}
else
{
print $anvil->Words->string({key => "job_0159"})."\n\n";
}
} }
my $anvil_uuid = $anvil->data->{target_server}{anvil_uuid}; my $anvil_uuid = $anvil->data->{target_server}{anvil_uuid};
print $anvil->Words->string({key => "job_0160", variables => { anvil_name => $anvil->data->{target_server}{anvil_name} }})."\n"; print $anvil->Words->string({key => "job_0354", variables => { anvil_name => $anvil->data->{target_server}{anvil_name} }})."\n";
foreach my $server_name (sort {$a cmp $b} keys %{$anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}}) foreach my $server_name (sort {$a cmp $b} keys %{$anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}})
{ {
my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server_name}{server_uuid}; my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server_name}{server_uuid};
@ -652,18 +816,12 @@ sub interactive_ask_server_name
server_uuid => $server_uuid, server_uuid => $server_uuid,
server_state => $server_state, server_state => $server_state,
}}); }});
if ($server_state eq "DELETED") next if $server_state eq "DELETED";
{
### NOTE: This could get cluttered, so for now we'll not show them. print $anvil->Words->string({key => "message_0219", variables => {
#print $anvil->Words->string({key => "message_0220", variables => { server_name => $server_name }})."\n"; server_name => $server_name,
} server_state => $server_state,
else }})."\n";
{
print $anvil->Words->string({key => "message_0219", variables => {
server_name => $server_name,
server_state => $server_state,
}})."\n";
}
} }
print $terminal->Tgoto('cm', 0, 3)."? "; print $terminal->Tgoto('cm', 0, 3)."? ";
@ -681,41 +839,24 @@ sub interactive_ask_server_name
$anvil->Database->get_servers(); $anvil->Database->get_servers();
if ($answer) if ($answer)
{ {
# Duplicate? # Found?
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }});
if (exists $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$answer}) if (exists $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$answer})
{ {
my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$answer}{server_uuid}; # Valid
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state}; $anvil->data->{target_server}{server_name} = $answer;
$anvil->data->{target_server}{server_uuid} = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$answer}{server_uuid};
$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, "target_server::server_name" => $anvil->data->{target_server}{server_name},
server_state => $server_state, "target_server::server_uuid" => $anvil->data->{target_server}{server_uuid},
}}); }});
if ($server_state eq "DELETED") last;
{
# Valid, we can re-use deleted server names. We'll also re-use the
# UUID, if the user didn't specifically specify a UUID.
$anvil->data->{target_server}{name} = $answer;
$anvil->data->{target_server}{uuid} = $server_uuid if not $anvil->data->{target_server}{uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::name" => $anvil->data->{target_server}{name},
"target_server::uuid" => $anvil->data->{target_server}{uuid},
}});
}
else
{
# Invalid, duplicate.
$duplicate = $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { duplicate => $duplicate }});
}
} }
else else
{ {
# Valid. # Inalid.
$anvil->data->{target_server}{name} = $answer; $not_found = $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { not_found => $not_found }});
"target_server::name" => $anvil->data->{target_server}{name},
}});
} }
last; last;
} }
@ -724,6 +865,7 @@ sub interactive_ask_server_name
$retry = 1; $retry = 1;
} }
} }
interactive_question($anvil);
return(0); return(0);
} }

Loading…
Cancel
Save