Finished System->check_if_configured({thorough => 1}) support.

* Updated Database->get_variables() to store columns with
  variable_source_table values in a more useful hash.

Signed-off-by: Madison Kelly <mkelly@alteeve.com>
main
Madison Kelly 7 months ago
parent 94dacd08d8
commit 8b8be39717
  1. 48
      Anvil/Tools/Database.pm
  2. 132
      Anvil/Tools/System.pm
  3. 2
      share/words.xml

@ -7082,21 +7082,21 @@ 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)
* 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)
* variables::source_table::<source_table>::source_uuid::<source_uuid>::variable_uuid::<variable_uuid>::variable_name = <variable_name>
* variables::source_table::<source_table>::source_uuid::<source_uuid>::variable_uuid::<variable_uuid>::variable_value = <variable_value>
* variables::source_table::<source_table>::source_uuid::<source_uuid>::variable_uuid::<variable_uuid>::variable_default = <variable_default>
* variables::source_table::<source_table>::source_uuid::<source_uuid>::variable_uuid::<variable_uuid>::variable_description = <variable_description> (this is a string key)
* variables::source_table::<source_table>::source_uuid::<source_uuid>::variable_uuid::<variable_uuid>::modified_date = <modified_date> (this is a plain text english date and time)
* variables::source_table::<source_table>::source_uuid::<source_uuid>::variable_uuid::<variable_uuid>::modified_date_unix = <modified_date_unix> (this is the unix time stamp)
This method takes no parameters.
@ -7169,19 +7169,19 @@ FROM
{
# 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->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_uuid}{variable_name} = $variable_name;
$anvil->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_uuid}{variable_value} = $variable_value;
$anvil->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_uuid}{variable_default} = $variable_default;
$anvil->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_uuid}{variable_description} = $variable_description;
$anvil->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_uuid}{modified_date} = $modified_date;
$anvil->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_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},
"variables::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::variable_uuid::${variable_uuid}::variable_name" => $anvil->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_uuid}{variable_name},
"variables::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::variable_uuid::${variable_uuid}::variable_value" => $anvil->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_uuid}{variable_value},
"variables::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::variable_uuid::${variable_uuid}::variable_default" => $anvil->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_uuid}{variable_default},
"variables::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::variable_uuid::${variable_uuid}::variable_description" => $anvil->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_uuid}{variable_description},
"variables::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::variable_uuid::${variable_uuid}::modified_date" => $anvil->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_uuid}{modified_date},
"variables::source_table::${variable_source_table}::source_uuid::${variable_source_uuid}::variable_uuid::${variable_uuid}::modified_date_unix" => $anvil->data->{variables}{source_table}{$variable_source_table}{source_uuid}{$variable_source_uuid}{variable_uuid}{$variable_uuid}{modified_date_unix},
}});
}
else

@ -681,18 +681,130 @@ sub check_if_configured
if ($thorough)
{
# OK, but are we really though?
my $host_uuid = $anvil->Get->host_uuid({debug => $debug});
my $short_host_name = $anvil->Get->short_host_name({debug => $debug});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_uuid => $host_uuid,
short_host_name => $short_host_name,
}});
$anvil->Network->get_ips({debug => $debug, target => $short_host_name});
$anvil->Network->collect_data({debug => $debug});
$anvil->Database->get_variables({debug => $debug});
my $reconfigure = 0;
if (not exists $anvil->data->{variables}{source_table}{hosts}{source_uuid}{$host_uuid})
{
# Report that we can't validate this host's configuration. We'll have
# to rely on the variable value, if any.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "warning_0183"});
$reconfigure = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { reconfigure => $reconfigure }});
}
else
{
foreach my $variable_uuid (sort {$a cmp $b} keys %{$anvil->data->{variables}{source_table}{hosts}{source_uuid}{$host_uuid}{variable_uuid}})
{
my $variable_name = $anvil->data->{variables}{source_table}{hosts}{source_uuid}{$host_uuid}{variable_uuid}{$variable_uuid}{variable_name};
my $variable_value = $anvil->data->{variables}{source_table}{hosts}{source_uuid}{$host_uuid}{variable_uuid}{$variable_uuid}{variable_value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
variable_uuid => $variable_uuid,
variable_name => $variable_name,
variable_value => $variable_value,
}});
if ($variable_name =~ /form::config_step2::(\w+)n(\d+)_create_bridge::value/)
{
my $network = $1."n".$2;
my $bridge_name = $network."_bridge1";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
network => $network,
bridge_name => $bridge_name,
}});
# Does this bridge exist?
if (not exists $anvil->data->{nmcli}{bridge}{$bridge_name})
{
# Missing bridge!
$reconfigure = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { reconfigure => $reconfigure }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "warning_0184", variables => { interface => $bridge_name }});
}
}
if ($variable_name =~ /form::config_step2::(\d+)n(\d+)_link(\d)_mac_to_set::value/)
{
my $interface = $1."n".$2."_link".$3;
my $bond_name = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { interface => $interface }});
# If this is link2, look for a bond.
if ($3 eq "2")
{
# We'll check for a bond after we check for this interface.
$bond_name = $1."n".$2."_bond1";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { bond_name => $bond_name }});
}
# Does this interface exist? See if we can find it via the
# MAC address record or the interface name. Note that if the
# 'match.interface-name' is set, both interface names are
# stored, even if NM decided not to use one of them.
if ((not exists $anvil->data->{nmcli}{perm_mac_address}{$interface}) && (not exists $anvil->data->{nmcli}{interface}{$interface}))
{
# Missing interface!
$reconfigure = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { reconfigure => $reconfigure }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "warning_0184", variables => { interface => $interface }});
}
if (($bond_name) && (not exists $anvil->data->{nmcli}{bond}{$bond_name}))
{
# Missing bond!
$reconfigure = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { reconfigure => $reconfigure }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "warning_0184", variables => { interface => $bond_name }});
}
}
}
}
if ($reconfigure)
{
$configured = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { configured => $configured }});
# Mark this host as not configured.
$variable_uuid = $anvil->Database->insert_or_update_variables({
debug => $debug,
variable_name => "system::configured",
variable_value => $configured,
variable_default => "",
variable_description => "striker_0048",
variable_section => "system",
variable_source_uuid => $host_uuid,
variable_source_table => "hosts",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { variable_uuid => $variable_uuid }});
my $failed = $anvil->Storage->write_file({
debug => $debug,
file => $anvil->data->{path}{data}{host_configured},
backup => 0,
overwrite => 1,
body => "system::configured = ".$configured."\n",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }});
}
}
if (not -f $anvil->data->{path}{data}{host_configured})
{
my $failed = $anvil->Storage->write_file({
debug => $debug,
file => $anvil->data->{path}{data}{host_configured},
body => "system::configured = ".$configured."\n",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }});
}
}
if (not -f $anvil->data->{path}{data}{host_configured})
{
my $failed = $anvil->Storage->write_file({
debug => $debug,
file => $anvil->data->{path}{data}{host_configured},
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 => { configured => $configured }});

@ -4210,6 +4210,8 @@ We will try to proceed anyway.</key>
<key name="warning_0180">[ Warning ] - We were asked to read from the database: [#!variable!server!#], but it is not or is no longer available.</key>
<key name="warning_0181">[ Warning ] - We were asked to read from the database: [#!variable!server!#], but it is no longer available, and no alternative databases are available.</key>
<key name="warning_0182">[ Warning ] - We appear to have lost access to the database: [#!variable!uuid!#], during a write. Skipping this database.</key>
<key name="warning_0183">[ Warning ] - We were asked to thoroughly check if this host is configured or not, but there are no records in the 'variables' table for this host. Unable to check the network config! Relying on the 'system::configured' value.</key>
<key name="warning_0184">[ Warning ] - We were asked to thoroughly check if this host is configured or not, and the interface: [#!variable!interface!#] doesn't exist! Marking this host as unconfigured!</key>
</language>
<!-- 日本語 -->

Loading…
Cancel
Save