More progress on the new NM version of anvil-configure-host

* It's technically done, but I know bugs remain.
* Updated Jobs->update_progress() to take 'file' and 'line' to make it
  easier in the logs to see the origin of the message, when logging the
  update.
* Created Network->modify_connection() to update network manager
  variables. Created ->reset_connection() to take an interface down and
  bring it back up again.
* Fixed a bug in scan-network where the device_to_uuid hash wasn't being
  stored.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 11 months ago
parent 83057d0b45
commit 518fddfa82
  1. 16
      Anvil/Tools/Job.pm
  2. 117
      Anvil/Tools/Network.pm
  3. 6
      scancore-agents/scan-network/scan-network
  4. 48
      share/words.xml
  5. 1467
      tools/anvil-configure-host

@ -616,10 +616,18 @@ B<< Note >>: Some special C<< job_status >> processing is done to support some s
Parameters;
=head3 file (optional)
When logging as well, this is the file causing the update. Use with C<< line >>. Ignored if C<< log_level >> is not set, or such that it wouldn't be logged anyway.
=head3 job_uuid (optional, default 'jobs::job_uuid')
This is the UUID of the job to update. If it isn't set, but C<< jobs::job_uuid >> is set, it will be used. If that is also not set,
=head3 line (optional_
When logging as well, this is the line the update came from. Use with C<< file >>. Ignored if C<< log_level >> is not set, or such that it wouldn't be logged anyway.
=head3 log_level (optional)
If set to a numeric level, the job's message will also be logged. This is designed to simplify code as most job progress messages will also want to be logged.
@ -663,7 +671,9 @@ sub update_progress
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Job->update_progress()" }});
my $file = defined $parameter->{file} ? $parameter->{file} : $THIS_FILE;
my $job_uuid = defined $parameter->{job_uuid} ? $parameter->{job_uuid} : "";
my $line = defined $parameter->{line} ? $parameter->{line} : __LINE__;
my $log_level = defined $parameter->{log_level} ? $parameter->{log_level} : "";
my $message = defined $parameter->{message} ? $parameter->{message} : "";
my $picked_up_by = defined $parameter->{picked_up_by} ? $parameter->{picked_up_by} : "";
@ -673,11 +683,13 @@ sub update_progress
my $secure = defined $parameter->{secure} ? $parameter->{secure} : "";
my $variables = defined $parameter->{variables} ? $parameter->{variables} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
file => $file,
job_uuid => $job_uuid,
line => $line,
log_level => $log_level,
picked_up_by => $picked_up_by,
'print' => $print,
progress => $progress,
log_level => $log_level,
message => $message,
variables => $variables,
secure => $secure,
@ -687,7 +699,7 @@ sub update_progress
if (($message ne "clear") && ($log_level =~ /^\d+$/))
{
# Log this message.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $log_level, 'print' => $print, secure => $secure, priority => $priority, key => $message, variables => $variables});
$anvil->Log->entry({source => $file, line => $line, level => $log_level, 'print' => $print, secure => $secure, priority => $priority, key => $message, variables => $variables});
}
if ($picked_up_by eq "")

@ -32,8 +32,10 @@ my $THIS_FILE = "Network.pm";
# load_interfces
# load_ips
# manage_firewall
# modify_connection
# ping
# read_nmcli
# reset_connection
# _check_firewalld_conf
# _get_existing_zone_interfaces
# _get_server_ports
@ -4320,6 +4322,68 @@ sub manage_firewall
return(0);
}
=head3 modify_connection
This takes a network manager connection UUID, and changes the requested variable to be set to the given value.
The command output and return code are returned. If there is a problem, C<< !!error!! >> is returned.
Parameters
=head3 uuid (required)
This is the network manager UUID of the connection being worked on.
=head3 variable (required)
This is the name of the variable to set (as shown in C<< nmcli connection show <uuid> >>).
=head3 value (optional, defult "")
This is the value to set. Note that and empty string (C<< "" >>) deletes the variable.
=cut
sub modify_connection
{
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 => "Network->modify_connection()" }});
my $uuid = defined $parameter->{uuid} ? $parameter->{uuid} : "";
my $variable = defined $parameter->{variable} ? $parameter->{variable} : "";
my $value = defined $parameter->{value} ? $parameter->{value} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
variable => $variable,
value => $value,
}});
if (not $uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->modify_connection()", parameter => "uuid" }});
return("!!error!!");
}
if (not $variable)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->modify_connection()", parameter => "variable" }});
return("!!error!!");
}
my $shell_call = $anvil->data->{path}{exe}{nmcli}." connection modify ".$uuid." ".$variable." ".$value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
return($output, $return_code);
}
=head2 ping
@ -4754,6 +4818,59 @@ sub read_nmcli
return(0);
}
=head2 reset_connection
This method takes a network manager connection UUID and resets the connection by calling it C<< down >> and then C<< up >>.
If there is a problem, C<< !!error!! >> is returned. Otherwise, the output and return code from the C<< up >> call are returned.
Parameters;
=head3 uuid (required)
This is the UUID of the connection to reset.
=cut
sub reset_connection
{
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 => "Network->reset_connection()" }});
my $uuid = defined $parameter->{uuid} ? $parameter->{uuid} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
}});
if (not $uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->reset_connection()", parameter => "uuid" }});
return("!!error!!");
}
my $shell_call = $anvil->data->{path}{exe}{nmcli}." connection down ".$uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
$shell_call = $anvil->data->{path}{exe}{nmcli}." connection up ".$uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
return($output, $return_code);
}
#############################################################################################################
# Private functions #
#############################################################################################################

@ -535,6 +535,10 @@ sub collect_data
{
my ($anvil) = @_;
# Read in data from Network Manager
$anvil->Network->collect_data({debug => 2});
### TODO: We can get the IPs from collect_data, we should phase this out.
# The 'local_host' is needed to pull data recorded by Network->get_ips();
$anvil->Network->get_ips({debug => 2});
my $local_host = $anvil->Get->short_host_name();
@ -2474,12 +2478,14 @@ WHERE
$anvil->data->{network_interfaces}{uuid_to_name}{$network_interface_uuid} = $network_interface_name;
$anvil->data->{network_interfaces}{mac_to_uuid}{$network_interface_mac_address} = $network_interface_uuid;
$anvil->data->{interface}{name_to_uuid}{$network_interface_name} = $network_interface_uuid;
$anvil->data->{interface}{device_to_uuid}{$network_interface_device} = $network_interface_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"network_interfaces::name_to_uuid::${network_interface_name}" => $anvil->data->{network_interfaces}{name_to_uuid}{$network_interface_name},
"network_interfaces::device_to_uuid::${network_interface_device}" => $anvil->data->{network_interfaces}{device_to_uuid}{$network_interface_device},
"network_interfaces::uuid_to_name::${network_interface_name}" => $anvil->data->{network_interfaces}{uuid_to_name}{$network_interface_uuid},
"network_interfaces::mac_to_uuid::${network_interface_mac_address}" => $anvil->data->{network_interfaces}{mac_to_uuid}{$network_interface_mac_address},
"interface::name_to_uuid::${network_interface_name}" => $anvil->data->{interface}{name_to_uuid}{$network_interface_name},
"interface::device_to_uuid::${network_interface_device}" => $anvil->data->{interface}{device_to_uuid}{$network_interface_device},
}});
}

@ -755,6 +755,30 @@ The XML that failed sanity check was:
<key name="error_0480">[ Error ] - The wanted interface: [#!variable!interface_name!#] which should have the MAC address: [#!variable!mac_address!#] was not found in Network Manager. Unable to proceed.</key>
<key name="error_0481">[ Error ] - Failed to delete the 'connection.interface-name', got: [#!variable!output!#] and it should bhave been blank, aborting!</key>
<key name="error_0482">[ Error ] - Failed to create the 'match.interface-name' value. Expected: [#!variable!new_name!#,#!variable!old_device!#], got: [#!variable!output!#], aborting!</key>
<key name="error_0483">[ Error ] - The attempt to add the bond: [#!variable!bond_name!#] failed! The return code was: [#!variable!return_code!#]. The output, if any, was:
========
#!variable!output!#
========
</key>
<key name="error_0484">[ Error ] - The attempt to add the network link: [#!variable!link_name!#] to the bond: [#!variable!bond_name!#] failed! The return code was: [#!variable!return_code!#]. The output, if any, was:
========
#!variable!output!#
========
</key>
<key name="error_0485">[ Error ] - The attempt to add the bridge: [#!variable!bridge_name!# failed! The return code was: [#!variable!return_code!#]. The output, if any, was:
========
#!variable!output!#
========
</key>
<key name="error_0486">[ Error ] - The attempt to add the device: [#!variable!on_device!#] to the bridge: [#!variable!bridge_name!#] failed! The return code was: [#!variable!return_code!#]. The output, if any, was:
========
#!variable!output!#
========
</key>
<key name="error_0487">[ Error ] - The subnet_mask: [#!variable!subnet_mask!#] is not valid. It must be either a CIDR notation, or a dotted-decimal mask that can be translated to CIDR notation.</key>
<key name="error_0488">[ Error ] - Can't find a device to assign the: [#!variable!network!#] IP address: [#!variable!ip_address!#/#!variable!subnet_mask!#] to!</key>
<key name="error_0489">[ Error ] - Failed to map the IP address: [#!variable!ip_address!#] to a network manager connection UUID!</key>
<key name="error_0490">[ Error ] - Both the netbios name: [#!variable!wanted_link_name!#] and the old device name: [#!variable!old_device!#] are the same, 'match.interface-name' would break!</key>
<!-- Files templates -->
<!-- NOTE: Translating these files requires an understanding of which lines are translatable -->
@ -3296,7 +3320,29 @@ proceeding.
<key name="message_0389">Rebooting NOW! The job will restart on reboot.</key>
<key name="message_0390">Checking if the bond: [#!variable!bond_name!#] exists or not.</key>
<key name="message_0391">- It does, its UUID is: [#!variable!nm_uuid!#].</key>
<key name="message_0392">- The bond: [#!variable!bond_name!#] doesn't exist. Will create it using the primary interface: [#!variable!link1_name!#] (MAC: [#!variable!link1_mac!#], NM UUID: [#!variable!link1_nm_uuid!#) and the backup interface: : [#!variable!link2_name!#] (MAC: [#!variable!link2_mac!#], NM UUID: [#!variable!link2_nm_uuid!#).</key>
<key name="message_0392">- The bond: [#!variable!bond_name!#] doesn't exist. Will create it using the primary interface: [#!variable!link1_name!#] (MAC: [#!variable!link1_mac!#], NM UUID: [#!variable!link1_nm_uuid!#) and the backup interface: [#!variable!link2_name!#] (MAC: [#!variable!link2_mac!#], NM UUID: [#!variable!link2_nm_uuid!#).</key>
<key name="message_0393">Checking to see if the IP address: [#!variable!ip_address!#/#!variable!subnet_mask!#] is assigned to: [#!variable!device!#] yet.</key>
<key name="message_0394"> - Done! Rescanning the network config.</key>
<key name="message_0395">- The interface: [#!variable!link_name!#] (#!variable!nm_uuid!#) is already a member of the bond.</key>
<key name="message_0396">- The interface: [#!variable!link_name!#] (#!variable!nm_uuid!#) is a member of the bond: [#!variable!old_bond!#], switching it to this bond.</key>
<key name="message_0397">- The interface: [#!variable!link_name!#] (#!variable!nm_uuid!#) needs to be connected to the bond.</key>
<key name="message_0398">- The IP exists, checking if it needs to be updated.</key>
<key name="message_0399"> - Connecting the interface: [#!variable!link_name!#] to the bond: [#!variable!bond_name!#].</key>
<key name="message_0400">Checking if the bridge: [#!variable!bridge_name!#] exists and that it is on: [#!variable!on_device!#]</key>
<key name="message_0401">- The bridge exists!</key>
<key name="message_0402">- The IP address is on: [#!variable!current_device!#], will move the IP.</key>
<key name="message_0403"> - Resetting the device: [#!variable!device!#] (#!variable!device_uuid!#) to make sure the new config takes effect.</key>
<key name="message_0404">- Checking that the device: [#!variable!on_device!#] is connected to this bridge.</key>
<key name="message_0405">- The device is connected to the bridge already.</key>
<key name="message_0406">- The device is on the bridge: [#!variable!on_device_parent!#], moving it.</key>
<key name="message_0407">- The device is not on this bridge, connecting it.</key>
<key name="message_0408"> - Disabling DHCP on the device: [#!variable!device!#] (#!variable!device_uuid!#).</key>
<key name="message_0409"> - Connecting it now.</key>
<key name="message_0410">- The current subnet mask is: [#!variable!current_subnet_mask!#], will update.</key>
<key name="message_0411">- The current gateway is: [#!variable!current_gateway!#], will update.</key>
<key name="message_0412">- The current DNS is: [#!variable!current_dns!#], will update.</key>
<key name="message_0413">- No update is needed.</key>
<key name="message_0414">- The IP address needs to be assigned.</key>
<!-- Translate names (protocols, etc) -->
<key name="name_0001">Normal Password</key> <!-- none in mail-server -->

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save