Updated anvil-update-states to use the permanent MAC addresses, as done in scan-network. Updated Network->get_ips() to do the same.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 3 years ago
parent 7f1f71dcf0
commit 226d1de6b5
  1. 9
      Anvil/Tools/Network.pm
  2. 11
      scancore-agents/scan-network/scan-network
  3. 63
      tools/anvil-update-states

@ -2178,13 +2178,8 @@ then
elif [ -e "/proc/net/bonding/${IFACE}" ]; elif [ -e "/proc/net/bonding/${IFACE}" ];
then then
echo bond; echo bond;
elif [ -e "/sys/class/net/${IFACE}/bonding_slave/perm_hwaddr" ];
then
echo -n mac:
cat /sys/class/net/${IFACE}/bonding_slave/perm_hwaddr;
else else
echo -n mac: ethtool -P ${IFACE}
cat /sys/class/net/${IFACE}/address;
fi'; fi';
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
if ($is_local) if ($is_local)
@ -2216,7 +2211,7 @@ fi';
foreach my $line (split/\n/, $output) foreach my $line (split/\n/, $output)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
if ($line =~ /^mac:(.*)$/) if ($line =~ /^.*: (\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)$/)
{ {
my $real_mac = $1; my $real_mac = $1;
$anvil->data->{network}{$host}{interface}{$in_iface}{mac_address} = $real_mac; $anvil->data->{network}{$host}{interface}{$in_iface}{mac_address} = $real_mac;

@ -215,7 +215,7 @@ OR
records => $commits, records => $commits,
host => $anvil->Get->host_name_from_uuid({host_uuid => $uuid}), host => $anvil->Get->host_name_from_uuid({host_uuid => $uuid}),
}}); }});
$anvil->Database->write({debug => 2, uuid => $uuid, query => $queries, source => $THIS_FILE, line => __LINE__}); $anvil->Database->write({debug => 3, uuid => $uuid, query => $queries, source => $THIS_FILE, line => __LINE__});
undef $queries; undef $queries;
} }
} }
@ -469,8 +469,8 @@ sub collect_data
my $target = readlink($full_path."/master"); my $target = readlink($full_path."/master");
$bond_master = ($target =~ /^.*\/(.*)$/)[0]; $bond_master = ($target =~ /^.*\/(.*)$/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
target => $target, target => $target,
bond_master => $bond_master bond_master => $bond_master,
}}); }});
} }
elsif (-d $full_path."/bridge") elsif (-d $full_path."/bridge")
@ -625,11 +625,6 @@ sub collect_data
"cache::new_file" => $anvil->data->{cache}{new_file}, "cache::new_file" => $anvil->data->{cache}{new_file},
}}); }});
} }
if (($interface =~ /^vnet/) && ($operational ne "up"))
{
#die;
}
} }
} }
closedir(DIRECTORY); closedir(DIRECTORY);

@ -198,7 +198,6 @@ sub update_network
{ {
# 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 $mac_address = -e $full_path."/address" ? $anvil->Storage->read_file({file => $full_path."/address"}) : "";
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;
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;
my $duplex = -e $full_path."/duplex" ? $anvil->Storage->read_file({file => $full_path."/duplex"}) : "unknown"; # full or half? my $duplex = -e $full_path."/duplex" ? $anvil->Storage->read_file({file => $full_path."/duplex"}) : "unknown"; # full or half?
@ -207,14 +206,7 @@ sub update_network
my $media = "unknown"; my $media = "unknown";
my $type = "interface"; my $type = "interface";
# If the NIC is a bond member, the MAC address could be virtual.
if (-e $full_path."/bonding_slave/perm_hwaddr")
{
$mac_address = $anvil->Storage->read_file({file => $full_path."/bonding_slave/perm_hwaddr"});
}
# Clean up some newlines. # Clean up some newlines.
$mac_address =~ s/\n$//;
$link_state =~ s/\n$//; $link_state =~ s/\n$//;
$mtu =~ s/\n$//; $mtu =~ s/\n$//;
$duplex =~ s/\n$//; $duplex =~ s/\n$//;
@ -222,7 +214,6 @@ sub update_network
$speed =~ s/\n$//; $speed =~ s/\n$//;
$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,
mac_address => $mac_address,
link_state => $link_state, link_state => $link_state,
mtu => $mtu, mtu => $mtu,
duplex => $duplex, duplex => $duplex,
@ -230,11 +221,35 @@ sub update_network
speed => $speed, speed => $speed,
}}); }});
# If this a vnet device, set 'operational' to 'up'. # The MAC address can faked by a number of ways, so we make an explicit call to 'ethtool' to get the permanent mac address.
if (($interface =~ /^vnet/) && ($operational ne "up")) my $mac_address = "";
my $shell_call = $anvil->data->{path}{exe}{ethtool}." -P ".$interface;
$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,
}});
if ($output =~ /(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)$/)
{ {
$operational = "up"; $mac_address = lc($1);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { operational => $operational }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mac_address => $mac_address }});
}
else
{
# Get it by reading the address file.
if (-e $full_path."/bonding_slave/perm_hwaddr")
{
$mac_address = $anvil->Storage->read_file({file => $full_path."/bonding_slave/perm_hwaddr"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mac_address => $mac_address }});
}
elsif (-e $full_path."/address")
{
$mac_address = $anvil->Storage->read_file({file => $full_path."/address"});
$mac_address =~ s/\n//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mac_address => $mac_address }});
}
} }
# These are variables that will be needed if this is a bond interface. # These are variables that will be needed if this is a bond interface.
@ -369,6 +384,17 @@ sub update_network
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { bridge_stp_enabled => $bridge_stp_enabled }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { bridge_stp_enabled => $bridge_stp_enabled }});
} }
# If this a vnet device, set 'operational' to 'up'.
if ($interface =~ /^vnet/)
{
$operational = "up";
$media = "virtual";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
operational => $operational,
media => $media,
}});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
active_interface => $active_interface, active_interface => $active_interface,
bond_master => $bond_master, bond_master => $bond_master,
@ -393,11 +419,16 @@ sub update_network
# If the MAC address starts with '52:54:00', we've got a virtio NIC. # If the MAC address starts with '52:54:00', we've got a virtio NIC.
if ((not defined $speed) or ($speed eq "")) if ((not defined $speed) or ($speed eq ""))
{ {
die $THIS_FILE." ".__LINE__."; No speed for: [".$full_path."/speed]\n"; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_network_error_0001", variables => { file => $full_path."/speed" }});
next;
} }
if ($speed =~ /\D/) if ($speed =~ /\D/)
{ {
die $THIS_FILE." ".__LINE__."; Speed: [$speed] isn't numeric for: [".$full_path."/speed]\n"; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_network_error_0002", variables => {
file => $full_path."/speed",
speed => $speed,
}});
next;
} }
if ($speed > 100000) if ($speed > 100000)
{ {
@ -408,7 +439,7 @@ sub update_network
} }
# 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 => 3, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { line => $line }});

Loading…
Cancel
Save