diff --git a/Anvil/Tools/Cluster.pm b/Anvil/Tools/Cluster.pm index 5e3a5477..c6dc5651 100644 --- a/Anvil/Tools/Cluster.pm +++ b/Anvil/Tools/Cluster.pm @@ -273,8 +273,16 @@ sub assemble_storage_groups if (not $anvil_uuid) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Cluster->assemble_storage_groups()", parameter => "anvil_uuid" }}); - return("!!error!!"); + # Can we deduce the anvil_uuid? + $anvil_uuid = $anvil->Cluster->get_anvil_uuid({debug => $debug}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { anvil_uuid=> $anvil_uuid }}); + + if (not $anvil_uuid) + { + # Still no anvil_uuid + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Cluster->assemble_storage_groups()", parameter => "anvil_uuid" }}); + return("!!error!!"); + } } # Get the node UUIDs for this anvil. @@ -372,7 +380,8 @@ ORDER BY # only. my $storage_group_uuid = $anvil->data->{storage_groups}{vg_uuid}{$scan_lvm_vg_internal_uuid}{storage_group_uuid}; my $group_name = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{group_name}; - my $storage_group_member_uuid = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{host_uuid}{$host_uuid}{vg_uuid}{$scan_lvm_vg_internal_uuid}{storage_group_member_uuid}; + #my $storage_group_member_uuid = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{host_uuid}{$host_uuid}{vg_uuid}{$scan_lvm_vg_internal_uuid}{storage_group_member_uuid}; + my $storage_group_member_uuid = $anvil->data->{storage_groups}{anvil_uuid}{$anvil_uuid}{storage_group_uuid}{$storage_group_uuid}{host_uuid}{$host_uuid}{storage_group_member_uuid}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { anvil_uuid => $anvil_uuid, host_uuid => $host_uuid, @@ -434,6 +443,7 @@ ORDER BY storage_group_member_host_uuid => $host_uuid, storage_group_member_vg_uuid => $storage_group_member_vg_uuid, }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { storage_group_member_uuid => $storage_group_member_uuid }}); $anvil->data->{ungrouped_vg_count}{$this_is}--; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index b7e80993..795b8d62 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -2015,7 +2015,7 @@ WHERE $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_node2_host_uuid} = $anvil_node2_host_uuid; $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_dr1_host_uuid} = $anvil_dr1_host_uuid; $anvil->data->{anvils}{anvil_name}{$anvil_name}{modified_date} = $modified_date; - $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{query_time} = time; + $anvil->data->{anvils}{anvil_name}{$anvil_uuid}{query_time} = time; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "anvils::anvil_name::${anvil_name}::anvil_uuid" => $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_uuid}, "anvils::anvil_name::${anvil_name}::anvil_description" => $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_description}, @@ -4219,7 +4219,7 @@ ORDER BY my $storage_group_name = $row->[2]; my $storage_group_member_uuid = $row->[3]; my $storage_group_member_host_uuid = $row->[4]; - my $storage_group_member_vg_uuid = $row->[5]; + my $storage_group_member_vg_uuid = $row->[5]; # This is the VG's internal UUID $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { storage_group_uuid => $storage_group_uuid, storage_group_anvil_uuid => $storage_group_anvil_uuid, @@ -11644,7 +11644,9 @@ SELECT FROM storage_group_members WHERE - storage_group_member_vg_uuid = ".$anvil->Database->quote($storage_group_member_vg_uuid)." + storage_group_member_vg_uuid = ".$anvil->Database->quote($storage_group_member_vg_uuid)." +AND + storage_group_member_host_uuid = ".$anvil->Database->quote($storage_group_member_host_uuid)." ;"; my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__}); my $count = @{$results}; diff --git a/Anvil/Tools/Get.pm b/Anvil/Tools/Get.pm index af29567c..ba5c488b 100644 --- a/Anvil/Tools/Get.pm +++ b/Anvil/Tools/Get.pm @@ -132,8 +132,14 @@ sub anvil_name_from_uuid if (not $anvil_uuid) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Get->anvil_name_from_uuid()", parameter => "server_name" }}); - return("!!error!!"); + $anvil_uuid = $anvil->Cluster->get_anvil_uuid({debug => $debug}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { anvil_uuid => $anvil_uuid }}); + + if (not $anvil_uuid) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Get->anvil_name_from_uuid()", parameter => "server_name" }}); + return("!!error!!"); + } } my $query = " @@ -423,8 +429,14 @@ sub available_resources if (not $anvil_uuid) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Get->available_resources()", parameter => "anvil_uuid" }}); - return("!!error!!"); + $anvil_uuid = $anvil->Cluster->get_anvil_uuid({debug => $debug}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { anvil_uuid => $anvil_uuid }}); + + if (not $anvil_uuid) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Get->available_resources()", parameter => "anvil_uuid" }}); + return("!!error!!"); + } } if (exists $anvil->data->{anvil_resources}{$anvil_uuid}) diff --git a/cgi-bin/Makefile.am b/cgi-bin/Makefile.am index 33cd0e86..a2b72735 100644 --- a/cgi-bin/Makefile.am +++ b/cgi-bin/Makefile.am @@ -2,8 +2,16 @@ MAINTAINERCLEANFILES = Makefile.in cgibindir = $(localstatedir)/www/cgi-bin dist_cgibin_SCRIPTS = \ - striker \ - upload.pl \ + cold_stop \ + get_anvil_status \ get_anvils \ - get_anvil_status + get_cpu \ + get_memory \ + get_replicated_storage + get_shared_storage \ + get_status \ + set_membership \ + set_power \ + striker \ + upload.pl diff --git a/cgi-bin/cold_stop b/cgi-bin/cold_stop new file mode 100755 index 00000000..e69de29b diff --git a/cgi-bin/get_cpu b/cgi-bin/get_cpu new file mode 100755 index 00000000..e69de29b diff --git a/cgi-bin/get_memory b/cgi-bin/get_memory new file mode 100755 index 00000000..e69de29b diff --git a/cgi-bin/get_replicated_storage b/cgi-bin/get_replicated_storage new file mode 100755 index 00000000..e69de29b diff --git a/cgi-bin/get_shared_storage b/cgi-bin/get_shared_storage new file mode 100755 index 00000000..3455a04b --- /dev/null +++ b/cgi-bin/get_shared_storage @@ -0,0 +1,71 @@ +#!/usr/bin/perl +# +# This prints JSON formated data reporting the status of an Anvil! system and it's member 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 = {}; +my $anvil_uuid = $anvil->data->{cgi}{anvil_uuid}{value}; +if ((not $anvil_uuid) or (not exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})) +{ + $anvil->data->{anvil_status}{anvil_name} = "!!invalid!anvil_uuid!!"; +} +else +{ + $anvil->data->{anvil_status}{anvil_name} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name}; + $anvil->data->{anvil_status}{anvil_description} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_description}; + $anvil->data->{anvil_status}{timestamp} = time; + + 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 $node2_status = $anvil->data->{hosts}{host_uuid}{$node2_uuid}{host_status} eq "online" ? 1 : 0; + + $anvil->data->{anvil_status}{nodes}{node1}{host_name} = $anvil->data->{hosts}{host_uuid}{$node1_uuid}{host_name}; + $anvil->data->{anvil_status}{nodes}{node1}{host_uuid} = $node1_uuid; + $anvil->data->{anvil_status}{nodes}{node1}{host_status} = $anvil->data->{hosts}{host_uuid}{$node1_uuid}{host_status} eq "online" ? 1 : 0; + $anvil->data->{anvil_status}{nodes}{node2}{host_name} = $anvil->data->{hosts}{host_uuid}{$node2_uuid}{host_name}; + $anvil->data->{anvil_status}{nodes}{node2}{host_uuid} = $node2_uuid; + $anvil->data->{anvil_status}{nodes}{node2}{host_status} = $anvil->data->{hosts}{host_uuid}{$node2_uuid}{host_status} eq "online" ? 1 : 0; + + $hash->{timestamp} = time; + $hash->{nodes} = []; + push @{$hash->{nodes}}, { on => $anvil->data->{anvil_status}{nodes}{node1}{host_status} }; + push @{$hash->{nodes}}, { on => $anvil->data->{anvil_status}{nodes}{node2}{host_status} }; +} + +print JSON->new->utf8->encode($hash)."\n"; diff --git a/cgi-bin/get_status b/cgi-bin/get_status new file mode 100755 index 00000000..e69de29b diff --git a/cgi-bin/set_membership b/cgi-bin/set_membership new file mode 100755 index 00000000..e69de29b diff --git a/cgi-bin/set_power b/cgi-bin/set_power new file mode 100755 index 00000000..e69de29b diff --git a/tools/anvil-configure-host b/tools/anvil-configure-host index 07142c11..4647f0bd 100755 --- a/tools/anvil-configure-host +++ b/tools/anvil-configure-host @@ -1203,18 +1203,21 @@ AND }); # If we're in a cluster, abort. - my ($problem) = $anvil->Cluster->parse_cib(); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); - if ((not $problem) && ($anvil->data->{cib}{parsed}{'local'}{ready})) + if (-e $anvil->data->{path}{exe}{pcs}) { - # We're in a cluster, abort. - $anvil->Job->update_progress({ - progress => 100, - message => "error_0250", - job_uuid => $anvil->data->{job}{uuid}, - }); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0250"}); - $anvil->nice_exit({exit_code => 7}); + my ($problem) = $anvil->Cluster->parse_cib(); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); + if ((not $problem) && ($anvil->data->{cib}{parsed}{'local'}{ready})) + { + # We're in a cluster, abort. + $anvil->Job->update_progress({ + progress => 100, + message => "error_0250", + job_uuid => $anvil->data->{job}{uuid}, + }); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0250"}); + $anvil->nice_exit({exit_code => 7}); + } } return(0); diff --git a/tools/striker-initialize-host b/tools/striker-initialize-host index 8e80e97d..2038242e 100755 --- a/tools/striker-initialize-host +++ b/tools/striker-initialize-host @@ -184,7 +184,7 @@ sub add_databases if ($db_host) { my $failed = $anvil->Database->manage_anvil_conf({ - debug => 3, + debug => 2, target => $target, remote_user => "root", password => $anvil->data->{data}{password}, @@ -773,7 +773,7 @@ EOF $shell_call = $anvil->data->{path}{exe}{'dnf'}." -y install ".$package; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); ($output, $error, $return_code) = $anvil->Remote->call({ - debug => 3, + debug => 2, shell_call => $shell_call, password => $anvil->data->{data}{password}, port => $anvil->data->{data}{ssh_port},