|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# This program will manage servers; Changing RAM, CPU cores, Growing virtual disks, adding virtual disks,
|
|
|
|
# inserting and ejecting ISO images into virtual optical media.
|
|
|
|
#
|
|
|
|
# Exit codes;
|
|
|
|
# 0 = Normal exit.
|
|
|
|
# 1 = No database connection.
|
|
|
|
#
|
|
|
|
# TODO:
|
|
|
|
#
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Anvil::Tools;
|
|
|
|
require POSIX;
|
|
|
|
use Term::Cap;
|
|
|
|
|
|
|
|
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0];
|
|
|
|
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0];
|
|
|
|
if (($running_directory =~ /^\./) && ($ENV{PWD}))
|
|
|
|
{
|
|
|
|
$running_directory =~ s/^\./$ENV{PWD}/;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
|
|
|
|
$| = 1;
|
|
|
|
|
|
|
|
my $anvil = Anvil::Tools->new();
|
|
|
|
|
|
|
|
$anvil->data->{switches}{anvil} = ""; # This is the Anvil! Name or UUID being worked on.
|
|
|
|
$anvil->data->{switches}{boot} = ""; # This is a comma-separated list of ordered boot devices
|
|
|
|
$anvil->data->{switches}{cores} = ""; # This sets the server to use this number of CPU cores.
|
|
|
|
$anvil->data->{switches}{drive} = ""; # drive being modified (insert/eject ISO, growing drive)
|
|
|
|
$anvil->data->{switches}{eject} = ""; # This will eject whatever ISO (if any) in the '--drive'.
|
|
|
|
$anvil->data->{switches}{'expand-to'} = ""; # When the drive is a disk (backed by a DRBD resource), this is the new desired size to grow to.
|
|
|
|
$anvil->data->{switches}{insert} = ""; # This is the ISO to insert into the --drive
|
|
|
|
$anvil->data->{switches}{'job-uuid'} = "";
|
|
|
|
$anvil->data->{switches}{ram} = ""; # This is the amount of RAM to set the server to use.
|
|
|
|
$anvil->data->{switches}{server} = ""; # server name or uuid
|
|
|
|
$anvil->data->{switches}{y} = ""; # Don't prompt for confirmation. Only useful when there isn't a job UUID.
|
|
|
|
$anvil->Get->switches;
|
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
|
|
|
'switches::boot' => $anvil->data->{switches}{boot},
|
|
|
|
'switches::cores' => $anvil->data->{switches}{cores},
|
|
|
|
'switches::drive' => $anvil->data->{switches}{drive},
|
|
|
|
'switches::eject' => $anvil->data->{switches}{eject},
|
|
|
|
'switches::expand-to' => $anvil->data->{switches}{'expand-to'},
|
|
|
|
'switches::insert' => $anvil->data->{switches}{insert},
|
|
|
|
'switches::job-uuid' => $anvil->data->{switches}{'job-uuid'},
|
|
|
|
'switches::ram' => $anvil->data->{switches}{ram},
|
|
|
|
'switches::server' => $anvil->data->{switches}{server},
|
|
|
|
'switches::y' => $anvil->data->{switches}{y},
|
|
|
|
}});
|
|
|
|
|
|
|
|
# Connect to the database(s). If we have no connections, we'll proceed anyway as one of the 'run_once' tasks
|
|
|
|
# is to setup the database server.
|
|
|
|
$anvil->Database->connect();
|
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
|
|
|
|
if (not $anvil->data->{sys}{database}{connections})
|
|
|
|
{
|
|
|
|
# No databases, update the job, sleep for a bit and then exit. The daemon will pick it up and try
|
|
|
|
# again after we exit.
|
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0305"});
|
|
|
|
sleep 10;
|
|
|
|
$anvil->nice_exit({exit_code => 1});
|
|
|
|
}
|
|
|
|
|
|
|
|
# If we don't have a job UUID, try to find one.
|
|
|
|
if (not $anvil->data->{switches}{'job-uuid'})
|
|
|
|
{
|
|
|
|
# Load the job data.
|
|
|
|
$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'} }});
|
|
|
|
}
|
|
|
|
|
|
|
|
# If we still don't have a job-uuit, go into interactive mode.
|
|
|
|
if ($anvil->data->{switches}{'job-uuid'})
|
|
|
|
{
|
|
|
|
# Load the job data.
|
|
|
|
$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_0251",
|
|
|
|
});
|
|
|
|
|
|
|
|
# Job data will be in $anvil->data->{jobs}{job_data}
|
|
|
|
run_jobs($anvil);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# Interactive!
|
|
|
|
interactive_question($anvil);
|
|
|
|
}
|
|
|
|
|
|
|
|
$anvil->nice_exit({exit_code => 0});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=cut
|
|
|
|
# Make sure we're in an Anvil!
|
|
|
|
$anvil->data->{sys}{anvil_uuid} = $anvil->Cluster->get_anvil_uuid();
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
|
|
|
'sys::anvil_uuid' => $anvil->data->{sys}{anvil_uuid},
|
|
|
|
}});
|
|
|
|
if (not $anvil->data->{sys}{anvil_uuid})
|
|
|
|
{
|
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0260"});
|
|
|
|
$anvil->Job->update_progress({progress => 100, message => "error_0260"});
|
|
|
|
$anvil->nice_exit({exit_code => 1});
|
|
|
|
}
|
|
|
|
|
|
|
|
# Load servers and resources.
|
|
|
|
$anvil->Database->get_servers();
|
|
|
|
$anvil->DRBD->gather_data({debug => 2});
|
|
|
|
$anvil->Get->available_resources({
|
|
|
|
debug => 2,
|
|
|
|
anvil_uuid => $anvil->data->{sys}{anvil_uuid},
|
|
|
|
});
|
|
|
|
|
|
|
|
# Do we have a server (name or UUID)?
|
|
|
|
if ($anvil->Validate->uuid({uuid => $anvil->data->{switches}{server}}))
|
|
|
|
{
|
|
|
|
$anvil->data->{sys}{server_uuid} = $anvil->data->{switches}{server};
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
|
|
|
"sys::server_uuid" => $anvil->data->{sys}{server_uuid},
|
|
|
|
}});
|
|
|
|
|
|
|
|
# Find the server name
|
|
|
|
my $server_uuid = $anvil->data->{sys}{server_uuid};
|
|
|
|
if (exists $anvil->data->{servers}{server_uuid}{$server_uuid})
|
|
|
|
{
|
|
|
|
$anvil->data->{sys}{server_name} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_name};
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
|
|
|
"sys::server_name" => $anvil->data->{sys}{server_name},
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($anvil->data->{switches}{server})
|
|
|
|
{
|
|
|
|
$anvil->data->{sys}{server_name} = $anvil->data->{switches}{server};
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
|
|
|
"sys::server_name" => $anvil->data->{sys}{server_name},
|
|
|
|
}});
|
|
|
|
|
|
|
|
# Get the server UUID.
|
|
|
|
my $anvil_uuid = $anvil->data->{sys}{anvil_uuid};
|
|
|
|
my $server_name = $anvil->data->{sys}{server_name};
|
|
|
|
if (exists $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server_name})
|
|
|
|
{
|
|
|
|
$anvil->data->{sys}{server_uuid} = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server_name}{server_uuid};
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
|
|
|
"sys::server_uuid" => $anvil->data->{sys}{server_uuid},
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Do we have a valid server?
|
|
|
|
if ((not $anvil->data->{sys}{server_name}) or (not $anvil->data->{sys}{server_uuid}))
|
|
|
|
{
|
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "message_0247"});
|
|
|
|
|
|
|
|
my $anvil_uuid = $anvil->data->{sys}{anvil_uuid};
|
|
|
|
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};
|
|
|
|
print "- ".$server_name." (".$server_uuid.")\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Show the server's existing stats.
|
|
|
|
show_stats($anvil);
|
|
|
|
=cut
|
|
|
|
|
|
|
|
$anvil->nice_exit({exit_code => 0});
|
|
|
|
|
|
|
|
|
|
|
|
#############################################################################################################
|
|
|
|
# Functions #
|
|
|
|
#############################################################################################################
|
|
|
|
|
|
|
|
sub run_jobs
|
|
|
|
{
|
|
|
|
my ($anvil) = @_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub interactive_question
|
|
|
|
{
|
|
|
|
my ($anvil) = @_;
|
|
|
|
|
|
|
|
$anvil->Database->get_hosts();
|
|
|
|
$anvil->Database->get_anvils();
|
|
|
|
$anvil->Database->get_servers();
|
|
|
|
|
|
|
|
$anvil->data->{target_server}{server_uuid} = "" if not defined $anvil->data->{target_server}{server_uuid};
|
|
|
|
$anvil->data->{target_server}{server_name} = "" if not defined $anvil->data->{target_server}{server_name};
|
|
|
|
$anvil->data->{target_server}{server_state} = "" if not defined $anvil->data->{target_server}{server_state};
|
|
|
|
$anvil->data->{target_server}{anvil_uuid} = "" if not defined $anvil->data->{target_server}{anvil_uuid};
|
|
|
|
$anvil->data->{target_server}{anvil_name} = "" if not defined $anvil->data->{target_server}{anvil_name};
|
|
|
|
$anvil->data->{target_server}{anvil_description} = "" if not defined $anvil->data->{target_server}{anvil_description};
|
|
|
|
$anvil->data->{target_server}{anvil_node1_host_uuid} = "" if not defined $anvil->data->{target_server}{anvil_node1_host_uuid};
|
|
|
|
$anvil->data->{target_server}{anvil_node1_host_name} = "" if not defined $anvil->data->{target_server}{anvil_node1_host_name};
|
|
|
|
$anvil->data->{target_server}{anvil_node2_host_uuid} = "" if not defined $anvil->data->{target_server}{anvil_node2_host_uuid};
|
|
|
|
$anvil->data->{target_server}{anvil_node2_host_name} = "" if not defined $anvil->data->{target_server}{anvil_node2_host_name};
|
|
|
|
$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};
|
|
|
|
|
|
|
|
### 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.
|
|
|
|
if ($anvil->data->{switches}{server})
|
|
|
|
{
|
|
|
|
if ($anvil->Validate->uuid({uuid => $anvil->data->{switches}{server}}))
|
|
|
|
{
|
|
|
|
$anvil->data->{target_server}{server_uuid} = $anvil->data->{switches}{server};
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
|
|
|
"target_server::server_uuid" => $anvil->data->{target_server}{server_uuid},
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$anvil->data->{target_server}{server_name} = $anvil->data->{switches}{server};
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
|
|
|
"target_server::server_name" => $anvil->data->{target_server}{server_name},
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# If we have a server UUID, make sure it's valid.
|
|
|
|
if ($anvil->data->{target_server}{server_uuid})
|
|
|
|
{
|
|
|
|
# Pull up the server data.
|
|
|
|
my $server_uuid = $anvil->data->{target_server}{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_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->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};
|
|
|
|
$anvil->data->{target_server}{anvil_node1_host_name} = $anvil->data->{hosts}{host_uuid}{$node1_host_uuid}{host_name};
|
|
|
|
$anvil->data->{target_server}{anvil_node2_host_uuid} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid};
|
|
|
|
$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};
|
|
|
|
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};;
|
|
|
|
}
|
|
|
|
|
|
|
|
### Pull out details pf the server.
|
|
|
|
# How much RAM are we using and how much is configured?
|
|
|
|
$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};
|
|
|
|
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->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;
|
|
|
|
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};
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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};
|
|
|
|
$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,
|
|
|
|
}});
|
|
|
|
|
|
|
|
if ($file_type eq "iso")
|
|
|
|
{
|
|
|
|
# ISO image
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# (Potential) script
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# $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},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_post_migration_arguments" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_post_migration_arguments},
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
|
|
|
# "hosts::host_uuid::${host_uuid}::host_name" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_name},
|
|
|
|
# "hosts::host_uuid::${host_uuid}::short_host_name" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{short_host_name},
|
|
|
|
# "hosts::host_uuid::${host_uuid}::host_type" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type},
|
|
|
|
# "hosts::host_uuid::${host_uuid}::host_key" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_key},
|
|
|
|
# "hosts::host_uuid::${host_uuid}::host_ipmi" => $host_ipmi =~ /passw/ ? $anvil->Log->is_secure($anvil->data->{hosts}{host_uuid}{$host_uuid}{host_ipmi}) : $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_ipmi},
|
|
|
|
# "hosts::host_uuid::${host_uuid}::host_status" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_status},
|
|
|
|
# "hosts::host_uuid::${host_uuid}::anvil_name" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name},
|
|
|
|
# "hosts::host_uuid::${host_uuid}::anvil_uuid" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_uuid},
|
|
|
|
# }});
|
|
|
|
# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
|
|
|
# "anvils::anvil_uuid::${anvil_uuid}::anvil_name" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name},
|
|
|
|
# "anvils::anvil_uuid::${anvil_uuid}::anvil_description" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_description},
|
|
|
|
# "anvils::anvil_uuid::${anvil_uuid}::anvil_password" => $anvil->Log->is_secure($anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_password}),
|
|
|
|
# "anvils::anvil_uuid::${anvil_uuid}::anvil_node1_host_uuid" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid},
|
|
|
|
# "anvils::anvil_uuid::${anvil_uuid}::anvil_node2_host_uuid" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid},
|
|
|
|
# "anvils::anvil_uuid::${anvil_uuid}::anvil_dr1_host_uuid" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid},
|
|
|
|
# }});
|
|
|
|
# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_anvil_uuid" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_anvil_uuid},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_user_stop" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_user_stop},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_start_after_server_uuid" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_start_after_server_uuid},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_start_delay" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_start_delay},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_host_uuid" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_host_uuid},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_state" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_live_migration" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_live_migration},
|
|
|
|
# "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},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_post_migration_arguments" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_post_migration_arguments},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_ram_in_use" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_ram_in_use},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_configured_ram" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_configured_ram},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_updated_by_user" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_updated_by_user},
|
|
|
|
# "servers::server_uuid::${server_uuid}::server_boot_time" => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_boot_time},
|
|
|
|
# }});
|
|
|
|
|
|
|
|
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
|
|
|
"target_server::server_name" => $anvil->data->{target_server}{server_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'} : "";
|
|
|
|
|
|
|
|
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},
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif (not $anvil->data->{target_server}{anvil_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} }});
|
|
|
|
}
|
|
|
|
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 this is a node, load the anvil_uuid automatically.
|
|
|
|
|
|
|
|
my $termios = new POSIX::Termios;
|
|
|
|
$termios->getattr;
|
|
|
|
my $ospeed = $termios->getospeed;
|
|
|
|
|
|
|
|
my $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };
|
|
|
|
$terminal->Trequire(qw/ce ku kd/);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub show_stats
|
|
|
|
{
|
|
|
|
my ($anvil) = @_;
|
|
|
|
|
|
|
|
# Load the server's details.
|
|
|
|
my $server_xml = $anvil->Server->get_definition({server_uuid => $anvil->data->{sys}{server_uuid}});
|
|
|
|
my $server_name = $anvil->data->{sys}{server_name};
|
|
|
|
my $short_host_name = $anvil->Get->short_host_name();
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
|
|
|
's1:short_host_name' => $short_host_name,
|
|
|
|
's2:server_name' => $server_name,
|
|
|
|
's3:server_xml' => $server_xml,
|
|
|
|
}});
|
|
|
|
|
|
|
|
$anvil->Server->parse_definition({
|
|
|
|
debug => 2,
|
|
|
|
source => "from_db",
|
|
|
|
definition => $server_xml,
|
|
|
|
server => $server_name,
|
|
|
|
});
|
|
|
|
|
|
|
|
my $cpu_cores = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{cpu}{total_cores};
|
|
|
|
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});
|
|
|
|
print "Cores: [".$cpu_cores."], RAM: [".$say_ram."] (".$ram_bytes." bytes)\n";
|
|
|
|
|
|
|
|
# Show disks
|
|
|
|
foreach my $device ("disk", "cdrom")
|
|
|
|
{
|
|
|
|
print "- Device: [".$device."]\n";
|
|
|
|
foreach my $device_target (sort {$a cmp $b} keys %{$anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{$device}{target}})
|
|
|
|
{
|
|
|
|
my $boot_order = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{$device}{target}{$device_target}{boot_order};
|
|
|
|
my $type = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{$device}{target}{$device_target}{type};
|
|
|
|
my $device_bus = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{$device}{target}{$device_target}{device_bus};
|
|
|
|
my $path = $anvil->data->{server}{$short_host_name}{$server_name}{from_db}{device}{$device}{target}{$device_target}{path};
|
|
|
|
print " - Target: [".$device_target."], type: [".$type."], boot order: [".$boot_order."], bus: [".$device_bus."]\n";
|
|
|
|
print " - Path: [".$path."]\n";
|
|
|
|
if ($device eq "disk")
|
|
|
|
{
|
|
|
|
# Pull the size
|
|
|
|
my $volume = ($path =~ /\/(\d+)$/)[0];
|
|
|
|
print " - Volume: [".$volume."]\n";
|
|
|
|
foreach my $host_name (sort {$a cmp $b} keys %{$anvil->data->{new}{resource}{$server_name}{host}})
|
|
|
|
{
|
|
|
|
my $host_uuid = $anvil->Get->host_uuid_from_name({host_name => $host_name});
|
|
|
|
my $device_path = $anvil->data->{new}{resource}{$server_name}{host}{$host_name}{volume}{$volume}{device_path};
|
|
|
|
my $backing_disk = $anvil->data->{new}{resource}{$server_name}{host}{$host_name}{volume}{$volume}{backing_disk};
|
|
|
|
print " - Host: [".$host_name."] (".$host_uuid."), path: [".$device_path."], backing disk: [".$backing_disk."]\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|