From ff0e6c3575707fe19ad1c4a53dd0561b3c270c61 Mon Sep 17 00:00:00 2001 From: digimer Date: Sat, 13 Jan 2024 20:17:59 -0500 Subject: [PATCH] Updated anvil-daemon to call scan-network if no interfaces exist. Signed-off-by: digimer --- Anvil/Tools/Network.pm | 34 ++++++++++++++++++++++++++++++++++ tools/anvil-daemon | 21 +++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Anvil/Tools/Network.pm b/Anvil/Tools/Network.pm index 82ba92e3..9ed4baf0 100644 --- a/Anvil/Tools/Network.pm +++ b/Anvil/Tools/Network.pm @@ -1354,6 +1354,15 @@ sub collect_data } next; } + if ($line =~ / (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)$/i) + { + # This is the real MAC address of the link. + my $mac_address = $1; + $anvil->data->{nmcli}{perm_mac_address}{$in_link} = $mac_address; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "nmcli::perm_mac_address::${in_link}" => $anvil->data->{nmcli}{perm_mac_address}{$in_link}, + }}); + } } else { @@ -1427,6 +1436,8 @@ sub collect_data my $mtu_file = "/sys/class/net/".$device."/mtu"; if (-e $mac_address_file) { + ### NOTE: This will always be the active link's MAC in a bond, so tis gets + ### overwritten when the bond device is parsed. my $mac_address = $anvil->Storage->read_file({file => $mac_address_file}); $mac_address =~ s/\n$//; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mac_address => $mac_address }}); @@ -1472,6 +1483,29 @@ sub collect_data } } + # Loop through interfaces and see if the MAC address needs to be updated if it's the backup interface + # in a bond. + foreach my $device (sort {$a cmp $b} keys %{$anvil->data->{nmcli}{interface}}) + { + my $uuid = $anvil->data->{nmcli}{interface}{$device}{uuid}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "s1:device" => $device, + "s2:uuid" => $uuid, + }}); + + if ((exists $anvil->data->{nmcli}{perm_mac_address}{$device}) && ($anvil->data->{nmcli}{perm_mac_address}{$device})) + { + # There's a permanent MAC address, overwrite the one we read earlier. + my $perm_mac_address = $anvil->data->{nmcli}{perm_mac_address}{$device}; + $anvil->data->{nmcli}{uuid}{$uuid}{mac_address} = $perm_mac_address; + $anvil->data->{nmcli}{mac_address}{$perm_mac_address}{uuid} = $uuid; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "s1:nmcli::uuid::${uuid}::mac_address" => $anvil->data->{nmcli}{uuid}{$uuid}{mac_address}, + "s2:nmcli::mac_address::${perm_mac_address}::uuid" => $anvil->data->{nmcli}{mac_address}{$perm_mac_address}{uuid}, + }}); + } + } + # Should we start interfaces? if ($start) { diff --git a/tools/anvil-daemon b/tools/anvil-daemon index 794827c1..9d0c002a 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -405,6 +405,27 @@ sub check_network } } + # Check that there's at least one entry in 'network_interfaces' and, if not, call scan-network. + if (1) + { + my $query = "SELECT COUNT(*) FROM network_interfaces WHERE network_interface_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid).";"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); + + my $count = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }}); + if (not $count) + { + # Run scan-network + my $shell_call = $anvil->data->{path}{directories}{scan_agents}."/scan-network/scan-network".$anvil->Log->switches; + $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(0); }