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. 512
      Anvil/Tools/Network.pm
  3. 231
      scancore-agents/scan-network/scan-network
  4. 2
      scancore-agents/scan-network/scan-network.xml
  5. 101
      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,247 +1225,313 @@ 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}{device} = $device; $anvil->data->{nmcli}{uuid}{$uuid}{name} = $connection_id;
$anvil->data->{nmcli}{uuid}{$uuid}{mac_address} = ""; $anvil->data->{nmcli}{uuid}{$uuid}{device} = $device;
$anvil->data->{nmcli}{uuid}{$uuid}{type} = ""; $anvil->data->{nmcli}{uuid}{$uuid}{mac_address} = "";
$anvil->data->{nmcli}{uuid}{$uuid}{mtu} = 0; $anvil->data->{nmcli}{uuid}{$uuid}{type} = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->data->{nmcli}{uuid}{$uuid}{mtu} = 0;
"nmcli::uuid::${uuid}::device" => $anvil->data->{nmcli}{uuid}{$uuid}{device}, $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
}}); "nmcli::uuid::${uuid}::device" => $anvil->data->{nmcli}{uuid}{$uuid}{device},
}});
# The 'connection.timestamp' seems to be where the 'connected' (as in, have an IP)
# comes from.
$anvil->data->{nmcli}{uuid}{$uuid}{connected} = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.timestamp'} ? $anvil->data->{nmcli}{uuid}{$uuid}{'connection.timestamp'} : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::uuid::${uuid}::connected" => $anvil->data->{nmcli}{uuid}{$uuid}{connected},
}});
# The 'connection.timestamp' seems to be where the 'connected' (as in, have an IP) if ($device_type eq "bond")
# comes from. {
$anvil->data->{nmcli}{uuid}{$uuid}{connected} = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.timestamp'} ? $anvil->data->{nmcli}{uuid}{$uuid}{'connection.timestamp'} : 0; # 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::uuid::${uuid}::connected" => $anvil->data->{nmcli}{uuid}{$uuid}{connected}, "nmcli::bond::${connection_id}::uuid" => $anvil->data->{nmcli}{bond}{$connection_id}{uuid},
}}); }});
if ($device_type eq "bond") # Read the interface's 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 }});
if (-e $carrier_file)
{ {
$anvil->data->{nmcli}{bond}{$device}{uuid} = $uuid; my $carrier = $anvil->Storage->read_file({debug => $debug, file => $carrier_file});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { chomp $carrier;
"nmcli::bond::${device}::uuid" => $anvil->data->{nmcli}{bond}{$device}{uuid}, $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { carrier => $carrier }});
$anvil->data->{nmcli}{bond}{$connection_id}{carrier} = $carrier;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"nmcli::bond::${connection_id}::carrier" => $anvil->data->{nmcli}{bond}{$connection_id}{carrier},
}}); }});
}
# Read the interface's carrier my $operstate_file = "/sys/class/net/".$connection_id."/operstate";
my $carrier_file = "/sys/class/net/".$device."/carrier"; $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 => { carrier_file => $carrier_file }});
if (-e $carrier_file) if (-e $operstate_file)
{ {
my $carrier = $anvil->Storage->read_file({debug => $debug, file => $carrier_file}); my $operstate = $anvil->Storage->read_file({debug => $debug, file => $operstate_file});
chomp $carrier; chomp $operstate;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { carrier => $carrier }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { operstate => $operstate }});
$anvil->data->{nmcli}{bond}{$device}{carrier} = $carrier; $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}::carrier" => $anvil->data->{nmcli}{bond}{$device}{carrier}, "nmcli::bond::${connection_id}::operstate" => $anvil->data->{nmcli}{bond}{$connection_id}{operstate},
}}); }});
} }
my $operstate_file = "/sys/class/net/".$device."/operstate"; # Read in the /proc file.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { operstate_file => $operstate_file }}); my $proc_file = "/proc/net/bonding/".$connection_id;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { proc_file => $proc_file }});
if (-e $operstate_file) my $in_link = "";
{ my $file_body = $anvil->Storage->read_file({debug => $debug, file => $proc_file});
my $operstate = $anvil->Storage->read_file({debug => $debug, file => $operstate_file}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { file_body => $file_body }});
chomp $operstate; foreach my $line (split/\n/, $file_body)
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { operstate => $operstate }}); {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
$anvil->data->{nmcli}{bond}{$device}{up} = $operstate eq "up" ? 1 : 0; if ($line =~ /Slave Interface: (.*)$/)
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { {
"nmcli::bond::${device}::operstate" => $anvil->data->{nmcli}{bond}{$device}{operstate}, $in_link = $1;
}}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_link => $in_link }});
next;
} }
if (not $line)
# Read in the /proc file.
my $proc_file = "/proc/net/bonding/".$device;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { proc_file => $proc_file }});
my $in_link = "";
my $file_body = $anvil->Storage->read_file({debug => $debug, file => $proc_file});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { file_body => $file_body }});
foreach my $line (split/\n/, $file_body)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); $in_link = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_link => $in_link }});
if ($line =~ /Slave Interface: (.*)$/) next;
{ }
$in_link = $1; if ($in_link)
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_link => $in_link }}); {
next; if ($line =~ /MII Status: (.*)$/)
}
if (not $line)
{
$in_link = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_link => $in_link }});
next;
}
if ($in_link)
{ {
if ($line =~ /MII Status: (.*)$/) my $status = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { status => $status }});
if ($status eq "up")
{ {
my $status = $1; $anvil->data->{nmcli}{bond}{$connection_id}{interface}{$in_link}{up} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { status => $status }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
if ($status eq "up") "nmcli::bond::${connection_id}::interface::${in_link}::up" => $anvil->data->{nmcli}{bond}{$connection_id}{interface}{$in_link}{up},
{ }});
$anvil->data->{nmcli}{bond}{$device}{interface}{$in_link}{up} = 1;
$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},
}});
}
else
{
$anvil->data->{nmcli}{bond}{$device}{interface}{$in_link}{up} = 0;
$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},
}});
}
next;
} }
} else
else
{
if ($line =~ /MII Status: (.*)$/)
{ {
my $status = $1; $anvil->data->{nmcli}{bond}{$connection_id}{interface}{$in_link}{up} = 0;
$anvil->data->{nmcli}{bond}{$device}{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, "nmcli::bond::${connection_id}::interface::${in_link}::up" => $anvil->data->{nmcli}{bond}{$connection_id}{interface}{$in_link}{up},
"nmcli::bond::${device}::up" => $anvil->data->{nmcli}{bond}{$device}{up},
}}); }});
next;
} }
next;
}
}
else
{
if ($line =~ /MII Status: (.*)$/)
{
my $status = $1;
$anvil->data->{nmcli}{bond}{$connection_id}{up} = $status eq "up" ? 1 : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
status => $status,
"nmcli::bond::${connection_id}::up" => $anvil->data->{nmcli}{bond}{$connection_id}{up},
}});
next;
} }
} }
} }
elsif ($device_type eq "bridge") }
{ elsif ($device_type eq "bridge")
$anvil->data->{nmcli}{bridge}{$device}{uuid} = $uuid; {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { # Bonds always have the name we chose as the connection.id as they don't have
"nmcli::bridge::${device}::uuid" => $anvil->data->{nmcli}{bridge}{$device}{uuid}, # biosdevnames.
}}); $anvil->data->{nmcli}{bridge}{$connection_id}{uuid} = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"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});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output, output => $output,
return_code => $return_code, return_code => $return_code,
}}); }});
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 }});
if ($line =~ /^\d+: (.*?): <(.*?)>/)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }}); my $interface = $1;
if ($line =~ /^\d+: (.*?): <(.*?)>/) my $status = $2;
{ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
my $interface = $1; interface => $interface,
my $status = $2; status => $status,
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { }});
interface => $interface,
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 "--"))
{ {
$anvil->data->{nmcli}{interface}{$device}{uuid} = $uuid; $device = $general_ip_iface;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { }
"nmcli::interface::${device}::uuid" => $anvil->data->{nmcli}{interface}{$device}{uuid}, $anvil->data->{nmcli}{interface}{$device}{uuid} = $uuid;
}}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::interface::${device}::uuid" => $anvil->data->{nmcli}{interface}{$device}{uuid},
}});
# MAC address
my $mac_address_file = "/sys/class/net/".$device."/address";
my $type_file = "/sys/class/net/".$device."/type";
my $mtu_file = "/sys/class/net/".$device."/mtu";
if (-e $mac_address_file)
{
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 }});
# MAC address if (($mac_address) && ($mac_address ne "!!error!!"))
my $mac_address_file = "/sys/class/net/".$device."/address";
my $type_file = "/sys/class/net/".$device."/type";
my $mtu_file = "/sys/class/net/".$device."/mtu";
if (-e $mac_address_file)
{ {
my $mac_address = $anvil->Storage->read_file({file => $mac_address_file}); $anvil->data->{nmcli}{uuid}{$uuid}{mac_address} = $mac_address;
$mac_address =~ s/\n$//; $anvil->data->{nmcli}{mac_address}{$mac_address}{uuid} = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mac_address => $mac_address }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"nmcli::uuid::${uuid}::mac_address" => $anvil->data->{nmcli}{uuid}{$uuid}{mac_address},
"nmcli::mac_address::${mac_address}::uuid" => $anvil->data->{nmcli}{mac_address}{$mac_address}{uuid},
}});
}
}
if (-e $type_file)
{
my $type = $anvil->Storage->read_file({file => $type_file});
$type =~ s/\n$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { type => $type }});
if (($mac_address) && ($mac_address ne "!!error!!")) if (($type) && ($type ne "!!error!!"))
{ {
$anvil->data->{nmcli}{uuid}{$uuid}{mac_address} = $mac_address; $anvil->data->{nmcli}{uuid}{$uuid}{type} = $type;
$anvil->data->{nmcli}{mac_address}{$mac_address}{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::uuid::${uuid}::type" => $anvil->data->{nmcli}{uuid}{$uuid}{type},
"nmcli::uuid::${uuid}::mac_address" => $anvil->data->{nmcli}{uuid}{$uuid}{mac_address}, }});
"nmcli::mac_address::${mac_address}::uuid" => $anvil->data->{nmcli}{mac_address}{$mac_address}{uuid},
}});
}
} }
if (-e $type_file) }
if (-e $mtu_file)
{
my $mtu = $anvil->Storage->read_file({file => $mtu_file});
$mtu =~ s/\n$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mtu => $mtu }});
if (($mtu) && ($mtu ne "!!error!!"))
{ {
my $type = $anvil->Storage->read_file({file => $type_file}); $anvil->data->{nmcli}{uuid}{$uuid}{mtu} = $mtu;
$type =~ s/\n$//; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { type => $type }}); "nmcli::uuid::${uuid}::mtu" => $anvil->data->{nmcli}{uuid}{$uuid}{mtu},
}});
}
}
}
}
# 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;
if (($type) && ($type ne "!!error!!")) # 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})
{ {
$anvil->data->{nmcli}{uuid}{$uuid}{type} = $type; $found = 1;
$use_ip = $test_ip;
$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}, found => $found,
use_ip => $use_ip,
}}); }});
} }
} else
if (-e $mtu_file)
{
my $mtu = $anvil->Storage->read_file({file => $mtu_file});
$mtu =~ s/\n$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mtu => $mtu }});
if (($mtu) && ($mtu ne "!!error!!"))
{ {
$anvil->data->{nmcli}{uuid}{$uuid}{mtu} = $mtu; $sequence++;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { sequence => $sequence }});
"nmcli::uuid::${uuid}::mtu" => $anvil->data->{nmcli}{uuid}{$uuid}{mtu},
}});
} }
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;
@ -626,14 +625,13 @@ sub collect_data
$modalias =~ s/\n$//; $modalias =~ s/\n$//;
my $speed = $link_state ? $anvil->Storage->read_file({file => $full_path."/speed"}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link my $speed = $link_state ? $anvil->Storage->read_file({file => $full_path."/speed"}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link
$speed =~ s/\n$//; $speed =~ s/\n$//;
my $media = "unknown"; my $media = "unknown";
my $type = "interface"; my $type = "interface";
my $driver = ""; my $driver = "";
my $tx_bytes = 0; # How many bytes transmitted my $tx_bytes = 0; # How many bytes transmitted
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,26 +3055,45 @@ 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_bond_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bond_uuid}; my $old_nm_device = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_device};
my $old_bond_name = ""; my $old_bond_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bond_uuid};
my $old_bridge_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bridge_uuid}; my $old_bond_name = "";
my $old_bridge_name = ""; my $old_bridge_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_bridge_uuid};
my $old_duplex = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_duplex}; my $old_bridge_name = "";
my $old_link_state = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_link_state}; my $old_duplex = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_duplex};
my $old_operational = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_operational}; my $old_link_state = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_link_state};
my $old_mac_address = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mac_address}; my $old_operational = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_operational};
my $old_medium = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_medium}; my $old_mac_address = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mac_address};
my $old_mtu = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mtu}; my $old_medium = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_medium};
my $old_speed = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_speed}; my $old_mtu = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_mtu};
my $old_rx_bytes = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{rx_bytes}; my $old_speed = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{network_interface_speed};
my $rx_variable_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{rx_variable_uuid}; my $old_rx_bytes = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{rx_bytes};
my $old_tx_bytes = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{tx_bytes}; my $rx_variable_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{rx_variable_uuid};
my $tx_variable_uuid = $anvil->data->{old}{network_interfaces}{network_interface_uuid}{$network_interface_uuid}{tx_variable_uuid}; 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};
$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});
} }
rename_interface($anvil, $wanted_link1_name, $link1_nm_uuid);
$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);
}
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});
} }
rename_interface($anvil, $wanted_link2_name, $link2_nm_uuid);
$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);
}
# 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