Fixed issue #515; anvil-join-anvil updates hostnames properly now

* Updated Get->host_name() to accept the new 'refresh' parameter. This
  forces a reread of the hostname, instead of using the cached value.
* Updated System->host_name() so that, when it's updating the hostname,
  it updates the database and cached variables.
* Updated Words->center_text() to avoid undefinied parameter issues.
* Updated anvil-join-anvil to ensure the 'sys::host_name' variable.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 1 year ago
parent 85f86cda8a
commit 49f194eac6
  1. 10
      Anvil/Tools/Get.pm
  2. 46
      Anvil/Tools/System.pm
  3. 2
      Anvil/Tools/Words.pm
  4. 7
      tools/anvil-join-anvil
  5. 2
      tools/anvil-watch-bonds

@ -1455,18 +1455,24 @@ AND
This returns the full host name for the local machine. This returns the full host name for the local machine.
This method takes no parameters. Parameters;
=head3 refresh (optional, default '0')
If set to C<< 1 >>, and if C<< sys::host_name >>, the cached value will be ignored and the hostname will be queried directly.
=cut =cut
sub host_name sub host_name
{ {
### NOTE: This method doesn't offer logging. ### NOTE: This method doesn't offer logging.
my $self = shift; my $self = shift;
my $parameter = shift;
my $anvil = $self->parent; my $anvil = $self->parent;
my $refresh = defined $parameter->{refresh} ? $parameter->{refresh} : 0;
my $host_name = ""; my $host_name = "";
# NOTE: Don't use 'ENV{HOSTNAME}'! It lags behind changes made by 'hostnamectl'. # NOTE: Don't use 'ENV{HOSTNAME}'! It lags behind changes made by 'hostnamectl'.
if ($anvil->data->{sys}{host_name}) if ((not $refresh) && ($anvil->data->{sys}{host_name}))
{ {
# We have an environment variable, so use it. # We have an environment variable, so use it.
$host_name = $anvil->data->{sys}{host_name}; $host_name = $anvil->data->{sys}{host_name};

@ -3402,19 +3402,51 @@ sub host_name
# Set? # Set?
if ($set) if ($set)
{ {
my $shell_call = $anvil->data->{path}{exe}{hostnamectl}." set-hostname $set"; my $shell_call = $anvil->data->{path}{exe}{hostnamectl}." set-hostname ".$set;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
my $output = ""; my $output = "";
my $return_code = ""; my $return_code = "";
if ($anvil->Network->is_local({host => $target})) if ($anvil->Network->is_local({host => $target}))
{ {
# Load the hosts from the database so that we know which on to update.
$anvil->Database->get_hosts();
my $host_uuid = $anvil->Get->host_uuid;
my $current_host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_uuid => $host_uuid,
current_host_name => $current_host_name,
}});
# Local call # Local call
($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call}); ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output, output => $output,
return_code => $return_code, return_code => $return_code,
}}); }});
# Update the database
$anvil->Database->insert_or_update_hosts({
debug => $debug,
host_ipmi => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_ipmi},
host_key => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_key},
host_name => $set,
host_type => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type},
host_uuid => $host_uuid,
host_status => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_status},
});
# Reload hosts
$anvil->Database->get_hosts();
# Reload the host name
$anvil->Get->host_name({refresh => 1});
# Update the stored hostname
$anvil->data->{sys}{host_name} = $set;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"sys::host_name" => $anvil->data->{sys}{host_name},
}});
} }
else else
{ {
@ -3452,6 +3484,12 @@ sub host_name
output => $output, output => $output,
return_code => $return_code, return_code => $return_code,
}}); }});
# Update the stored hostname
$anvil->data->{sys}{host_name} = $set;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"sys::host_name" => $anvil->data->{sys}{host_name},
}});
} }
else else
{ {
@ -3487,6 +3525,12 @@ sub host_name
host_name => $host_name, host_name => $host_name,
return_code => $return_code, return_code => $return_code,
}}); }});
# Update the stored hostname
$anvil->data->{sys}{host_name} = $host_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"sys::host_name" => $anvil->data->{sys}{host_name},
}});
} }
else else
{ {

@ -129,7 +129,7 @@ sub center_text
}}); }});
return($string) if $width eq ""; return($string) if $width eq "";
return("") if $parameter->{string} eq ""; return("") if $string eq "";
### NOTE: If a '#!string!x!#' is passed, the Log->entry method will translate it in the log itself, ### NOTE: If a '#!string!x!#' is passed, the Log->entry method will translate it in the log itself,
### so you won't see that string. ### so you won't see that string.

@ -1505,6 +1505,9 @@ sub check_local_network
}}); }});
$anvil->data->{sys}{host_name} = $new_host_name; $anvil->data->{sys}{host_name} = $new_host_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
'sys::host_name' => $anvil->data->{sys}{host_name},
}});
# If the hostname isn't the same, change it. # If the hostname isn't the same, change it.
if ($old_host_name ne $new_host_name) if ($old_host_name ne $new_host_name)
@ -1540,6 +1543,10 @@ sub check_local_network
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "job_0077", variables => { host_name => $new_host_name }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "job_0077", variables => { host_name => $new_host_name }});
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
'sys::host_name' => $anvil->data->{sys}{host_name},
}});
# Read the local network manager data. # Read the local network manager data.
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0080"); update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0080");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "job_0080"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "job_0080"});

@ -663,6 +663,8 @@ while(1)
my $centered_failures = $anvil->Words->center_text({string => $fail_count, width => $failures_length}); my $centered_failures = $anvil->Words->center_text({string => $fail_count, width => $failures_length});
my $centered_mac_address = $anvil->Words->center_text({string => $mac_address, width => $mac_length}); my $centered_mac_address = $anvil->Words->center_text({string => $mac_address, width => $mac_length});
$anvil->data->{bond}{$bond_name}{slave}{$in_slave}{mii_status_raw} = "" if not $anvil->data->{bond}{$bond_name}{slave}{$in_slave}{mii_status_raw};
my $iface_name_colour = $anvil->data->{bond}{$bond_name}{slave}{$in_slave}{mii_status_raw} eq "up" ? $anvil->data->{colours}{bond}{interface} : $anvil->data->{bond}{$bond_name}{slave}{$in_slave}{status_colour}; my $iface_name_colour = $anvil->data->{bond}{$bond_name}{slave}{$in_slave}{mii_status_raw} eq "up" ? $anvil->data->{colours}{bond}{interface} : $anvil->data->{bond}{$bond_name}{slave}{$in_slave}{status_colour};
my $say_iface_name = colored($centered_iface_name, $iface_name_colour); my $say_iface_name = colored($centered_iface_name, $iface_name_colour);

Loading…
Cancel
Save