Updated anvil-daemon to call scan-network if no interfaces exist.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 11 months ago
parent 518fddfa82
commit ff0e6c3575
  1. 34
      Anvil/Tools/Network.pm
  2. 21
      tools/anvil-daemon

@ -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)
{

@ -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);
}

Loading…
Cancel
Save