* Updated Cluster->assemble_storage_groups() and Cluster->anvil_name_from_uuid() and ->available_resources() to try to detect the anvil_uuid if not passed in.

* Updated Database->insert_or_update_storage_group_members() to use the host_uuid when trying to find existing members.
* Added the skeleton of a bunch of new json endpoints for the new UI features.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 4 years ago
parent f07f77d060
commit 5536e8ff47
  1. 12
      Anvil/Tools/Cluster.pm
  2. 6
      Anvil/Tools/Database.pm
  3. 12
      Anvil/Tools/Get.pm
  4. 14
      cgi-bin/Makefile.am
  5. 0
      cgi-bin/cold_stop
  6. 0
      cgi-bin/get_cpu
  7. 0
      cgi-bin/get_memory
  8. 0
      cgi-bin/get_replicated_storage
  9. 71
      cgi-bin/get_shared_storage
  10. 0
      cgi-bin/get_status
  11. 0
      cgi-bin/set_membership
  12. 0
      cgi-bin/set_power
  13. 3
      tools/anvil-configure-host
  14. 4
      tools/striker-initialize-host

@ -273,9 +273,17 @@ sub assemble_storage_groups
if (not $anvil_uuid) if (not $anvil_uuid)
{ {
# 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" }}); $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!!"); return("!!error!!");
} }
}
# Get the node UUIDs for this anvil. # Get the node UUIDs for this anvil.
my $query = " my $query = "
@ -372,7 +380,8 @@ ORDER BY
# only. # only.
my $storage_group_uuid = $anvil->data->{storage_groups}{vg_uuid}{$scan_lvm_vg_internal_uuid}{storage_group_uuid}; 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 $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->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
anvil_uuid => $anvil_uuid, anvil_uuid => $anvil_uuid,
host_uuid => $host_uuid, host_uuid => $host_uuid,
@ -434,6 +443,7 @@ ORDER BY
storage_group_member_host_uuid => $host_uuid, storage_group_member_host_uuid => $host_uuid,
storage_group_member_vg_uuid => $storage_group_member_vg_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->data->{ungrouped_vg_count}{$this_is}--;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {

@ -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_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}{anvil_dr1_host_uuid} = $anvil_dr1_host_uuid;
$anvil->data->{anvils}{anvil_name}{$anvil_name}{modified_date} = $modified_date; $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 => { $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_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}, "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_name = $row->[2];
my $storage_group_member_uuid = $row->[3]; my $storage_group_member_uuid = $row->[3];
my $storage_group_member_host_uuid = $row->[4]; 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 => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
storage_group_uuid => $storage_group_uuid, storage_group_uuid => $storage_group_uuid,
storage_group_anvil_uuid => $storage_group_anvil_uuid, storage_group_anvil_uuid => $storage_group_anvil_uuid,
@ -11645,6 +11645,8 @@ FROM
storage_group_members storage_group_members
WHERE 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 $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
my $count = @{$results}; my $count = @{$results};

@ -130,11 +130,17 @@ sub anvil_name_from_uuid
my $anvil_uuid = defined $parameter->{anvil_uuid} ? $parameter->{anvil_uuid} : ""; my $anvil_uuid = defined $parameter->{anvil_uuid} ? $parameter->{anvil_uuid} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { anvil_uuid => $anvil_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { anvil_uuid => $anvil_uuid }});
if (not $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) 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" }}); $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!!"); return("!!error!!");
} }
}
my $query = " my $query = "
SELECT SELECT
@ -421,11 +427,17 @@ sub available_resources
anvil_uuid=> $anvil_uuid, anvil_uuid=> $anvil_uuid,
}}); }});
if (not $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) 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" }}); $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!!"); return("!!error!!");
} }
}
if (exists $anvil->data->{anvil_resources}{$anvil_uuid}) if (exists $anvil->data->{anvil_resources}{$anvil_uuid})
{ {

@ -2,8 +2,16 @@ MAINTAINERCLEANFILES = Makefile.in
cgibindir = $(localstatedir)/www/cgi-bin cgibindir = $(localstatedir)/www/cgi-bin
dist_cgibin_SCRIPTS = \ dist_cgibin_SCRIPTS = \
striker \ cold_stop \
upload.pl \ get_anvil_status \
get_anvils \ get_anvils \
get_anvil_status get_cpu \
get_memory \
get_replicated_storage
get_shared_storage \
get_status \
set_membership \
set_power \
striker \
upload.pl

@ -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";

@ -1203,6 +1203,8 @@ AND
}); });
# If we're in a cluster, abort. # If we're in a cluster, abort.
if (-e $anvil->data->{path}{exe}{pcs})
{
my ($problem) = $anvil->Cluster->parse_cib(); my ($problem) = $anvil->Cluster->parse_cib();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
if ((not $problem) && ($anvil->data->{cib}{parsed}{'local'}{ready})) if ((not $problem) && ($anvil->data->{cib}{parsed}{'local'}{ready}))
@ -1216,6 +1218,7 @@ AND
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0250"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0250"});
$anvil->nice_exit({exit_code => 7}); $anvil->nice_exit({exit_code => 7});
} }
}
return(0); return(0);
} }

@ -184,7 +184,7 @@ sub add_databases
if ($db_host) if ($db_host)
{ {
my $failed = $anvil->Database->manage_anvil_conf({ my $failed = $anvil->Database->manage_anvil_conf({
debug => 3, debug => 2,
target => $target, target => $target,
remote_user => "root", remote_user => "root",
password => $anvil->data->{data}{password}, password => $anvil->data->{data}{password},
@ -773,7 +773,7 @@ EOF
$shell_call = $anvil->data->{path}{exe}{'dnf'}." -y install ".$package; $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 }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
($output, $error, $return_code) = $anvil->Remote->call({ ($output, $error, $return_code) = $anvil->Remote->call({
debug => 3, debug => 2,
shell_call => $shell_call, shell_call => $shell_call,
password => $anvil->data->{data}{password}, password => $anvil->data->{data}{password},
port => $anvil->data->{data}{ssh_port}, port => $anvil->data->{data}{ssh_port},

Loading…
Cancel
Save