Created Database->get_variables().

* Updated (NOT COMPLETE!) System->check_if_configured to take the new
  'thorough' parameter to see if the network is no longer configured.
  When used, the method attempts to detect if a host has been
  rebuilt and, thus, no longer configured.
* Started work on having 'anvil-join-anvil --rejoin' try to see if the
  network needs to be reconfigured prior to rejoining the cluster.

Signed-off-by: Madison Kelly <mkelly@alteeve.com>
main
Madison Kelly 7 months ago
parent cb6346f468
commit 94dacd08d8
  1. 133
      Anvil/Tools/Database.pm
  2. 2
      Anvil/Tools/Network.pm
  3. 29
      Anvil/Tools/System.pm
  4. 53
      tools/anvil-join-anvil

@ -56,6 +56,7 @@ my $THIS_FILE = "Database.pm";
# get_tables_from_schema # get_tables_from_schema
# get_power # get_power
# get_upses # get_upses
# get_variables
# initialize # initialize
# insert_or_update_alert_overrides # insert_or_update_alert_overrides
# insert_or_update_anvils # insert_or_update_anvils
@ -7075,6 +7076,138 @@ WHERE
} }
=head2 get_variables
This method loads the C<< variables >> table data into memory.
If the record does NOT have a C<< variable_source_table >>, the data will be stored in the hash;
* variables::variable_uuid::<variable_uuid::global::variable_name = <variable_name>
* variables::variable_uuid::<variable_uuid::global::variable_value = <variable_value>
* variables::variable_uuid::<variable_uuid::global::variable_default = <variable_default>
* variables::variable_uuid::<variable_uuid::global::variable_description = <variable_description> (this is a string key)
* variables::variable_uuid::<variable_uuid::global::modified_date = <modified_date> (this is a plain text english date and time)
* variables::variable_uuid::<variable_uuid::global::modified_date_unix = <modified_date_unix> (this is the unix time stamp)
If there is a source table, then the data is stored in the hash;
* variables::variable_uuid::<variable_uuid::source_table::<source_table>::source_uuid::<source_uuid>::variable_name = <variable_name>
* variables::variable_uuid::<variable_uuid::source_table::<source_table>::source_uuid::<source_uuid>::variable_value = <variable_value>
* variables::variable_uuid::<variable_uuid::source_table::<source_table>::source_uuid::<source_uuid>::variable_default = <variable_default>
* variables::variable_uuid::<variable_uuid::source_table::<source_table>::source_uuid::<source_uuid>::variable_description = <variable_description> (this is a string key)
* variables::variable_uuid::<variable_uuid::source_table::<source_table>::source_uuid::<source_uuid>::modified_date = <modified_date> (this is a plain text english date and time)
* variables::variable_uuid::<variable_uuid::source_table::<source_table>::source_uuid::<source_uuid>::modified_date_unix = <modified_date_unix> (this is the unix time stamp)
This method takes no parameters.
=cut
sub get_variables
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->get_variables()" }});
if (exists $anvil->data->{variables})
{
delete $anvil->data->{variables};
}
# Load the power data.
$anvil->Database->get_hosts({debug => $debug});
my $query = "
SELECT
variable_uuid,
variable_name,
variable_value,
variable_default,
variable_description,
variable_section,
variable_source_uuid,
variable_source_table,
modified_date,
round(extract(epoch from modified_date))
FROM
variables
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, 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 => $debug, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $variable_uuid = $row->[0];
my $variable_name = $row->[1];
my $variable_value = $row->[2];
my $variable_default = $row->[3];
my $variable_description = $row->[4];
my $variable_section = $row->[5];
my $variable_source_uuid = defined $row->[6] ? $row->[6] : "";
my $variable_source_table = $row->[7];
my $modified_date = $row->[8];
my $modified_date_unix = $row->[9];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
variable_uuid => $variable_uuid,
variable_name => $variable_name,
variable_value => $variable_value,
variable_default => $variable_default,
variable_description => $variable_description,
variable_section => $variable_section,
variable_source_uuid => $variable_source_uuid,
variable_source_table => $variable_source_table,
modified_date => $modified_date,
modified_date_unix => $modified_date_unix,
}});
if ($variable_source_table)
{
# Store it under the associated table
$variable_source_uuid = "--" if not $variable_source_uuid; # This should never be needed, but just in case...
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_name} = $variable_name;
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_value} = $variable_value;
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_default} = $variable_default;
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_description} = $variable_description;
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{modified_date} = $modified_date;
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{modified_date_unix} = $modified_date_unix;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"variables::variable_uuid::${variable_uuid}::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::variable_name" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_name},
"variables::variable_uuid::${variable_uuid}::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::variable_value" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_value},
"variables::variable_uuid::${variable_uuid}::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::variable_default" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_default},
"variables::variable_uuid::${variable_uuid}::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::variable_description" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_description},
"variables::variable_uuid::${variable_uuid}::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::modified_date" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{modified_date},
"variables::variable_uuid::${variable_uuid}::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::modified_date_unix" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{modified_date_unix},
}});
}
else
{
# Global variable
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{variable_name} = $variable_name;
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{variable_value} = $variable_value;
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{variable_default} = $variable_default;
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{variable_description} = $variable_description;
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{modified_date} = $modified_date;
$anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{modified_date_unix} = $modified_date_unix;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"variables::variable_uuid::${variable_uuid}::global::variable_name" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{variable_name},
"variables::variable_uuid::${variable_uuid}::global::variable_value" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{variable_value},
"variables::variable_uuid::${variable_uuid}::global::variable_default" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{variable_default},
"variables::variable_uuid::${variable_uuid}::global::variable_description" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{variable_description},
"variables::variable_uuid::${variable_uuid}::global::modified_date" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{modified_date},
"variables::variable_uuid::${variable_uuid}::global::modified_date_unix" => $anvil->data->{variables}{variable_uuid}{$variable_uuid}{global}{modified_date_unix},
}});
}
}
return(0);
}
=head2 initialize =head2 initialize
This will initialize a database using a given file. This will initialize a database using a given file.

@ -4287,7 +4287,7 @@ sub ping
{ {
if ($is_local) if ($is_local)
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => $secure, key => "log_0855", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0855", variables => {
shell_call => $shell_call, shell_call => $shell_call,
timeout => $timeout, timeout => $timeout,
}}); }});

@ -599,7 +599,13 @@ sub check_daemon
This returns C<< 1 >> is the system has finished initial configuration, and C<< 0 >> if not. This returns C<< 1 >> is the system has finished initial configuration, and C<< 0 >> if not.
This method takes no parameters. Parameters;
=head3 thorough (optional, default 0)
If this is set to C<< 1 >>, then a check is made of the host's network. If the network is found to be unconfigured, then C<< 0 >> is returned, Even if the variable C<< system::configured >> is set to C<< 1 >>.
If this test fails, the C<< system::configured >> variable will be reset to C<< 0 >>. Likewise, the C<< path::data::host_configured >> file (usually C<< /etc/anvil/host.configured >>) wil be updated also.
=cut =cut
sub check_if_configured sub check_if_configured
@ -610,6 +616,11 @@ sub check_if_configured
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->check_if_configured()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->check_if_configured()" }});
my $thorough = defined $parameter->{thorough} ? $parameter->{thorough} : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
thorough => $thorough,
}});
my ($configured, $variable_uuid, $modified_date) = $anvil->Database->read_variable({ my ($configured, $variable_uuid, $modified_date) = $anvil->Database->read_variable({
debug => $debug, debug => $debug,
variable_name => "system::configured", variable_name => "system::configured",
@ -644,7 +655,7 @@ sub check_if_configured
if (($variable eq "system::configured") && ($value eq "1")) if (($variable eq "system::configured") && ($value eq "1"))
{ {
# Write the database entry. # Write the database entry.
my $variable_uuid = $anvil->Database->insert_or_update_variables({ $variable_uuid = $anvil->Database->insert_or_update_variables({
debug => 2, debug => 2,
variable_name => "system::configured", variable_name => "system::configured",
variable_value => 1, variable_value => 1,
@ -664,15 +675,25 @@ sub check_if_configured
} }
} }
if (($configured) && (not -f $anvil->data->{path}{data}{host_configured})) # Are we configured?
if ($configured)
{
if ($thorough)
{
# OK, but are we really though?
}
if (not -f $anvil->data->{path}{data}{host_configured})
{ {
my $failed = $anvil->Storage->write_file({ my $failed = $anvil->Storage->write_file({
debug => $debug, debug => $debug,
file => $anvil->data->{path}{data}{host_configured}, file => $anvil->data->{path}{data}{host_configured},
body => "system::configured = 1\n", body => "system::configured = ".$configured."\n",
}); });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }});
} }
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { configured => $configured }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { configured => $configured }});
return($configured); return($configured);

@ -203,6 +203,47 @@ sub process_rejoin
}}); }});
} }
# Does this host need to be reconfigured? If so, register a job, if one doesn't exist yet, and exit.
my $configured = check_if_configured({debug => 2, thorough => 1});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { configured => $configured }});
if ($configured)
{
print "The host appears to already be configured, good.\n";
}
else
{
print "[ Note ] - The host appears to NOT be configured yet!\n";
if (exists $anvil->data->{anvils}{host_uuid}{$host_uuid})
{
# Can we find the data needed to reconfigure this subnode?
my $job_uuid = create_anvil_configure_host_job($anvil, $host_uuid);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }});
if ($job_uuid)
{
print "[ Success ] - Found the data needed to configure the network on this subnode! The anvil-join-anvil job has\n";
print "[ Success ] been created with the job UUID: [".$job_uuid."]\n";
print "[ Note ] - This subnode will reboot one minute after the network configuration completes. Once rebooted,\n";
print "[ Note ] please run this again.\n";
$anvil->nice_exit({exit_code => 0});
}
else
{
print "[ Warning ] - Failed to automatically create the anvil-join-anvil job.\n";
print "[ Warning ] - Please use Striker to initialize this host. Once the network has been configured, try rejoining\n";
print "[ Warning ] this subnode again.\n";
$anvil->nice_exit({exit_code => 1});
}
}
else
{
# We can't configure it automatically.
print "[ Warning ] - This is a new host, so the information needed to configure the network does not exist.\n";
print "[ Warning ] - Please use Striker to initialize this host. Once the network has been configured, try rejoining\n";
print "[ Warning ] this subnode again.\n";
$anvil->nice_exit({exit_code => 1});
}
}
if ($manifest) if ($manifest)
{ {
# Did we get a valid manifest? # Did we get a valid manifest?
@ -226,7 +267,7 @@ sub process_rejoin
} }
else else
{ {
print "[ Error ] - The manifest: [".$manifest."] was not found in the database.\n"; print "[ Error ] - The manifest: [".$manifest."] was not found in the database.\n"; <
print "[ Error ] - Try again without this switch to see the available manifests.\n"; print "[ Error ] - Try again without this switch to see the available manifests.\n";
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
@ -402,6 +443,16 @@ sub process_rejoin
return(0); return(0);
} }
sub create_anvil_configure_host_job
{
my ($anvil, $host_uuid) = @_;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }});
my $job_uuid = "";
return($job_uuid)
}
# Make sure the hosts file has entries for all nets for both subnodes # Make sure the hosts file has entries for all nets for both subnodes
sub wait_for_etc_hosts sub wait_for_etc_hosts
{ {

Loading…
Cancel
Save