Merge branch 'master' into anvil-tools-dev

main
Digimer 4 years ago committed by GitHub
commit 3b1afa0d92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      cgi-bin/get_anvils
  2. 10
      cgi-bin/get_cpu
  3. 183
      cgi-bin/get_filesystems
  4. 19
      cgi-bin/get_memory
  5. 236
      cgi-bin/get_networks
  6. 20
      cgi-bin/get_servers
  7. 241
      cgi-bin/get_shared_storage
  8. 49
      cgi-bin/get_status
  9. 215
      cgi-bin/set_membership
  10. 2
      cgi-bin/set_power
  11. 8
      share/words.xml

@ -33,6 +33,8 @@ if (not $anvil->data->{sys}{database}{connections})
# Read in any CGI variables, if needed.
$anvil->Get->cgi();
$anvil->Database->get_hosts();
$anvil->Database->get_anvils();
my $json_hash = {};
@ -40,13 +42,25 @@ $json_hash->{anvils} = [];
foreach my $anvil_uuid (keys %{$anvil->data->{anvils}{anvil_uuid}})
{
push @{$json_hash->{anvils}}, { uuid => $anvil_uuid };
my $anvil_name = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name};
my $anvil_description = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_description};
my $anvil_password = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_password};
my $anvil_node1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid};
my $anvil_node1_host_name = $anvil->data->{hosts}{host_uuid}{$anvil_node1_host_uuid}{short_host_name};
my $anvil_node2_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid};
my $anvil_node2_host_name = $anvil->data->{hosts}{host_uuid}{$anvil_node2_host_uuid}{short_host_name};
my $anvil_dr1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid};
my $anvil_dr1_host_name = $anvil->data->{hosts}{host_uuid}{$anvil_dr1_host_uuid}{short_host_name};
push @{$json_hash->{anvils}}, {
anvil_name => $anvil_name,
anvil_uuid => $anvil_uuid,
hosts => [
{ host_name => $anvil_node1_host_name, host_uuid => $anvil_node1_host_uuid },
{ host_name => $anvil_node2_host_name, host_uuid => $anvil_node2_host_uuid },
{ host_name => $anvil_dr1_host_name, host_uuid => $anvil_dr1_host_uuid }
]
};
}
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n";

@ -118,25 +118,27 @@ ORDER BY
scan_hardware_cpu_cores => $scan_hardware_cpu_cores,
scan_hardware_cpu_threads => $scan_hardware_cpu_threads,
}});
# Important: ensure the cores and threads are integers, which will be auto-transformed JSON number type.
if (not $hash->{cores})
{
$hash->{cores} = $scan_hardware_cpu_cores;
$hash->{cores} = int($scan_hardware_cpu_cores);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->cores' => $hash->{cores} }});
}
elsif ($scan_hardware_cpu_cores < $hash->{cores})
{
$hash->{cores} = $scan_hardware_cpu_cores;
$hash->{cores} = int($scan_hardware_cpu_cores);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->cores' => $hash->{cores} }});
}
if (not $hash->{threads})
{
$hash->{threads} = $scan_hardware_cpu_threads;
$hash->{threads} = int($scan_hardware_cpu_threads);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->threads' => $hash->{threads} }});
}
elsif ($scan_hardware_cpu_threads < $hash->{threads})
{
$hash->{threads} = $scan_hardware_cpu_threads;
$hash->{threads} = int($scan_hardware_cpu_threads);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->threads' => $hash->{threads} }});
}
}

@ -0,0 +1,183 @@
#!/usr/bin/perl
#
# This prints JSON formated data reporting the status of an file systems on nodes and DR hosts.
#
use strict;
use warnings;
use Anvil::Tools;
use Data::Dumper;
use JSON;
$| = 1;
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0];
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0];
if (($running_directory =~ /^\./) && ($ENV{PWD}))
{
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $anvil = Anvil::Tools->new();
$anvil->Get->switches;
$anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003"});
$anvil->nice_exit({exit_code => 1});
}
# Read in any CGI variables, if needed.
$anvil->Get->cgi();
$anvil->Database->get_hosts();
$anvil->Database->get_anvils();
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n";
my $hash = { file_systems => [] };
my $anvil_uuid = "";
if ($anvil->data->{cgi}{anvil_uuid}{value})
{
$anvil_uuid = $anvil->data->{cgi}{anvil_uuid}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }});
}
elsif ($anvil->data->{switches}{'anvil-uuid'})
{
$anvil_uuid = $anvil->data->{switches}{'anvil-uuid'};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }});
}
if ((not $anvil_uuid) or (not exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}))
{
$anvil->data->{anvil_status}{anvil_name} = "!!invalid!anvil_uuid!!";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'anvil_status::anvil_name' => $anvil->data->{anvil_status}{anvil_name} }});
}
else
{
my $node1_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid};
my $node2_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid};
my $dr1_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
node1_uuid => $node1_uuid,
node2_uuid => $node2_uuid,
dr1_uuid => $dr1_uuid,
}});
my $query = "
SELECT
a.host_uuid,
a.host_name,
b.scan_filesystem_mount_point,
b.scan_filesystem_size,
b.scan_filesystem_used
FROM
hosts a,
scan_filesystems b
WHERE
a.host_uuid = b.scan_filesystem_host_uuid
AND
(
a.host_uuid = ".$anvil->Database->quote($node1_uuid)."
OR
a.host_uuid = ".$anvil->Database->quote($node2_uuid);
if ($dr1_uuid)
{
$query .= "
OR
a.host_uuid = ".$anvil->Database->quote($dr1_uuid);
}
$query .= "
)
ORDER BY
a.host_name ASC,
b.scan_filesystem_mount_point DESC
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $host_uuid = $row->[0];
my $host_name = $row->[1];
my $mount_point = $row->[2];
my $size = $row->[3];
my $used = $row->[4];
my $free = $size - $used;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
host_uuid => $host_uuid,
host_name => $host_name,
mount_point => $mount_point,
size => $anvil->Convert->add_commas({number => $size})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $size}).")",,
used => $anvil->Convert->add_commas({number => $used})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $used}).")",,
free => $anvil->Convert->add_commas({number => $free})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $free}).")",,
}});
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name} = $host_name;
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total} = $size;
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free} = $free;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"raw::file_systems::${mount_point}::nodes::${host_uuid}::host_name" => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name},
"raw::file_systems::${mount_point}::nodes::${host_uuid}::total" => $anvil->Convert->add_commas({number => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total}}).")",,
"raw::file_systems::${mount_point}::nodes::${host_uuid}::free" => $anvil->Convert->add_commas({number => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free}}).")",,
}});
}
foreach my $mount_point (sort {$a cmp $b} keys %{$anvil->data->{raw}{file_systems}})
{
# Make a FS hash, which will be pushed into the file_systems array in the response body.
my $file_system = {};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mount_point => $mount_point }});
$file_system->{mount_point} = $mount_point;
$file_system->{hosts} = [];
my $nodes = [$node1_uuid, $node2_uuid];
if ($dr1_uuid)
{
push @{$nodes}, $dr1_uuid;
}
foreach my $host_uuid (@{$nodes})
{
my $host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
host_uuid => $host_uuid,
host_name => $host_name,
}});
if (exists $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid})
{
push @{$file_system->{hosts}}, {
host_uuid => $host_uuid,
host_name => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name},
# \1 will be transformed to the JSON boolean "true" by the JSON module.
is_mounted => \1,
# FS total size is required by the spec to be an JSON number rather than string.
total => int($anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total}),
free => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free},
}
}
else
{
push @{$file_system->{hosts}}, {
host_uuid => $host_uuid,
host_name => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_name},
# \0 will be transformed to the JSON boolean "false" by the JSON module.
is_mounted => \0,
total => 0,
free => 0,
}
}
}
# Push the filled FS has into the response body's file_systems array.
push(@{$hash->{file_systems}}, $file_system);
}
}
print JSON->new->utf8->encode($hash)."\n";

@ -40,7 +40,7 @@ $anvil->Database->get_anvils();
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n";
my $target = $anvil->Get->short_host_name();
my $hash = {};
my $hash = { reserved => 68719476736 };
my $anvil_uuid = "";
if ($anvil->data->{cgi}{anvil_uuid}{value})
{
@ -70,7 +70,7 @@ else
$hash->{total} = 0;
$hash->{allocated} = 0;
$hash->{nodes} = [];
$hash->{hosts} = [];
my @hosts = ($node1_uuid, $node2_uuid);
if ($dr1_uuid)
@ -118,24 +118,25 @@ AND
scan_hardware_swap_free => $anvil->Convert->add_commas({number => $scan_hardware_swap_free})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $scan_hardware_swap_free}).")",
}});
# Important: ensure all size values are integers, which will be auto-transformed to JSON number type.
if (not $hash->{total})
{
$hash->{total} = $scan_hardware_ram_total;
$hash->{total} = int($scan_hardware_ram_total);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->total' => $hash->{total} }});
}
elsif ($scan_hardware_ram_total < $hash->{total})
{
$hash->{total} = $scan_hardware_ram_total;
$hash->{total} = int($scan_hardware_ram_total);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->total' => $hash->{total} }});
}
push @{$hash->{nodes}}, {
push @{$hash->{hosts}}, {
host_uuid => $host_uuid,
total => $scan_hardware_ram_total,
free => $scan_hardware_memory_free,
swap_total => $scan_hardware_swap_total,
swap_used => $scan_hardware_swap_free,
total => int($scan_hardware_ram_total),
free => int($scan_hardware_memory_free),
swap_total => int($scan_hardware_swap_total),
swap_used => int($scan_hardware_swap_free),
};
}
}

@ -0,0 +1,236 @@
#!/usr/bin/perl
#
# This prints JSON formatted data about all networks within a specified anvil.
#
use strict;
use warnings;
use Anvil::Tools;
use Data::Dumper;
use JSON;
$| = 1;
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0];
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0];
if (($running_directory =~ /^\./) && ($ENV{PWD}))
{
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $anvil = Anvil::Tools->new();
sub handle_invalid_uuid
{
my $parameters = shift;
my $name = $parameters->{name};
my $uuid = $parameters->{uuid};
$anvil->Log->entry({
source => $THIS_FILE,
line => __LINE__,
level => 0,
'print' => 1,
priority => "err",
key => "error_0160",
variables => { name => $name, uuid => $uuid }
});
$anvil->nice_exit({ exit_code => 1 });
}
sub get_anvil_networks
{
my $parameters = shift;
my $anvil_uuid = $parameters->{anvil_uuid};
my @host_uuids = (
$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid},
$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid}
);
my $anvil_networks = [];
foreach (@host_uuids)
{
my $host_networks = get_host_networks({ host_uuid => $_ });
push(@$anvil_networks, $host_networks);
}
return $anvil_networks;
}
sub get_host_networks
{
my $parameters = shift;
my $host_uuid = $parameters->{host_uuid};
my $host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{short_host_name};
# Note: the subprocess name matches its definition; there is a typo though.
$anvil->Network->load_interfces({ host_uuid => $host_uuid, host => $host_name });
my $host_networks_data = $anvil->data->{network}{$host_name};
my $interfaces = $host_networks_data->{interface};
my $bond_uuids = $host_networks_data->{bond_uuid};
my $bond_uuid_index_map = {};
my $host_networks = {
host_uuid => $host_uuid,
host_name => $host_name,
bonds => []
};
my $build_bond_link_hash = sub {
my $parameters = shift;
my $bond_data = $parameters->{bond_data};
my $link_name = $parameters->{link_name};
my $link_data = $parameters->{link_data};
my $known_links = $parameters->{known_links};
my $link_speed = $link_data->{speed};
my $link_state = $link_data->{operational} eq "up" ? "optimal" : "down";
my $degrade_link_state = sub {
my $current_link_state = shift;
return $current_link_state eq "optimal" ? "degraded" : $current_link_state;
};
# When at lease 1 link has already been processed, check this link against them.
if ($known_links)
{
my $known_links_index = 0;
my $known_links_length = scalar(@$known_links);
foreach (@$known_links)
{
# Degrade the link with lower speed.
if ($_->{link_speed} < $link_speed)
{
$_->{link_state} = &$degrade_link_state($_->{link_state});
}
elsif ($_->{link_state} > $link_speed)
{
$link_state = &$degrade_link_state($link_state);
}
$anvil->Log->variables({
source => $THIS_FILE,
line => __LINE__,
level => 2,
list => {
known_link_name => $_->{link_name},
known_link_speed => $_->{link_speed},
known_link_state => $_->{link_state},
link_speed => $link_speed,
link_name => $link_name,
link_state => $link_state
}
});
}
}
return {
link_name => $link_name,
link_uuid => $link_data->{uuid},
link_speed => $link_speed,
link_state => $link_state,
is_active => $link_name eq $bond_data->{active_interface} ? \1 : \0
};
};
foreach my $interface_name (sort { $a cmp $b } keys %$interfaces)
{
my $interface = $interfaces->{$interface_name};
# Only a bond's link will have the bond_uuid entry.
my $bond_uuid = $interface->{bond_uuid};
if ($bond_uuid)
{
my $bond_name = $bond_uuids->{$bond_uuid}{name};
my $bond_index = $bond_uuid_index_map->{$bond_uuid};
$anvil->Log->variables({
source => $THIS_FILE,
line => __LINE__,
level => 2,
list => {
bond_name => $bond_name,
bond_index => $bond_index
}
});
if (defined $bond_index)
{
my $bond = @{$host_networks->{bonds}}[$bond_index];
push(@{$bond->{links}}, &$build_bond_link_hash({
bond_data => $interfaces->{$bond_name},
link_name => $interface_name,
link_data => $interface,
known_links => $bond->{links}
}));
}
else
{
my $bond = { bond_name => $bond_name, bond_uuid => $bond_uuid, links => [] };
my $link = &$build_bond_link_hash({
bond_data => $interfaces->{$bond_name},
link_name => $interface_name,
link_data => $interface
});
push(@{$bond->{links}}, $link);
push(@{$host_networks->{bonds}}, $bond);
# Get the index of the most recently inserted item and map it to the bond's UUID.
$bond_uuid_index_map->{$bond_uuid} = $#{$host_networks->{bonds}};
}
}
}
return $host_networks;
}
$anvil->Get->switches;
$anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003"});
$anvil->nice_exit({exit_code => 1});
}
# Read in any CGI variables, if needed.
$anvil->Get->cgi();
$anvil->Database->get_hosts();
$anvil->Database->get_anvils();
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n";
my $anvil_uuid = exists $anvil->data->{cgi}{anvil_uuid}{value} ? $anvil->data->{cgi}{anvil_uuid}{value} : $anvil->data->{switches}{'anvil-uuid'};
my $anvil_uuid_variable_name = "anvil UUID";
my $response_body = {};
if ($anvil_uuid)
{
if (exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})
{
my $anvil_networks = get_anvil_networks({ anvil_uuid => $anvil_uuid });
$response_body->{hosts} = $anvil_networks;
}
else
{
handle_invalid_uuid({ name => $anvil_uuid_variable_name, uuid => $anvil_uuid });
}
}
else
{
handle_invalid_uuid({ name => $anvil_uuid_variable_name, uuid => $anvil_uuid });
}
print JSON->new->utf8->encode($response_body)."\n";

@ -109,29 +109,11 @@ WHERE
# Ignore deleted servers.
next if $server_state eq "DELETED";
my $server_host_index = undef;
if ($server_state ne "shut off")
{
if ($server_host_uuid eq $node1_uuid)
{
$server_host_index = 0;
}
elsif ($server_host_uuid eq $node2_uuid)
{
$server_host_index = 1;
}
else
{
# Is it on DR?
}
}
push @{$hash->{servers}}, {
server_uuid => $server_uuid,
server_name => $server_name,
server_state => $server_state,
server_host_uuid => $server_state eq "shut off" ? undef : $server_host_uuid,
server_host_index => $server_host_index,
server_host_uuid => $server_state eq "shut off" ? undef : $server_host_uuid
};
}
}

@ -1,7 +1,7 @@
#!/usr/bin/perl
#
# This prints JSON formated data reporting the status of an file systems on nodes and DR hosts.
#
#
# Prints JSON formatted data reporting the status of shared storage (a.k.a. storage groups/shared VGs)
#
use strict;
use warnings;
@ -20,6 +20,88 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
my $anvil = Anvil::Tools->new();
sub handle_invalid_uuid
{
my $parameters = shift;
my $name = $parameters->{name};
my $uuid = $parameters->{uuid};
$anvil->Log->entry({
source => $THIS_FILE,
line => __LINE__,
level => 0,
'print' => 1,
priority => "err",
key => "error_0160",
variables => { name => $name, uuid => $uuid }
});
$anvil->nice_exit({ exit_code => 1 });
}
sub get_storage_groups
{
my $parameters = shift;
my $anvil_uuid = $parameters->{anvil_uuid};
my $storage_groups = [];
# Use DISTINCT ON (...) to limit the occurence of a storage group to 1 and
# ORDER BY [free] ASC to only select the storage with lowest free space.
my $query = "
SELECT
DISTINCT ON (sgr.storage_group_uuid) storage_group_uuid,
sgr.storage_group_name,
slv.scan_lvm_vg_size,
slv.scan_lvm_vg_free
FROM
anvils anv,
storage_groups sgr,
storage_group_members sgm,
scan_lvm_vgs slv
WHERE
anv.anvil_uuid = sgr.storage_group_anvil_uuid
AND
sgr.storage_group_uuid = sgm.storage_group_member_storage_group_uuid
AND
sgm.storage_group_member_vg_uuid = slv.scan_lvm_vg_internal_uuid
AND
anv.anvil_uuid = ".$anvil->Database->quote($anvil_uuid)."
ORDER BY
sgr.storage_group_uuid ASC,
slv.scan_lvm_vg_free ASC
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
results => $results,
count => $count
}});
foreach my $row (@{$results})
{
my $storage_group_uuid = $row->[0];
my $storage_group_name = $row->[1];
my $scan_lvm_vg_size = $row->[2];
my $scan_lvm_vg_free = $row->[3];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
storage_group_uuid => $storage_group_uuid,
storage_group_name => $storage_group_name,
scan_lvm_vg_size => $scan_lvm_vg_size,
scan_lvm_vg_free => $scan_lvm_vg_free
}});
push(@{$storage_groups}, {
storage_group_uuid => $storage_group_uuid,
storage_group_name => $storage_group_name,
storage_group_total => int($scan_lvm_vg_size),
storage_group_free => int($scan_lvm_vg_free)
});
}
return $storage_groups;
}
$anvil->Get->switches;
$anvil->Database->connect;
@ -39,138 +121,35 @@ $anvil->Database->get_anvils();
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n";
my $hash = {};
my $anvil_uuid = "";
if ($anvil->data->{cgi}{anvil_uuid}{value})
{
$anvil_uuid = $anvil->data->{cgi}{anvil_uuid}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }});
}
elsif ($anvil->data->{switches}{'anvil-uuid'})
{
$anvil_uuid = $anvil->data->{switches}{'anvil-uuid'};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }});
}
if ((not $anvil_uuid) or (not exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}))
{
$anvil->data->{anvil_status}{anvil_name} = "!!invalid!anvil_uuid!!";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'anvil_status::anvil_name' => $anvil->data->{anvil_status}{anvil_name} }});
}
else
my $anvil_uuid = exists $anvil->data->{cgi}{anvil_uuid}{value} ? $anvil->data->{cgi}{anvil_uuid}{value} : $anvil->data->{switches}{'anvil-uuid'};
my $anvil_uuid_variable_name = "anvil UUID";
my $response_body = {};
if ($anvil_uuid)
{
my $node1_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid};
my $node2_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid};
my $dr1_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
node1_uuid => $node1_uuid,
node2_uuid => $node2_uuid,
dr1_uuid => $dr1_uuid,
}});
my $query = "
SELECT
a.host_uuid,
a.host_name,
b.scan_filesystem_mount_point,
b.scan_filesystem_size,
b.scan_filesystem_used
FROM
hosts a,
scan_filesystems b
WHERE
a.host_uuid = b.scan_filesystem_host_uuid
AND
(
a.host_uuid = ".$anvil->Database->quote($node1_uuid)."
OR
a.host_uuid = ".$anvil->Database->quote($node2_uuid);
if ($dr1_uuid)
if (exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})
{
$query .= "
OR
a.host_uuid = ".$anvil->Database->quote($dr1_uuid);
}
$query .= "
)
ORDER BY
a.host_name ASC,
b.scan_filesystem_mount_point DESC
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $host_uuid = $row->[0];
my $host_name = $row->[1];
my $mount_point = $row->[2];
my $size = $row->[3];
my $used = $row->[4];
my $free = $size - $used;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
host_uuid => $host_uuid,
host_name => $host_name,
mount_point => $mount_point,
size => $anvil->Convert->add_commas({number => $size})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $size}).")",,
used => $anvil->Convert->add_commas({number => $used})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $used}).")",,
free => $anvil->Convert->add_commas({number => $free})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $free}).")",,
}});
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name} = $host_name;
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total} = $size;
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free} = $free;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"raw::file_systems::${mount_point}::nodes::${host_uuid}::host_name" => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name},
"raw::file_systems::${mount_point}::nodes::${host_uuid}::total" => $anvil->Convert->add_commas({number => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total}}).")",,
"raw::file_systems::${mount_point}::nodes::${host_uuid}::free" => $anvil->Convert->add_commas({number => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free}}).")",,
}});
$anvil->Log->variables({
source => $THIS_FILE,
line => __LINE__,
level => 2,
list => {
message => "Valid ".$anvil_uuid_variable_name." received.",
anvil_uuid => $anvil_uuid
}
});
$response_body->{storage_groups} = get_storage_groups({ anvil_uuid => $anvil_uuid });
}
$anvil->data->{file_systems} = [];
foreach my $mount_point (sort {$a cmp $b} keys %{$anvil->data->{raw}{file_systems}})
else
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mount_point => $mount_point }});
$hash->{mount_point} = $mount_point;
$hash->{nodes} = [];
my $nodes = [$node1_uuid, $node2_uuid];
if ($dr1_uuid)
{
push @{$nodes}, $dr1_uuid;
}
foreach my $host_uuid (@{$nodes})
{
my $host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
host_uuid => $host_uuid,
host_name => $host_name,
}});
if (exists $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid})
{
push @{$hash->{nodes}}, {
host_uuid => $host_uuid,
host_name => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name},
is_mounted => 1,
total => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total},
free => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free},
}
}
else
{
push @{$hash->{nodes}}, {
host_uuid => $host_uuid,
host_name => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_name},
is_mounted => 0,
total => 0,
free => 0,
}
}
}
handle_invalid_uuid({ name => $anvil_uuid_variable_name, uuid => $anvil_uuid });
}
}
else
{
handle_invalid_uuid({ name => $anvil_uuid_variable_name, uuid => $anvil_uuid });
}
print JSON->new->utf8->encode($hash)."\n";
print JSON->new->utf8->encode($response_body)."\n";

@ -82,15 +82,17 @@ else
# Array index 0 is node 1, index 1 is node 2.
$hash->{anvil_state} = "optimal";
$hash->{nodes}->[0] = {
host_uuid => $node1_uuid,
$hash->{hosts}->[0] = {
host_uuid => $node1_uuid,
host_name => $node1_host_name,
'state' => "offline",
state_percent => 0,
state_message => "message_0222,!!host_name!".$node1_host_name."!!",
maintenance_mode => 'undefined',
};
$hash->{nodes}->[1] = {
host_uuid => $node2_uuid,
$hash->{hosts}->[1] = {
host_uuid => $node2_uuid,
host_name => $node2_host_name,
'state' => "offline",
state_percent => 0,
state_message => "message_0222,!!host_name!".$node2_host_name."!!",
@ -99,7 +101,7 @@ else
foreach my $i (0..1)
{
my $host_uuid = $hash->{nodes}->[$i]->{host_uuid};
my $host_uuid = $hash->{hosts}->[$i]->{host_uuid};
my $short_host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{short_host_name};
my $host_status = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_status};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
@ -149,37 +151,38 @@ WHERE
scan_cluster_node_maintenance_mode => $scan_cluster_node_maintenance_mode,
}});
$hash->{nodes}->[$i]->{maintenance_mode} = $scan_cluster_node_maintenance_mode ? 1 : 0;
# Ensure the maintenance_mode is set to a value that can be converted to JSON booleans.
$hash->{hosts}->[$i]->{maintenance_mode} = $scan_cluster_node_maintenance_mode ? \1 : \0;
if ($scan_cluster_node_cluster_member)
{
$hash->{nodes}->[$i]->{'state'} = "online";
$hash->{nodes}->[$i]->{state_percent} = 100;
$hash->{nodes}->[$i]->{state_message} = "message_0223,!!host_name!".$node2_host_name."!!",
$hash->{hosts}->[$i]->{'state'} = "online";
$hash->{hosts}->[$i]->{state_percent} = 100;
$hash->{hosts}->[$i]->{state_message} = "message_0223,!!host_name!".$node2_host_name."!!",
}
elsif ($scan_cluster_node_crmd_member)
{
$hash->{nodes}->[$i]->{'state'} = "crmd";
$hash->{nodes}->[$i]->{state_percent} = 75;
$hash->{nodes}->[$i]->{state_message} = "message_0224,!!host_name!".$node2_host_name."!!",
$hash->{hosts}->[$i]->{'state'} = "crmd";
$hash->{hosts}->[$i]->{state_percent} = 75;
$hash->{hosts}->[$i]->{state_message} = "message_0224,!!host_name!".$node2_host_name."!!",
}
elsif ($scan_cluster_node_in_ccm)
{
$hash->{nodes}->[$i]->{'state'} = "in_ccm";
$hash->{nodes}->[$i]->{state_percent} = 50;
$hash->{nodes}->[$i]->{state_message} = "message_0225,!!host_name!".$node2_host_name."!!",
$hash->{hosts}->[$i]->{'state'} = "in_ccm";
$hash->{hosts}->[$i]->{state_percent} = 50;
$hash->{hosts}->[$i]->{state_message} = "message_0225,!!host_name!".$node2_host_name."!!",
}
else
{
$hash->{nodes}->[$i]->{'state'} = "booted";
$hash->{nodes}->[$i]->{state_percent} = 25;
$hash->{nodes}->[$i]->{state_message} = "message_0226,!!host_name!".$node2_host_name."!!",
$hash->{hosts}->[$i]->{'state'} = "booted";
$hash->{hosts}->[$i]->{state_percent} = 25;
$hash->{hosts}->[$i]->{state_message} = "message_0226,!!host_name!".$node2_host_name."!!",
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"hash->{nodes}->[".$i."]->{state}" => $hash->{nodes}->[$i]->{'state'},
"hash->{nodes}->[".$i."]->{state_percent}" => $hash->{nodes}->[$i]->{state_percent},
"hash->{nodes}->[".$i."]->{state_message}" => $hash->{nodes}->[$i]->{state_message},
"hash->{nodes}->[".$i."]->{maintenance_mode}" => $hash->{nodes}->[$i]->{maintenance_mode},
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"hash->{nodes}->[".$i."]->{state}" => $hash->{hosts}->[$i]->{'state'},
"hash->{nodes}->[".$i."]->{state_percent}" => $hash->{hosts}->[$i]->{state_percent},
"hash->{nodes}->[".$i."]->{state_message}" => $hash->{hosts}->[$i]->{state_message},
"hash->{nodes}->[".$i."]->{maintenance_mode}" => $hash->{hosts}->[$i]->{maintenance_mode},
}});
}
}

@ -0,0 +1,215 @@
#!/usr/bin/perl
#
# Accepts a HTTP PUT request to set the cluster membership of a host.
#
use strict;
use warnings;
use Anvil::Tools;
use Data::Dumper;
use JSON
$| = 1;
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0];
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0];
if (($running_directory =~ /^\./) && ($ENV{PWD}))
{
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $anvil = Anvil::Tools->new();
sub handle_invalid_uuid
{
my $parameters = shift;
my $name = $parameters->{name};
my $uuid = $parameters->{uuid};
$anvil->Log->entry({
source => $THIS_FILE,
line => __LINE__,
level => 0,
'print' => 1,
priority => "err",
key => "error_0160",
variables => { name => $name, uuid => $uuid }
});
$anvil->nice_exit({ exit_code => 1 });
}
sub get_active_member
{
my $parameters = shift;
my $host_uuid = $parameters->{host_uuid};
my $query = "
SELECT
scan_cluster_node_in_ccm,
scan_cluster_node_crmd_member,
scan_cluster_node_cluster_member
FROM
scan_cluster_nodes
WHERE
scan_cluster_node_host_uuid = ".$anvil->Database->quote($host_uuid)."
";
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query } });
my $results = $anvil->Database->query({ query => $query, source => $THIS_FILE, line => __LINE__ });
my $count = @{$results};
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
results => $results,
count => $count
} });
if ($count == 1)
{
my $row = $results->[0];
my $is_in_ccm = $row->[0];
my $is_crmd_member = $row->[1];
my $is_cluster_member = $row->[2];
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
is_in_ccm => $is_in_ccm,
is_crmd_member => $is_crmd_member,
is_cluster_member => $is_cluster_member
} });
return $is_in_ccm && $is_crmd_member && $is_cluster_member;
}
return 0;
}
sub alter_host_membership
{
# Expects the first of positional parameters to be a hash.
my $parameters = shift;
my $host_uuid = $parameters->{host_uuid};
my $is_join_cluster = $parameters->{is_join_cluster};
if ($is_join_cluster)
{
join_cluster({ host_uuid => $host_uuid });
}
else
{
leave_cluster({ host_uuid => $host_uuid });
}
}
# Re-adds a host to its anvil cluster.
#
# Note: not to be confused wtih adding a new host the an anvil.
sub join_cluster
{
my $parameters = shift;
my $host_uuid = $parameters->{host_uuid};
# Determine whether host is already a cluster member.
my $is_active_member = get_active_member({ host_uuid => $host_uuid });
# Find out whether the host is online before trying to make it join the cluster.
my $is_online = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_status} eq "online" ? 1 : 0;
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
is_active_member => $is_active_member,
is_online => $is_online
} });
if (not $is_active_member && $is_online)
{
$anvil->Database->insert_or_update_jobs({
job_command => $anvil->data->{path}{exe}{'anvil-safe-start'},
job_host_uuid => $host_uuid,
job_description => "job_0337",
job_name => "cgi-bin::set_membership::join",
job_progress => 0,
job_title => "job_0336"
});
}
}
# Removes a host from its anvil cluster.
#
# Note: does not permanently remove the host; can be re-added.
sub leave_cluster
{
my $parameters = shift;
my $host_uuid = $parameters->{host_uuid};
# Determine whether host is already a cluster member.
my $is_active_member = get_active_member({ host_uuid => $host_uuid });
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
is_active_member => $is_active_member
} });
if ($is_active_member)
{
$anvil->Database->insert_or_update_jobs({
job_command => $anvil->data->{path}{exe}{'anvil-safe-stop'},
job_host_uuid => $host_uuid,
job_description => "job_0339",
job_name => "cgi-bin::set_membership::leave",
job_progress => 0,
job_title => "job_0338"
});
}
}
$anvil->Get->switches;
$anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003"});
$anvil->nice_exit({exit_code => 1});
}
# Read in any CGI variables, if needed.
$anvil->Get->cgi();
$anvil->Database->get_hosts();
$anvil->Database->get_anvils();
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n";
my $response_body = {};
my $request_body;
my $is_decode_json_success = eval {
$request_body = decode_json($anvil->data->{cgi}{PUTDATA}{value});
};
if (not $is_decode_json_success)
{
$anvil->Log->entry({
source => $THIS_FILE,
line => __LINE__,
level => 0,
'print' => 1,
priority => "err",
key => "error_0304",
variables => { request_body_string => $anvil->data->{cgi}{PUTDATA}{value}, json_decode_error => $_ }
});
}
my $host_uuid = exists $request_body->{host_uuid} ? $request_body->{host_uuid} : $anvil->data->{switches}{'host-uuid'};
# Defaults to join; will check whether host is already part of its anvil cluster.
my $is_member = exists $request_body->{is_member} ? $request_body->{is_member} : $anvil->data->{switches}{'is-member'};
my $host_uuid_variable_name = "host UUID";
if ($host_uuid)
{
if (exists $anvil->data->{hosts}{host_uuid}{$host_uuid})
{
alter_host_membership({ host_uuid => $host_uuid, is_join_cluster => $is_member });
}
else
{
handle_invalid_uuid({ name => $host_uuid_variable_name, uuid => $host_uuid });
}
}
print JSON->new->utf8->encode($response_body)."\n";

@ -1,6 +1,6 @@
#!/usr/bin/perl
#
# This prints JSON formated data reporting the status of an Anvil! system and it's member hosts.
# Accepts a HTTP PUT request to power ON or OFF a specified host.
#
use strict;

@ -1083,6 +1083,14 @@ It should be provisioned in the next minute or two.</key>
<key name="job_0334">Power Off Host</key>
<!-- cgi-bin/set_power,off,job_description -->
<key name="job_0335">Power off the target host by executing a stop script on the host itself.</key>
<!-- cgi-bin/set_membership,join,job_title -->
<key name="job_0336">Host Join Cluster</key>
<!-- cgi-bin/set_membership,join,job_description -->
<key name="job_0337">Make target host join its anvil cluster.</key>
<!-- cgi-bin/set_membership,leave,job_title -->
<key name="job_0338">Host Leave Cluster</key>
<!-- cgi-bin/set_membership,leave,job_description -->
<key name="job_0339">Make target host leave its anvil cluster.</key>
<!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key>

Loading…
Cancel
Save