Fixed several bugs around renaming interfaces

* Also fixed problems with scan-network related to the new network
  naming / NM system.
* Updated Database->insert_or_update_network_interfaces() to better
  search for a network_interface_uuid when not specified.
* Updated Network->collect_data() to take the new 'start' parameter
  which, when set, brings up unconfigured connections/devices.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 12 months ago
parent 92ddf27979
commit 83057d0b45
  1. 62
      Anvil/Tools/Database.pm
  2. 208
      Anvil/Tools/Network.pm
  3. 191
      scancore-agents/scan-network/scan-network
  4. 2
      scancore-agents/scan-network/scan-network.xml
  5. 97
      tools/anvil-configure-host

@ -11601,6 +11601,68 @@ AND
$network_interface_uuid = $results->[0]->[0]; $network_interface_uuid = $results->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { network_interface_uuid => $network_interface_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { network_interface_uuid => $network_interface_uuid }});
} }
elsif ($network_interface_device)
{
# Try again using the device name.
my $query = "
SELECT
network_interface_uuid
FROM
network_interfaces
WHERE ";
if ($network_interface_name !~ /^vnet/)
{
$query .= "
network_interface_mac_address = ".$anvil->Database->quote($network_interface_mac_address)."
AND ";
}
### TODO: We may need to switch this to 'device' if the name or MAC address isn't found
$query .= "
network_interface_device = ".$anvil->Database->quote($network_interface_device)."
AND
network_interface_host_uuid = ".$anvil->Database->quote($network_interface_host_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if ($count)
{
$network_interface_uuid = $results->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { network_interface_uuid => $network_interface_uuid }});
}
}
elsif ($network_interface_name !~ /^vnet/)
{
# Try finding it by MAC
my $query = "
SELECT
network_interface_uuid
FROM
network_interfaces
WHERE
network_interface_mac_address = ".$anvil->Database->quote($network_interface_mac_address)."
AND
network_interface_host_uuid = ".$anvil->Database->quote($network_interface_host_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if ($count)
{
$network_interface_uuid = $results->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { network_interface_uuid => $network_interface_uuid }});
}
}
if (($link_only) && (not $network_interface_uuid)) if (($link_only) && (not $network_interface_uuid))
{ {

@ -956,9 +956,13 @@ Bridge data is simple, but also made easy to find. The only real data is the has
To make it easier to find interfaces, the following look up hash is available. To make it easier to find interfaces, the following look up hash is available.
* nmcli::interface::<device>::uuid = The UUID of the interface * nmcli::interface::<device>::uuid = The UUID of the interface
* nmcli::mac_address::<mac_address>::uuid = $anvil->data->{nmcli}{mac_address}{$mac_address}{uuid}, * nmcli::mac_address::<mac_address>::uuid = MAC address
This method takes no parameters Parameters;
=head3 start (optional, default '0')
If this is set to C<< 1 >>, any connetions found to be down and not referencing any devices will be assigned the unroutable IP C<< 169.0.0.x >>, where C<< x >> is a sequential number. This should bring up unconfigured devices.
=cut =cut
sub collect_data sub collect_data
@ -969,8 +973,13 @@ sub collect_data
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Network->check_internet()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Network->check_internet()" }});
my $start = defined $parameter->{start} ? $parameter->{start} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
start => $start,
}});
# Use nmcli to collect the data. # Use nmcli to collect the data.
my $shell_call = $anvil->data->{path}{exe}{nmcli}." --get-values uuid,type,active,state connection show"; my $shell_call = $anvil->data->{path}{exe}{nmcli}." --get-values uuid,type,active,state,name connection show";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); $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}); my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
@ -980,17 +989,19 @@ sub collect_data
foreach my $line (split/\n/, $output) foreach my $line (split/\n/, $output)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
if ($line =~ /^(.*?):(.*?):(.*?):(.*?)$/) if ($line =~ /^(.*?):(.*?):(.*?):(.*?):(.*?)$/)
{ {
my $uuid = $1; my $uuid = $1;
my $type = $2; my $type = $2;
my $active = $3; my $active = $3;
my $state = $4; my $state = $4;
my $nm_name = $4; # biosdevname
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
uuid => $uuid, uuid => $uuid,
type => $type, type => $type,
active => $active, active => $active,
'state' => $state, 'state' => $state,
nm_name => $nm_name,
}}); }});
next if $type eq "loopback"; next if $type eq "loopback";
@ -1003,10 +1014,12 @@ sub collect_data
$anvil->data->{nmcli}{uuid}{$uuid}{type} = $type; $anvil->data->{nmcli}{uuid}{$uuid}{type} = $type;
$anvil->data->{nmcli}{uuid}{$uuid}{active} = lc($active) eq "yes" ? 1 : 0; $anvil->data->{nmcli}{uuid}{$uuid}{active} = lc($active) eq "yes" ? 1 : 0;
$anvil->data->{nmcli}{uuid}{$uuid}{'state'} = lc($state); $anvil->data->{nmcli}{uuid}{$uuid}{'state'} = lc($state);
$anvil->data->{nmcli}{uuid}{$uuid}{nm_name} = $nm_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::uuid::${uuid}::type" => $anvil->data->{nmcli}{uuid}{$uuid}{type}, "nmcli::uuid::${uuid}::type" => $anvil->data->{nmcli}{uuid}{$uuid}{type},
"nmcli::uuid::${uuid}::active" => $anvil->data->{nmcli}{uuid}{$uuid}{active}, "nmcli::uuid::${uuid}::active" => $anvil->data->{nmcli}{uuid}{$uuid}{active},
"nmcli::uuid::${uuid}::state" => $anvil->data->{nmcli}{uuid}{$uuid}{'state'}, "nmcli::uuid::${uuid}::state" => $anvil->data->{nmcli}{uuid}{$uuid}{'state'},
"nmcli::uuid::${uuid}::nm_name" => $anvil->data->{nmcli}{uuid}{$uuid}{nm_name},
}}); }});
} }
} }
@ -1036,6 +1049,12 @@ sub collect_data
's2:value' => $value, 's2:value' => $value,
}}); }});
if ($value eq "--")
{
$value = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { value => $value }});
}
$anvil->data->{nmcli}{uuid}{$uuid}{$variable} = $value; $anvil->data->{nmcli}{uuid}{$uuid}{$variable} = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::uuid::${uuid}::${variable}" => $anvil->data->{nmcli}{uuid}{$uuid}{$variable}, "nmcli::uuid::${uuid}::${variable}" => $anvil->data->{nmcli}{uuid}{$uuid}{$variable},
@ -1138,7 +1157,7 @@ sub collect_data
{ {
$anvil->data->{nmcli}{uuid}{$uuid}{$hash_key}{dns} .= ",".$value; $anvil->data->{nmcli}{uuid}{$uuid}{$hash_key}{dns} .= ",".$value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::uuid::${uuid}::${hash_key}::dns" => $anvil->data->{nmcli}{uuid}{$uuid}{$sequence}{dns}, "nmcli::uuid::${uuid}::${hash_key}::dns" => $anvil->data->{nmcli}{uuid}{$uuid}{$hash_key}{dns},
}}); }});
} }
else else
@ -1167,27 +1186,38 @@ sub collect_data
} }
} }
# Now loop through and look for the name that maps to what's shown in 'ip addr list'. This can be a bit tricky. # Now loop through and look for the name that maps to what's shown in 'ip addr list'. This can be a
# bit tricky.
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{nmcli}{uuid}}) foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{nmcli}{uuid}})
{ {
### NOTE: The 'connection_id' is the 'network_interface_name' (biosdevname) and it is always
### available, 'GENERAL.IP-IFACE' is the 'network_interface_device' and is only
### available when the interface is up.
my $connection_id = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.id'} // ""; my $connection_id = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.id'} // "";
my $connection_interface_name = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.interface-name'} // "";
my $general_devices = $anvil->data->{nmcli}{uuid}{$uuid}{'GENERAL.DEVICES'} // "";
my $general_ip_iface = $anvil->data->{nmcli}{uuid}{$uuid}{'GENERAL.IP-IFACE'} // ""; my $general_ip_iface = $anvil->data->{nmcli}{uuid}{$uuid}{'GENERAL.IP-IFACE'} // "";
$general_ip_iface = "" if $general_ip_iface eq "--";
my $device_type = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.type'} // ""; my $device_type = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.type'} // "";
my $connection_interface_name = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.interface-name'} // "";
my $match_interface_name = $anvil->data->{nmcli}{uuid}{$uuid}{'match.interface-name'} // ""; my $match_interface_name = $anvil->data->{nmcli}{uuid}{$uuid}{'match.interface-name'} // "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:uuid' => $uuid, 's1:uuid' => $uuid,
's2:connection_id' => $connection_id, 's2:connection_id' => $connection_id,
's3:connection_interface_name' => $connection_interface_name, 's3:general_ip_iface' => $general_ip_iface,
's4:general_devices' => $general_devices, 's4:device_type' => $device_type,
's5:general_ip_iface' => $general_ip_iface, 's5:connection_interface_name' => $connection_interface_name,
's6:device_type' => $device_type, 's6:match_interface_name' => $match_interface_name,
's7:match_interface_name' => $match_interface_name,
}}); }});
# An unrenamed interface will have a default 'Wired connection X' name, not he biosdevname
# name. So if there's not 'match.interface_name', use the 'connection.interface-name'.
if ((not $match_interface_name) && ($connection_interface_name))
{
$connection_id = $connection_interface_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { connection_id => $connection_id }});
}
# If there isn't a GENERAL.DEVICES or GENERAL.IP-IFACE, the link is down. Use the match.interface-name. # If there isn't a GENERAL.DEVICES or GENERAL.IP-IFACE, the link is down. Use the match.interface-name.
if (((not $general_devices) or (not $general_ip_iface)) && ($match_interface_name)) if ((not $general_ip_iface) && ($match_interface_name))
{ {
foreach my $interface (split/,/, $match_interface_name) foreach my $interface (split/,/, $match_interface_name)
{ {
@ -1195,41 +1225,33 @@ sub collect_data
next if $connection_id eq $interface; next if $connection_id eq $interface;
if ($interface) if ($interface)
{ {
$general_devices = $interface if not $general_devices; $general_ip_iface = $interface;
$general_ip_iface = $interface if not $general_ip_iface; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { general_ip_iface => $general_ip_iface }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
general_devices => $general_devices,
general_ip_iface => $general_ip_iface,
}});
} }
last if $general_ip_iface;
} }
} }
my $device = ""; # Make it easier to lookup this device by name.
if (($general_ip_iface) && ($general_ip_iface ne "--")) $anvil->data->{nmcli}{name}{$connection_id}{uuid} = $uuid;
{ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$device = $general_ip_iface; "nmcli::name::${connection_id}::uuid" => $anvil->data->{nmcli}{name}{$connection_id}{uuid},
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { device => $device }}); }});
}
elsif (($connection_interface_name) && ($connection_interface_name ne "--")) if ((not $general_ip_iface) && (not $connection_interface_name))
{
$device = $connection_interface_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { device => $device }});
}
elsif (($general_devices) && ($general_devices ne "--"))
{ {
$device = $connection_interface_name; # This connection is down, so it's not linked to a device.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { device => $device }}); next;
} }
if ($device) my $device = $general_ip_iface ? $general_ip_iface : $connection_interface_name;
{
$anvil->data->{nmcli}{device}{$device}{uuid} = $uuid; $anvil->data->{nmcli}{device}{$device}{uuid} = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::device::${device}::uuid" => $anvil->data->{nmcli}{device}{$device}{uuid}, "nmcli::device::${device}::uuid" => $anvil->data->{nmcli}{device}{$device}{uuid},
}}); }});
### Get some data from sysfs. ### Get some data from sysfs.
$anvil->data->{nmcli}{uuid}{$uuid}{name} = $connection_id;
$anvil->data->{nmcli}{uuid}{$uuid}{device} = $device; $anvil->data->{nmcli}{uuid}{$uuid}{device} = $device;
$anvil->data->{nmcli}{uuid}{$uuid}{mac_address} = ""; $anvil->data->{nmcli}{uuid}{$uuid}{mac_address} = "";
$anvil->data->{nmcli}{uuid}{$uuid}{type} = ""; $anvil->data->{nmcli}{uuid}{$uuid}{type} = "";
@ -1247,13 +1269,15 @@ sub collect_data
if ($device_type eq "bond") if ($device_type eq "bond")
{ {
$anvil->data->{nmcli}{bond}{$device}{uuid} = $uuid; # Bonds always have the name we chose as the connection.id as they don't have
# biosdevnames.
$anvil->data->{nmcli}{bond}{$connection_id}{uuid} = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::bond::${device}::uuid" => $anvil->data->{nmcli}{bond}{$device}{uuid}, "nmcli::bond::${connection_id}::uuid" => $anvil->data->{nmcli}{bond}{$connection_id}{uuid},
}}); }});
# Read the interface's carrier # Read the interface's carrier
my $carrier_file = "/sys/class/net/".$device."/carrier"; my $carrier_file = "/sys/class/net/".$connection_id."/carrier";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { carrier_file => $carrier_file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { carrier_file => $carrier_file }});
if (-e $carrier_file) if (-e $carrier_file)
@ -1262,13 +1286,13 @@ sub collect_data
chomp $carrier; chomp $carrier;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { carrier => $carrier }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { carrier => $carrier }});
$anvil->data->{nmcli}{bond}{$device}{carrier} = $carrier; $anvil->data->{nmcli}{bond}{$connection_id}{carrier} = $carrier;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"nmcli::bond::${device}::carrier" => $anvil->data->{nmcli}{bond}{$device}{carrier}, "nmcli::bond::${connection_id}::carrier" => $anvil->data->{nmcli}{bond}{$connection_id}{carrier},
}}); }});
} }
my $operstate_file = "/sys/class/net/".$device."/operstate"; my $operstate_file = "/sys/class/net/".$connection_id."/operstate";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { operstate_file => $operstate_file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { operstate_file => $operstate_file }});
if (-e $operstate_file) if (-e $operstate_file)
@ -1277,14 +1301,14 @@ sub collect_data
chomp $operstate; chomp $operstate;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { operstate => $operstate }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { operstate => $operstate }});
$anvil->data->{nmcli}{bond}{$device}{up} = $operstate eq "up" ? 1 : 0; $anvil->data->{nmcli}{bond}{$connection_id}{up} = $operstate eq "up" ? 1 : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"nmcli::bond::${device}::operstate" => $anvil->data->{nmcli}{bond}{$device}{operstate}, "nmcli::bond::${connection_id}::operstate" => $anvil->data->{nmcli}{bond}{$connection_id}{operstate},
}}); }});
} }
# Read in the /proc file. # Read in the /proc file.
my $proc_file = "/proc/net/bonding/".$device; my $proc_file = "/proc/net/bonding/".$connection_id;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { proc_file => $proc_file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { proc_file => $proc_file }});
my $in_link = ""; my $in_link = "";
@ -1314,16 +1338,16 @@ sub collect_data
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { status => $status }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { status => $status }});
if ($status eq "up") if ($status eq "up")
{ {
$anvil->data->{nmcli}{bond}{$device}{interface}{$in_link}{up} = 1; $anvil->data->{nmcli}{bond}{$connection_id}{interface}{$in_link}{up} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"nmcli::bond::${device}::interface::${in_link}::up" => $anvil->data->{nmcli}{bond}{$device}{interface}{$in_link}{up}, "nmcli::bond::${connection_id}::interface::${in_link}::up" => $anvil->data->{nmcli}{bond}{$connection_id}{interface}{$in_link}{up},
}}); }});
} }
else else
{ {
$anvil->data->{nmcli}{bond}{$device}{interface}{$in_link}{up} = 0; $anvil->data->{nmcli}{bond}{$connection_id}{interface}{$in_link}{up} = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"nmcli::bond::${device}::interface::${in_link}::up" => $anvil->data->{nmcli}{bond}{$device}{interface}{$in_link}{up}, "nmcli::bond::${connection_id}::interface::${in_link}::up" => $anvil->data->{nmcli}{bond}{$connection_id}{interface}{$in_link}{up},
}}); }});
} }
next; next;
@ -1334,10 +1358,10 @@ sub collect_data
if ($line =~ /MII Status: (.*)$/) if ($line =~ /MII Status: (.*)$/)
{ {
my $status = $1; my $status = $1;
$anvil->data->{nmcli}{bond}{$device}{up} = $status eq "up" ? 1 : 0; $anvil->data->{nmcli}{bond}{$connection_id}{up} = $status eq "up" ? 1 : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
status => $status, status => $status,
"nmcli::bond::${device}::up" => $anvil->data->{nmcli}{bond}{$device}{up}, "nmcli::bond::${connection_id}::up" => $anvil->data->{nmcli}{bond}{$connection_id}{up},
}}); }});
next; next;
} }
@ -1346,13 +1370,15 @@ sub collect_data
} }
elsif ($device_type eq "bridge") elsif ($device_type eq "bridge")
{ {
$anvil->data->{nmcli}{bridge}{$device}{uuid} = $uuid; # Bonds always have the name we chose as the connection.id as they don't have
# biosdevnames.
$anvil->data->{nmcli}{bridge}{$connection_id}{uuid} = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::bridge::${device}::uuid" => $anvil->data->{nmcli}{bridge}{$device}{uuid}, "nmcli::bridge::${connection_id}::uuid" => $anvil->data->{nmcli}{bridge}{$connection_id}{uuid},
}}); }});
# See what interfaces are connected to the bridge. # See what interfaces are connected to the bridge.
my $shell_call = $anvil->data->{path}{exe}{ip}." link show master ".$device; my $shell_call = $anvil->data->{path}{exe}{ip}." link show master ".$connection_id;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); $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}); my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
@ -1372,15 +1398,22 @@ sub collect_data
status => $status, status => $status,
}}); }});
$anvil->data->{nmcli}{bridge}{$device}{interface}{$interface}{status} = $status; $anvil->data->{nmcli}{bridge}{$connection_id}{interface}{$interface}{status} = $status;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::bridge::${device}::interface::${interface}::status" => $anvil->data->{nmcli}{bridge}{$device}{interface}{$interface}{status}, "nmcli::bridge::${connection_id}::interface::${interface}::status" => $anvil->data->{nmcli}{bridge}{$connection_id}{interface}{$interface}{status},
}}); }});
} }
} }
} }
elsif (($device_type eq "802-3-ethernet") or ($device_type eq "interface")) elsif (($device_type eq "802-3-ethernet") or ($device_type eq "interface"))
{ {
# If we've got the if-name, use it. Otherwise, it's likely down and not renamed by
# us, so use the connection id.
my $device = $connection_id;
if (($general_ip_iface) && ($general_ip_iface ne "--"))
{
$device = $general_ip_iface;
}
$anvil->data->{nmcli}{interface}{$device}{uuid} = $uuid; $anvil->data->{nmcli}{interface}{$device}{uuid} = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::interface::${device}::uuid" => $anvil->data->{nmcli}{interface}{$device}{uuid}, "nmcli::interface::${device}::uuid" => $anvil->data->{nmcli}{interface}{$device}{uuid},
@ -1436,6 +1469,69 @@ sub collect_data
} }
} }
} }
# Should we start interfaces?
if ($start)
{
# Yup, but are there any to start? We'll set this to '1' if so and that will trigger a
# rescan.
my $rescan = 0;
# Sorted for log consistency on repeat runs
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{nmcli}{uuid}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::uuid::${uuid}::active" => $anvil->data->{nmcli}{uuid}{$uuid}{active},
"nmcli::uuid::${uuid}::active" => $anvil->data->{nmcli}{uuid}{$uuid}{'connection.interface-name'},
}});
if ((not $anvil->data->{nmcli}{uuid}{$uuid}{active}) && (not $anvil->data->{nmcli}{uuid}{$uuid}{'connection.interface-name'}))
{
# Find an IP
my $sequence = 1;
my $found = 0;
my $use_ip = "";
until ($found)
{
my $test_ip = "169.0.0.".$sequence;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { test_ip => $test_ip }});
if (not exists $anvil->data->{nmcli}{ipv4}{$test_ip})
{
$found = 1;
$use_ip = $test_ip;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
found => $found,
use_ip => $use_ip,
}});
}
else
{
$sequence++;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { sequence => $sequence }});
}
die "Failed to find an unused IP in 169.0.0.0/24\n" if $sequence > 255;
}
my $shell_call = $anvil->data->{path}{exe}{nmcli}." connection modify ".$uuid." ipv4.method manual ipv4.addresses ".$use_ip."/8";
$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,
}});
$rescan = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { rescan => $rescan }});
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { rescan => $rescan }});
if ($rescan)
{
# Give things a few seconds to settle
sleep 3;
# Rescan
$anvil->Network->collect_data({debug => $debug});
}
} }
return(0); return(0);

@ -70,7 +70,7 @@ if ($anvil->data->{switches}{purge})
} }
# If there's no DB (or cached data isn't recorded to the database yet), this will store those records. # If there's no DB (or cached data isn't recorded to the database yet), this will store those records.
$anvil->data->{cache}{new_file} = "# interface,timestamp,mac_address,speed,link_state,operational,nm_uuid,nm_device\n"; $anvil->data->{cache}{new_file} = "# interface (nm_device),timestamp,mac_address,speed,link_state,operational,nm_uuid,nm_name\n";
process_interface_cache($anvil); process_interface_cache($anvil);
# Read the data. # Read the data.
@ -124,9 +124,8 @@ sub process_interface_cache
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
next if $line =~ /^#/; next if $line =~ /^#/;
my ($interface, $timestamp, $mac_address, $speed, $link_state, $operational, $nm_uuid, $nm_device) = (split/,/, $line); my ($nm_device, $timestamp, $mac_address, $speed, $link_state, $operational, $nm_uuid, $nm_name) = (split/,/, $line);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
interface => $interface,
timestamp => $timestamp, timestamp => $timestamp,
speed => $speed, speed => $speed,
mac_address => $mac_address, mac_address => $mac_address,
@ -142,7 +141,7 @@ sub process_interface_cache
debug => 2, debug => 2,
link_only => 1, link_only => 1,
timestamp => $timestamp, timestamp => $timestamp,
network_interface_name => $interface, network_interface_name => $nm_device,
network_interface_link_state => $link_state, network_interface_link_state => $link_state,
network_interface_mac_address => $mac_address, network_interface_mac_address => $mac_address,
network_interface_operational => $operational, network_interface_operational => $operational,
@ -610,10 +609,10 @@ sub collect_data
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { full_path => $full_path }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { full_path => $full_path }});
if (-d $full_path) if (-d $full_path)
{ {
### NOTE: The 'interface' maps to the network manager 'GENERAL.IP-IFACE', which is
### 'network_interface_device'. The 'network_interface_name' is the biosdevname.
# Pull out the data I want. Note that some of these don't exist with virtio-net interfaces. # Pull out the data I want. Note that some of these don't exist with virtio-net interfaces.
my $interface = $file; my $interface = $file;
my $nm_uuid = $anvil->data->{nmcli}{interface}{$interface}{uuid} ? $anvil->data->{nmcli}{interface}{$interface}{uuid} : "";
my $nm_device = "";
my $link_state = -e $full_path."/carrier" ? $anvil->Storage->read_file({file => $full_path."/carrier"}) : 0; my $link_state = -e $full_path."/carrier" ? $anvil->Storage->read_file({file => $full_path."/carrier"}) : 0;
$link_state =~ s/\n$//; $link_state =~ s/\n$//;
my $mtu = -e $full_path."/mtu" ? $anvil->Storage->read_file({file => $full_path."/mtu"}) : 0; my $mtu = -e $full_path."/mtu" ? $anvil->Storage->read_file({file => $full_path."/mtu"}) : 0;
@ -633,7 +632,6 @@ sub collect_data
my $rx_bytes = 0; # How many bytes received my $rx_bytes = 0; # How many bytes received
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
interface => $interface, interface => $interface,
nm_uuid => $nm_uuid,
link_state => $link_state, link_state => $link_state,
mtu => $mtu, mtu => $mtu,
duplex => $duplex, duplex => $duplex,
@ -642,6 +640,31 @@ sub collect_data
modalias => $modalias, modalias => $modalias,
}}); }});
# Try to find the nm_uuid
my $nm_uuid = "";
if ((exists $anvil->data->{nmcli}{name}{$interface}) && ($anvil->data->{nmcli}{name}{$interface}{uuid}))
{
$nm_uuid = $anvil->data->{nmcli}{name}{$interface}{uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { nm_uuid => $nm_uuid }});
}
elsif ((exists $anvil->data->{nmcli}{device}{$interface}) && ($anvil->data->{nmcli}{device}{$interface}{uuid}))
{
$nm_uuid = $anvil->data->{nmcli}{device}{$interface}{uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { nm_uuid => $nm_uuid }});
}
my $nm_device = ""; # biosdevname
my $nm_name = ""; # ip name
if ($nm_uuid)
{
$nm_device = $anvil->data->{nmcli}{uuid}{$nm_uuid}{device};
$nm_name = $anvil->data->{nmcli}{uuid}{$nm_uuid}{name};
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
nm_device => $nm_device,
nm_name => $nm_name,
}});
### NOTE: This only parses virtio so far. ### NOTE: This only parses virtio so far.
# Pick out our driver. # Pick out our driver.
if ($modalias =~ /^virtio:/) if ($modalias =~ /^virtio:/)
@ -803,7 +826,6 @@ sub collect_data
{ {
# It's a bridge # It's a bridge
$type = "bridge"; $type = "bridge";
$nm_uuid = $anvil->data->{nmcli}{bridge}{$interface}{uuid};
$bridge_id = $anvil->Storage->read_file({debug => 3, file => $full_path."/bridge/bridge_id"}); $bridge_id = $anvil->Storage->read_file({debug => 3, file => $full_path."/bridge/bridge_id"});
$bridge_stp_enabled = $anvil->Storage->read_file({debug => 3, file => $full_path."/bridge/stp_state"}); $bridge_stp_enabled = $anvil->Storage->read_file({debug => 3, file => $full_path."/bridge/stp_state"});
$bridge_id =~ s/\n$//; $bridge_id =~ s/\n$//;
@ -811,7 +833,6 @@ sub collect_data
$speed = 0; $speed = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
type => $type, type => $type,
nm_uuid => $nm_uuid,
bridge_id => $bridge_id, bridge_id => $bridge_id,
bridge_stp_enabled => $bridge_stp_enabled, bridge_stp_enabled => $bridge_stp_enabled,
}}); }});
@ -830,12 +851,6 @@ sub collect_data
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bridge_stp_enabled => $bridge_stp_enabled }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bridge_stp_enabled => $bridge_stp_enabled }});
} }
if ($nm_uuid)
{
$nm_device = $anvil->data->{nmcli}{uuid}{$nm_uuid}{device};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { nm_device => $nm_device }});
}
# If this is a 'vnet' device, set 'operational' to up # If this is a 'vnet' device, set 'operational' to up
if ($interface =~ /^vnet/) if ($interface =~ /^vnet/)
{ {
@ -891,7 +906,7 @@ sub collect_data
} }
# Find the media, if possible. # Find the media, if possible.
(my $ethtool, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{ethtool}." $interface"}); (my $ethtool, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{ethtool}." ".$interface});
foreach my $line (split/\n/, $ethtool) foreach my $line (split/\n/, $ethtool)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
@ -913,6 +928,7 @@ sub collect_data
# Store new information we found. # Store new information we found.
$anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid} = $nm_uuid; $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid} = $nm_uuid;
$anvil->data->{network}{$local_host}{interface}{$interface}{nm_device} = $nm_device; $anvil->data->{network}{$local_host}{interface}{$interface}{nm_device} = $nm_device;
$anvil->data->{network}{$local_host}{interface}{$interface}{nm_name} = $nm_name;
$anvil->data->{network}{$local_host}{interface}{$interface}{active_interface} = $active_interface; $anvil->data->{network}{$local_host}{interface}{$interface}{active_interface} = $active_interface;
$anvil->data->{network}{$local_host}{interface}{$interface}{bond_mode} = $bond_mode; $anvil->data->{network}{$local_host}{interface}{$interface}{bond_mode} = $bond_mode;
$anvil->data->{network}{$local_host}{interface}{$interface}{bond_master} = $bond_master; $anvil->data->{network}{$local_host}{interface}{$interface}{bond_master} = $bond_master;
@ -936,6 +952,7 @@ sub collect_data
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"network::${local_host}::interface::${interface}::nm_uuid" => $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid}, "network::${local_host}::interface::${interface}::nm_uuid" => $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid},
"network::${local_host}::interface::${interface}::nm_device" => $anvil->data->{network}{$local_host}{interface}{$interface}{nm_device}, "network::${local_host}::interface::${interface}::nm_device" => $anvil->data->{network}{$local_host}{interface}{$interface}{nm_device},
"network::${local_host}::interface::${interface}::nm_name" => $anvil->data->{network}{$local_host}{interface}{$interface}{nm_name},
"network::${local_host}::interface::${interface}::active_interface" => $anvil->data->{network}{$local_host}{interface}{$interface}{active_interface}, "network::${local_host}::interface::${interface}::active_interface" => $anvil->data->{network}{$local_host}{interface}{$interface}{active_interface},
"network::${local_host}::interface::${interface}::bond_mode" => $anvil->data->{network}{$local_host}{interface}{$interface}{bond_mode}, "network::${local_host}::interface::${interface}::bond_mode" => $anvil->data->{network}{$local_host}{interface}{$interface}{bond_mode},
"network::${local_host}::interface::${interface}::bond_master" => $anvil->data->{network}{$local_host}{interface}{$interface}{bond_master}, "network::${local_host}::interface::${interface}::bond_master" => $anvil->data->{network}{$local_host}{interface}{$interface}{bond_master},
@ -965,7 +982,12 @@ sub collect_data
# If this is a link and there's no database connections, cache the data. # If this is a link and there's no database connections, cache the data.
if (($type eq "interface") && (not $anvil->data->{sys}{database}{connections})) if (($type eq "interface") && (not $anvil->data->{sys}{database}{connections}))
{ {
$anvil->data->{cache}{new_file} .= $interface.",".$anvil->Database->refresh_timestamp.",".$mac_address.",".$speed.",".$link_state.",".$operational.",".$nm_uuid.",".$nm_device."\n"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
nm_name => $nm_name,
nm_device => $nm_device,
}});
# nm_device,timestamp,mac_address,speed,link_state,operational,nm_uuid,nm_name
$anvil->data->{cache}{new_file} .= $nm_device.",".$anvil->Database->refresh_timestamp.",".$mac_address.",".$speed.",".$link_state.",".$operational.",".$nm_uuid.",".$nm_name."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cache::new_file" => $anvil->data->{cache}{new_file}, "cache::new_file" => $anvil->data->{cache}{new_file},
}}); }});
@ -1054,6 +1076,7 @@ sub collect_data
# Store the interface # Store the interface
$anvil->data->{new}{interface}{$interface}{nm_uuid} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid}; $anvil->data->{new}{interface}{$interface}{nm_uuid} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid};
$anvil->data->{new}{interface}{$interface}{nm_device} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_device}; $anvil->data->{new}{interface}{$interface}{nm_device} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_device};
$anvil->data->{new}{interface}{$interface}{nm_name} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_name};
$anvil->data->{new}{interface}{$interface}{bond_uuid} = ""; $anvil->data->{new}{interface}{$interface}{bond_uuid} = "";
$anvil->data->{new}{interface}{$interface}{bond_name} = $anvil->data->{network}{$local_host}{interface}{$interface}{bond_master}; $anvil->data->{new}{interface}{$interface}{bond_name} = $anvil->data->{network}{$local_host}{interface}{$interface}{bond_master};
$anvil->data->{new}{interface}{$interface}{bridge_uuid} = ""; $anvil->data->{new}{interface}{$interface}{bridge_uuid} = "";
@ -1070,6 +1093,7 @@ sub collect_data
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::interface::${interface}::nm_uuid" => $anvil->data->{new}{interface}{$interface}{nm_uuid}, "new::interface::${interface}::nm_uuid" => $anvil->data->{new}{interface}{$interface}{nm_uuid},
"new::interface::${interface}::nm_device" => $anvil->data->{new}{interface}{$interface}{nm_device}, "new::interface::${interface}::nm_device" => $anvil->data->{new}{interface}{$interface}{nm_device},
"new::interface::${interface}::nm_name" => $anvil->data->{new}{interface}{$interface}{nm_name},
"new::interface::${interface}::bond_uuid" => $anvil->data->{new}{interface}{$interface}{bond_uuid}, "new::interface::${interface}::bond_uuid" => $anvil->data->{new}{interface}{$interface}{bond_uuid},
"new::interface::${interface}::bond_name" => $anvil->data->{new}{interface}{$interface}{bond_name}, "new::interface::${interface}::bond_name" => $anvil->data->{new}{interface}{$interface}{bond_name},
"new::interface::${interface}::bridge_uuid" => $anvil->data->{new}{interface}{$interface}{bridge_uuid}, "new::interface::${interface}::bridge_uuid" => $anvil->data->{new}{interface}{$interface}{bridge_uuid},
@ -1114,6 +1138,7 @@ sub collect_data
### TODO: Remove this when ifcfg support is dropped. ### TODO: Remove this when ifcfg support is dropped.
sub collect_data_ifcfg sub collect_data_ifcfg
{ {
=cut
my ($anvil) = @_; my ($anvil) = @_;
# Read the data from the ifcfg files, if available. We'll use this to check for bond interfaces that # Read the data from the ifcfg files, if available. We'll use this to check for bond interfaces that
@ -1670,6 +1695,7 @@ sub collect_data_ifcfg
} }
return(0); return(0);
=cut
} }
# This reads in the states from the last can # This reads in the states from the last can
@ -2350,8 +2376,10 @@ sub load_interface_data
my $query = " my $query = "
SELECT SELECT
network_interface_uuid, network_interface_uuid,
network_interface_nm_uuid,
network_interface_mac_address, network_interface_mac_address,
network_interface_name, network_interface_name,
network_interface_device,
network_interface_speed, network_interface_speed,
network_interface_mtu, network_interface_mtu,
network_interface_link_state, network_interface_link_state,
@ -2376,12 +2404,14 @@ WHERE
foreach my $row (@{$results}) foreach my $row (@{$results})
{ {
my $network_interface_uuid = $row->[0]; my $network_interface_uuid = $row->[0];
my $network_interface_mac_address = $row->[1]; my $network_interface_mac_address = $row->[2];
my $network_interface_name = $row->[2]; my $network_interface_name = $row->[3];
my $network_interface_device = $row->[4];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
network_interface_uuid => $network_interface_uuid, network_interface_uuid => $network_interface_uuid,
network_interface_mac_address => $network_interface_mac_address, network_interface_mac_address => $network_interface_mac_address,
network_interface_name => $network_interface_name, network_interface_name => $network_interface_name,
network_interface_device => $network_interface_device,
}}); }});
# Read in the RX/TX values, set to '0' if not found. # Read in the RX/TX values, set to '0' if not found.
@ -2404,23 +2434,27 @@ WHERE
tx_variable_uuid => $tx_variable_uuid, tx_variable_uuid => $tx_variable_uuid,
}}); }});
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_nm_uuid} = $row->[1];
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mac_address} = $network_interface_mac_address; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mac_address} = $network_interface_mac_address;
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_name} = $network_interface_name; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_name} = $network_interface_name;
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_speed} = $row->[3]; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_device} = $network_interface_device;
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mtu} = $row->[4]; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_speed} = $row->[5];
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_link_state} = $row->[5]; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mtu} = $row->[6];
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_operational} = $row->[6]; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_link_state} = $row->[7];
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_duplex} = $row->[7]; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_operational} = $row->[8];
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_medium} = $row->[8]; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_duplex} = $row->[9];
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bond_uuid} = defined $row->[9] ? $row->[9] : ''; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_medium} = $row->[10];
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bridge_uuid} = defined $row->[10] ? $row->[10] : ''; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bond_uuid} = defined $row->[11] ? $row->[11] : '';
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bridge_uuid} = defined $row->[12] ? $row->[12] : '';
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{rx_bytes} = $rx_bytes =~ /^\d+$/ ? $rx_bytes : 0; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{rx_bytes} = $rx_bytes =~ /^\d+$/ ? $rx_bytes : 0;
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{rx_variable_uuid} = $rx_variable_uuid; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{rx_variable_uuid} = $rx_variable_uuid;
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{tx_bytes} = $tx_bytes =~ /^\d+$/ ? $tx_bytes : 0; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{tx_bytes} = $tx_bytes =~ /^\d+$/ ? $tx_bytes : 0;
$anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{tx_variable_uuid} = $tx_variable_uuid; $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{tx_variable_uuid} = $tx_variable_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_nm_uuid" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_nm_uuid},
"old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_mac_address" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mac_address}, "old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_mac_address" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mac_address},
"old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_name" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_name}, "old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_name" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_name},
"old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_device" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_device},
"old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_speed" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_speed}, "old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_speed" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_speed},
"old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_mtu" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mtu}, "old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_mtu" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mtu},
"old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_link_state" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_link_state}, "old::network_interfaces::network_interface_uuid::${network_interface_uuid}::network_interface_link_state" => $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_link_state},
@ -2436,11 +2470,13 @@ WHERE
}}); }});
$anvil->data->{network_interfaces}{name_to_uuid}{$network_interface_name} = $network_interface_uuid; $anvil->data->{network_interfaces}{name_to_uuid}{$network_interface_name} = $network_interface_uuid;
$anvil->data->{network_interfaces}{device_to_uuid}{$network_interface_device} = $network_interface_uuid;
$anvil->data->{network_interfaces}{uuid_to_name}{$network_interface_uuid} = $network_interface_name; $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->{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}{name_to_uuid}{$network_interface_name} = $network_interface_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $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::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::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}, "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::name_to_uuid::${network_interface_name}" => $anvil->data->{interface}{name_to_uuid}{$network_interface_name},
@ -2676,7 +2712,6 @@ sub check_ip_addresses
{ {
my $on_interface = $anvil->data->{new}{ip_address}{$ip_address}{on_interface}; my $on_interface = $anvil->data->{new}{ip_address}{$ip_address}{on_interface};
my $new_on_type = $anvil->data->{interface}{name_to_type}{$on_interface}; my $new_on_type = $anvil->data->{interface}{name_to_type}{$on_interface};
my $new_on_uuid = $anvil->data->{interface}{name_to_uuid}{$on_interface};
my $new_subnet_mask = $anvil->data->{new}{ip_address}{$ip_address}{subnet_mask}; my $new_subnet_mask = $anvil->data->{new}{ip_address}{$ip_address}{subnet_mask};
my $new_gateway = $anvil->data->{new}{ip_address}{$ip_address}{gateway}; my $new_gateway = $anvil->data->{new}{ip_address}{$ip_address}{gateway};
my $new_default_gateway = $anvil->data->{new}{ip_address}{$ip_address}{default_gateway}; my $new_default_gateway = $anvil->data->{new}{ip_address}{$ip_address}{default_gateway};
@ -2685,12 +2720,22 @@ sub check_ip_addresses
ip_address => $ip_address, ip_address => $ip_address,
on_interface => $on_interface, on_interface => $on_interface,
new_on_type => $new_on_type, new_on_type => $new_on_type,
new_on_uuid => $new_on_uuid,
new_subnet_mask => $new_subnet_mask, new_subnet_mask => $new_subnet_mask,
new_gateway => $new_gateway, new_gateway => $new_gateway,
new_default_gateway => $new_default_gateway, new_default_gateway => $new_default_gateway,
new_dns => $new_dns, new_dns => $new_dns,
}}); }});
my $new_on_uuid = "";
if ($anvil->data->{interface}{name_to_uuid}{$on_interface})
{
$new_on_uuid = $anvil->data->{interface}{name_to_uuid}{$on_interface};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_on_uuid => $new_on_uuid }});
}
elsif ($anvil->data->{interface}{device_to_uuid}{$on_interface})
{
$new_on_uuid = $anvil->data->{interface}{device_to_uuid}{$on_interface};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_on_uuid => $new_on_uuid }});
}
if (exists $anvil->data->{old}{ip_addresses}{ip_to_uuid}{$ip_address}) if (exists $anvil->data->{old}{ip_addresses}{ip_to_uuid}{$ip_address})
{ {
@ -2957,6 +3002,7 @@ sub check_interfaces
foreach my $network_interface_name (sort {$a cmp $b} keys %{$anvil->data->{new}{interface}}) foreach my $network_interface_name (sort {$a cmp $b} keys %{$anvil->data->{new}{interface}})
{ {
my $new_nm_uuid = $anvil->data->{new}{interface}{$network_interface_name}{nm_uuid}; my $new_nm_uuid = $anvil->data->{new}{interface}{$network_interface_name}{nm_uuid};
my $new_nm_name = $anvil->data->{new}{interface}{$network_interface_name}{nm_name};
my $new_nm_device = $anvil->data->{new}{interface}{$network_interface_name}{nm_device}; my $new_nm_device = $anvil->data->{new}{interface}{$network_interface_name}{nm_device};
my $new_bond_uuid = $anvil->data->{new}{interface}{$network_interface_name}{bond_uuid}; my $new_bond_uuid = $anvil->data->{new}{interface}{$network_interface_name}{bond_uuid};
my $new_bond_name = $anvil->data->{new}{interface}{$network_interface_name}{bond_name}; my $new_bond_name = $anvil->data->{new}{interface}{$network_interface_name}{bond_name};
@ -2974,6 +3020,7 @@ sub check_interfaces
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
network_interface_name => $network_interface_name, network_interface_name => $network_interface_name,
new_nm_uuid => $new_nm_uuid, new_nm_uuid => $new_nm_uuid,
new_nm_name => $new_nm_name,
new_nm_device => $new_nm_device, new_nm_device => $new_nm_device,
new_bond_uuid => $new_bond_uuid, new_bond_uuid => $new_bond_uuid,
new_bond_name => $new_bond_name, new_bond_name => $new_bond_name,
@ -3008,10 +3055,27 @@ sub check_interfaces
} }
# New or existing? # New or existing?
my $network_interface_uuid = "";
if (exists $anvil->data->{network_interfaces}{name_to_uuid}{$network_interface_name}) if (exists $anvil->data->{network_interfaces}{name_to_uuid}{$network_interface_name})
{
$network_interface_uuid = $anvil->data->{network_interfaces}{name_to_uuid}{$network_interface_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_interface_uuid => $network_interface_uuid }});
}
elsif (exists $anvil->data->{network_interfaces}{device_to_uuid}{$network_interface_name})
{
$network_interface_uuid = $anvil->data->{network_interfaces}{device_to_uuid}{$network_interface_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_interface_uuid => $network_interface_uuid }});
}
elsif (($new_mac_address) && (exists $anvil->data->{network_interfaces}{mac_to_uuid}{$new_mac_address}))
{
$network_interface_uuid = $anvil->data->{network_interfaces}{mac_to_uuid}{$new_mac_address};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_interface_uuid => $network_interface_uuid }});
}
if ($network_interface_uuid)
{ {
# Existing. Changes? # Existing. Changes?
my $network_interface_uuid = $anvil->data->{network_interfaces}{name_to_uuid}{$network_interface_name}; my $old_nm_name = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_name};
my $old_nm_device = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_device};
my $old_bond_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bond_uuid}; my $old_bond_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bond_uuid};
my $old_bond_name = ""; my $old_bond_name = "";
my $old_bridge_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bridge_uuid}; my $old_bridge_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bridge_uuid};
@ -3028,6 +3092,8 @@ sub check_interfaces
my $old_tx_bytes = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{tx_bytes}; my $old_tx_bytes = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{tx_bytes};
my $tx_variable_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{tx_variable_uuid}; my $tx_variable_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{tx_variable_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
old_nm_name => $old_nm_name,
old_nm_device => $old_nm_device,
old_bond_uuid => $old_bond_uuid, old_bond_uuid => $old_bond_uuid,
old_bridge_uuid => $old_bridge_uuid, old_bridge_uuid => $old_bridge_uuid,
old_duplex => $old_duplex, old_duplex => $old_duplex,
@ -3061,6 +3127,52 @@ sub check_interfaces
# Look for changes. # Look for changes.
my $changes = 0; my $changes = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
new_nm_name => $new_nm_name,
old_nm_name => $old_nm_name,
}});
if ($new_nm_name ne $old_nm_name)
{
$changes = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { changes => $changes }});
my $variables = {
name => $network_interface_name,
old => $old_nm_name,
new => $new_nm_name,
};
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_network_alert_0062", variables => $variables});
$anvil->Alert->register({
alert_level => "notice",
message => "scan_network_alert_0062",
variables => $variables,
set_by => $THIS_FILE,
});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
new_nm_device => $new_nm_device,
old_nm_device => $old_nm_device,
}});
if ($new_nm_device ne $old_nm_device)
{
$changes = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { changes => $changes }});
my $variables = {
name => $network_interface_name,
old => $old_nm_device,
new => $new_nm_device,
};
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_network_alert_0063", variables => $variables});
$anvil->Alert->register({
alert_level => "notice",
message => "scan_network_alert_0063",
variables => $variables,
set_by => $THIS_FILE,
});
}
if ($new_bond_uuid ne $old_bond_uuid) if ($new_bond_uuid ne $old_bond_uuid)
{ {
# We're making this a warning level alert as it should not be changing. # We're making this a warning level alert as it should not be changing.
@ -3390,13 +3502,17 @@ sub check_interfaces
if ($changes) if ($changes)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
new_nm_name => $new_nm_name,
new_nm_device => $new_nm_device,
}});
my $network_interface_uuid = $anvil->Database->insert_or_update_network_interfaces({ my $network_interface_uuid = $anvil->Database->insert_or_update_network_interfaces({
debug => 2, debug => 2,
network_interface_nm_uuid => $new_nm_uuid, network_interface_nm_uuid => $new_nm_uuid,
network_interface_bond_uuid => $new_bond_uuid, network_interface_bond_uuid => $new_bond_uuid,
network_interface_bridge_uuid => $new_bridge_uuid, network_interface_bridge_uuid => $new_bridge_uuid,
network_interface_name => $network_interface_name, network_interface_name => $new_nm_name, # biosdevname
network_interface_device => $new_nm_device, network_interface_device => $new_nm_device, # ip name
network_interface_duplex => $new_duplex, network_interface_duplex => $new_duplex,
network_interface_link_state => $new_link_state, network_interface_link_state => $new_link_state,
network_interface_operational => $new_operational, network_interface_operational => $new_operational,
@ -3525,13 +3641,18 @@ sub check_interfaces
else else
{ {
# Record the interface # Record the interface
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
new_nm_name => $new_nm_name,
network_interface_name => $network_interface_name,
new_nm_device => $new_nm_device,
}});
my $network_interface_uuid = $anvil->Database->insert_or_update_network_interfaces({ my $network_interface_uuid = $anvil->Database->insert_or_update_network_interfaces({
debug => 2, debug => 2,
network_interface_nm_uuid => $new_nm_uuid, network_interface_nm_uuid => $new_nm_uuid,
network_interface_bond_uuid => $new_bond_uuid, network_interface_bond_uuid => $new_bond_uuid,
network_interface_bridge_uuid => $new_bridge_uuid, network_interface_bridge_uuid => $new_bridge_uuid,
network_interface_name => $network_interface_name, network_interface_name => $new_nm_name,
network_interface_device => $new_nm_device, network_interface_device => $network_interface_name,
network_interface_duplex => $new_duplex, network_interface_duplex => $new_duplex,
network_interface_link_state => $new_link_state, network_interface_link_state => $new_link_state,
network_interface_operational => $new_operational, network_interface_operational => $new_operational,
@ -3547,11 +3668,13 @@ sub check_interfaces
$anvil->data->{network_interfaces}{uuid_to_name}{$network_interface_uuid} = $network_interface_name; $anvil->data->{network_interfaces}{uuid_to_name}{$network_interface_uuid} = $network_interface_name;
$anvil->data->{network_interfaces}{mac_to_uuid}{$new_mac_address} = $network_interface_uuid; $anvil->data->{network_interfaces}{mac_to_uuid}{$new_mac_address} = $network_interface_uuid;
$anvil->data->{interface}{name_to_uuid}{$network_interface_name} = $network_interface_uuid; $anvil->data->{interface}{name_to_uuid}{$network_interface_name} = $network_interface_uuid;
$anvil->data->{interface}{device_to_uuid}{$new_nm_device} = $network_interface_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $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::name_to_uuid::${network_interface_name}" => $anvil->data->{network_interfaces}{name_to_uuid}{$network_interface_name},
"network_interfaces::uuid_to_name::${network_interface_uuid}" => $anvil->data->{network_interfaces}{uuid_to_name}{$network_interface_uuid}, "network_interfaces::uuid_to_name::${network_interface_uuid}" => $anvil->data->{network_interfaces}{uuid_to_name}{$network_interface_uuid},
"network_interfaces::mac_to_uuid::${new_mac_address}" => $anvil->data->{network_interfaces}{mac_to_uuid}{$new_mac_address}, "network_interfaces::mac_to_uuid::${new_mac_address}" => $anvil->data->{network_interfaces}{mac_to_uuid}{$new_mac_address},
"interface::name_to_uuid::${network_interface_name}" => $anvil->data->{interface}{name_to_uuid}{$network_interface_name}, "interface::name_to_uuid::${network_interface_name}" => $anvil->data->{interface}{name_to_uuid}{$network_interface_name},
"interface::device_to_uuid::${new_nm_device}" => $anvil->data->{interface}{device_to_uuid}{$new_nm_device},
}}); }});
# Store the rx_bytes and tx_bytes # Store the rx_bytes and tx_bytes

@ -133,6 +133,8 @@ Note: If this is a Storage Network directly connected to the peer, and the peer
<key name="scan_network_alert_0059">The network interface: [#!variable!name!#] appears to have been removed. The last time we saw it, it had transmitted: [#!variable!tx!#] and received: [#!variable!rx!#].</key> <key name="scan_network_alert_0059">The network interface: [#!variable!name!#] appears to have been removed. The last time we saw it, it had transmitted: [#!variable!tx!#] and received: [#!variable!rx!#].</key>
<key name="scan_network_alert_0060">The IP address: [#!variable!ip!#] appears to no longer be used on this machine.</key> <key name="scan_network_alert_0060">The IP address: [#!variable!ip!#] appears to no longer be used on this machine.</key>
<key name="scan_network_alert_0061">The network interface: [#!variable!name!#] MAC address has changed from: [#!variable!old!#] to: [#!variable!new!#]. This is normal when a server boots or migrates.</key> <key name="scan_network_alert_0061">The network interface: [#!variable!name!#] MAC address has changed from: [#!variable!old!#] to: [#!variable!new!#]. This is normal when a server boots or migrates.</key>
<key name="scan_network_alert_0062">The network interface: [#!variable!name!#] network manager's 'connection.id' name (biosdevname) has changed from: [#!variable!old!#] to: [#!variable!new!#].</key>
<key name="scan_network_alert_0063">The network interface: [#!variable!name!#] network manager's 'GENERAL.IP-IFACE' name (ip addr name) has changed from: [#!variable!old!#] to: [#!variable!new!#].</key>
<!-- Error entries --> <!-- Error entries -->
<key name="scan_network_error_0001">Failed to read the network interface speed from the file: [#!variable!file!#]. Ignoring interface.</key> <key name="scan_network_error_0001">Failed to read the network interface speed from the file: [#!variable!file!#]. Ignoring interface.</key>

@ -981,6 +981,37 @@ sub reconfigure_interfaces
{ {
my ($anvil) = @_; my ($anvil) = @_;
# Before we start, we need to make sure all interfaces are up. Otherwise, there's no way to match a
# network manager device to the ip addr name or the biosdevname.
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{nmcli}{uuid}})
{
### TODO: Left off here... any devices that are down, set:
### nmcli connection modify <uuid> ipv4.method manual ipv4.addresses 169.0.0.x/8' (x == Wired connection x)
my $connection_id = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.id'} // "";
my $general_ip_iface = $anvil->data->{nmcli}{uuid}{$uuid}{'GENERAL.IP-IFACE'} // "";
$general_ip_iface = "" if $general_ip_iface eq "--";
my $device_type = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.type'} // "";
my $match_interface_name = $anvil->data->{nmcli}{uuid}{$uuid}{'match.interface-name'} // "";
my $active = $anvil->data->{nmcli}{uuid}{$uuid}{active};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:uuid' => $uuid,
's2:connection_id' => $connection_id,
's3:general_ip_iface' => $general_ip_iface,
's4:device_type' => $device_type,
's5:match_interface_name' => $match_interface_name,
's6:active' => $active,
}});
# Try activating it.
if ((not $general_ip_iface) && (not $active))
{
# Rescan.
$anvil->Network->collect_data({debug => 2});
}
}
my $local_host = $anvil->Get->short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $prefix = $anvil->data->{config}{prefix}; my $prefix = $anvil->data->{config}{prefix};
my $sequence = $anvil->data->{config}{sequence}; my $sequence = $anvil->data->{config}{sequence};
@ -1038,9 +1069,35 @@ sub reconfigure_interfaces
my $link1_nm_uuid = $anvil->data->{nmcli}{mac_address}{$wanted_link1_mac}{uuid}; my $link1_nm_uuid = $anvil->data->{nmcli}{mac_address}{$wanted_link1_mac}{uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { link1_nm_uuid => $link1_nm_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { link1_nm_uuid => $link1_nm_uuid }});
# Are the link(s) already configured?
my $configure_link1 = 0;
my $configure_link2 = 0;
# Get the Network Manager UUIDs. # Get the Network Manager UUIDs.
if (not $link1_nm_uuid) if ($link1_nm_uuid)
{
my $found = 0;
my $match_interface_name = $anvil->data->{nmcli}{uuid}{$link1_nm_uuid}{'match.interface-name'} // "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { match_interface_name => $match_interface_name }});
foreach my $interface (split/,/, $match_interface_name)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { interface => $interface }});
if ($interface eq $wanted_link1_name)
{
$found = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { found => $found }});
last;
}
}
if (not $found)
{
$configure_link1 = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { configure_link1 => $configure_link1 }});
}
}
else
{ {
# We're dead.
$anvil->Job->update_progress({ $anvil->Job->update_progress({
progress => 100, progress => 100,
message => "error_0480", message => "error_0480",
@ -1055,14 +1112,40 @@ sub reconfigure_interfaces
}); });
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { configure_link1 => $configure_link1 }});
if ($configure_link1)
{
rename_interface($anvil, $wanted_link1_name, $link1_nm_uuid); rename_interface($anvil, $wanted_link1_name, $link1_nm_uuid);
}
my $link2_nm_uuid = ""; my $link2_nm_uuid = "";
if ($wanted_link2_mac) if ($wanted_link2_mac)
{ {
$link2_nm_uuid = $anvil->data->{nmcli}{mac_address}{$wanted_link2_mac}{uuid}; $link2_nm_uuid = $anvil->data->{nmcli}{mac_address}{$wanted_link2_mac}{uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { link2_nm_uuid => $link2_nm_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { link2_nm_uuid => $link2_nm_uuid }});
if (not $link2_nm_uuid) if ($link2_nm_uuid)
{
my $found = 0;
my $match_interface_name = $anvil->data->{nmcli}{uuid}{$link2_nm_uuid}{'match.interface-name'} // "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { match_interface_name => $match_interface_name }});
foreach my $interface (split/,/, $match_interface_name)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { interface => $interface }});
if ($interface eq $wanted_link2_name)
{
$found = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { found => $found }});
last;
}
}
if (not $found)
{
$configure_link2 = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { configure_link1 => $configure_link1 }});
}
}
else
{ {
$anvil->Job->update_progress({ $anvil->Job->update_progress({
progress => 100, progress => 100,
@ -1078,7 +1161,12 @@ sub reconfigure_interfaces
}); });
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { configure_link2 => $configure_link2 }});
if ($configure_link2)
{
rename_interface($anvil, $wanted_link2_name, $link2_nm_uuid); rename_interface($anvil, $wanted_link2_name, $link2_nm_uuid);
}
# There's a second interface, so create a bond. # There's a second interface, so create a bond.
my $bond_name = $network_type.$i."_bond1"; my $bond_name = $network_type.$i."_bond1";
@ -1090,8 +1178,6 @@ sub reconfigure_interfaces
} }
} }
die;
# There is no way (that we've found) to get the network interface ames to be updated without a reboot. # There is no way (that we've found) to get the network interface ames to be updated without a reboot.
if ($anvil->data->{sys}{reboot_needed}) if ($anvil->data->{sys}{reboot_needed})
{ {
@ -1122,6 +1208,9 @@ sub rename_interface
's6:type' => $type, 's6:type' => $type,
}}); }});
die if not $wanted_link_name;
die if not $old_device;
# Tell the user what we're about to rename # Tell the user what we're about to rename
$anvil->Job->update_progress({ $anvil->Job->update_progress({
progress => $anvil->Job->bump_progress({steps => 2}), progress => $anvil->Job->bump_progress({steps => 2}),

Loading…
Cancel
Save