@ -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_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
# 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
# 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->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 => {
"target_server::server_uuid" => $anvil->data->{target_server}{server_uuid},
"target_server::server_name" => $anvil->data->{target_server}{server_name},
}});
}
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 => {
"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.
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})
{
# We can divine everthing from this.
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 $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 $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_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_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};
@ -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_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->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)
{
$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->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.
@ -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_host_uuid} = $server_host_uuid;
$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")
{
$anvil->data->{target_server}{server_ram_in_use} = 0;
$anvil->data->{target_server}{server_host_uuid} = "";
$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_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_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})
{
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_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!
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_directory = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_directory};
my $file_size = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_size};
my $file_md5sum = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_md5sum};
my $file_type = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_type};
my $file_name = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_name};
my $file_type = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_type};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
file_name => $file_name,
file_directory => $file_directory,
file_size => $anvil->Convert->bytes_to_human_readable({'bytes' => $file_size})." (".$anvil->Convert->add_commas({number => $file_size}).")",
file_md5sum => $file_md5sum,
file_type => $file_type,
file_uuid => $file_uuid,
file_name => $file_name,
file_type => $file_type,
}});
if ($file_type eq "iso")
$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 => {
"target_server::disk::${target}::device_bus" => $anvil->data->{target_server}{disk}{$target}{device_bus},
"target_server::disk::${target}::boot_order" => $anvil->data->{target_server}{disk}{$target}{boot_order},
"target_server::disk::${target}::cache" => $anvil->data->{target_server}{disk}{$target}{cache},
"target_server::disk::${target}::io" => $anvil->data->{target_server}{disk}{$target}{io},
"target_server::disk::${target}::path" => $anvil->data->{target_server}{disk}{$target}{path},
}});
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
2021/07/20 22:08:12:Server.pm:1664; Variables:
|- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::address::bus: [0]
|- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::address::type: [drive]
|- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::alias: ....... [sata0-0-0]
|- server::an-a02n01::srv02-c8s-fujitsu::from_db::device::cdrom::target::sda::boot_order: .. [2]
|- 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
# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
# "anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_name" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_name},
# "anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_directory" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_directory},
# "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}}).")",
# "anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_md5sum" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_md5sum},
# "anvils::anvil_uuid::${anvil_uuid}::file_uuid::${file_uuid}::file_type" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_type},
# }});
#
# "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_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.
my $termios = new POSIX::Termios;
$termios->getattr;
@ -547,6 +711,10 @@ sub interactive_question
{
interactive_ask_anvil_name($anvil, $terminal);
}
if (not $anvil->data->{target_server}{server_uuid})
{
interactive_ask_server_name($anvil, $terminal);
}
return(0);
}
@ -558,6 +726,11 @@ sub interactive_ask_anvil_name
my $retry = 0;
while(1)
{
my $default = "";
if ($anvil->data->{target_server}{anvil_name})
{
$default = $anvil->data->{target_server}{anvil_name};
}
print $terminal->Tputs('cl');
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";
@ -578,9 +751,9 @@ sub interactive_ask_anvil_name
chomp $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 }});
}
@ -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.
my $retry = 0;
my $duplicate = "";
my $not_found = "";
while(1)
{
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 $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_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.
if ($retry)
{
if ($duplicate)
{
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";
}
print $anvil->Words->string({key => "job_0353"})."\n\n";
}
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}})
{
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_state => $server_state,
}});
if ($server_state eq "DELETED")
{
### NOTE: This could get cluttered, so for now we'll not show them.
#print $anvil->Words->string({key => "message_0220", variables => { server_name => $server_name }})."\n";
}
else
{
print $anvil->Words->string({key => "message_0219", variables => {
server_name => $server_name,
server_state => $server_state,
}})."\n";
}
next if $server_state eq "DELETED";
print $anvil->Words->string({key => "message_0219", variables => {
server_name => $server_name,
server_state => $server_state,
}})."\n";
}
print $terminal->Tgoto('cm', 0, 3)."? ";
@ -681,41 +839,24 @@ sub interactive_ask_server_name
$anvil->Database->get_servers();
if ($answer)
{
# Duplicate ?
# Found ?
$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})
{
my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$answer}{server_uuid};
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
# Valid
$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 => {
server_uuid => $server_uuid ,
server_state => $server_state,
"target_server::server_name" => $anvil->data->{target_server}{server_name} ,
"target_server::server_uuid" => $anvil->data->{target_server}{server_uuid},
}});
if ($server_state eq "DELETED")
{
# 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 }});
}
last;
}
else
{
# Valid.
$anvil->data->{target_server}{name} = $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"target_server::name" => $anvil->data->{target_server}{name},
}});
# Inalid.
$not_found = $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { not_found => $not_found }});
}
last;
}
@ -724,6 +865,7 @@ sub interactive_ask_server_name
$retry = 1;
}
}
interactive_question($anvil);
return(0);
}