* Made the sysfs directory references static.

* Fixed a typo in Database->insert_or_update_bridges().
* Added 'bond_mac_address' and 'bond_operational' to the bonds table.
* Gathered data needed for bonds in tools/anvil-update-states and got bonds recording successfully (but more testing needed).

Signed-off-by: Digimer <digimer@alteeve.ca>
This commit is contained in:
Digimer 2018-05-29 17:57:55 -04:00
parent 66f280c9a7
commit b0232c6180
5 changed files with 201 additions and 76 deletions

View File

@ -863,9 +863,6 @@ sub _set_paths
secure => {
postgres_pgpass => "/var/lib/pgsql/.pgpass",
},
sysfs => {
network_interfaces => "/sys/class/net",
},
sql => {
'anvil.sql' => "/usr/sbin/anvil.sql",
},

View File

@ -1446,14 +1446,14 @@ sub insert_or_update_bridges
my $bridge_id = $parameter->{bridge_id} ? $parameter->{bridge_id} : "NULL";
my $bridge_stp_enabled = $parameter->{bridge_stp_enabled} ? $parameter->{bridge_stp_enabled} : "NULL";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
file => $file,
line => $line,
bridge_uuid => $bridge_uuid,
bridge_host_uuid => $bridge_host_uuid,
bridge_name => $bridge_name,
bridge_id => $bridge_id,
bridge_down_delay => $bridge_down_delay,
uuid => $uuid,
file => $file,
line => $line,
bridge_uuid => $bridge_uuid,
bridge_host_uuid => $bridge_host_uuid,
bridge_name => $bridge_name,
bridge_id => $bridge_id,
bridge_stp_enabled => $bridge_stp_enabled,
}});
if (not $bridge_name)
@ -1642,12 +1642,16 @@ This is the bond's device name.
=head2 bond_mode (required)
This is the bonding mode named used for this bond.
This is the bonding mode used for this bond.
=head2 bond_mtu (optional)
This is the MTU for the bonded interface.
=head2 bond_operational (optional)
This is set to C<< up >>, C<< down >> or C<< unknown >>. It indicates whether the bond has a working slaved interface or not.
=head2 bond_primary_slave (optional)
This is the primary interface name in the bond.
@ -1660,6 +1664,10 @@ This is the primary interface reselect policy.
This is the interface currently being used by the bond.
=head2 bond_mac_address (optional)
This is the current / active MAC address in use by the bond interface.
=head2 bond_mii_status (optional)
This is the current status of the interface (C<< up >> or C<< down >>).
@ -1698,6 +1706,8 @@ sub insert_or_update_bonds
my $bond_mii_polling_interval = $parameter->{bond_mii_polling_interval} ? $parameter->{bond_mii_polling_interval} : "NULL";
my $bond_up_delay = $parameter->{bond_up_delay} ? $parameter->{bond_up_delay} : "NULL";
my $bond_down_delay = $parameter->{bond_down_delay} ? $parameter->{bond_down_delay} : "NULL";
my $bond_mac_address = $parameter->{bond_mac_address} ? $parameter->{bond_mac_address} : "NULL";
my $bond_operational = $parameter->{bond_operational} ? $parameter->{bond_operational} : "NULL";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
file => $file,
@ -1714,6 +1724,8 @@ sub insert_or_update_bonds
bond_mii_polling_interval => $bond_mii_polling_interval,
bond_up_delay => $bond_up_delay,
bond_down_delay => $bond_down_delay,
bond_mac_address => $bond_mac_address,
bond_operational => $bond_operational,
}});
if (not $bond_name)
@ -1803,6 +1815,8 @@ INSERT INTO
bond_mii_polling_interval,
bond_up_delay,
bond_down_delay,
bond_mac_address,
bond_operational,
modified_date
) VALUES (
".$anvil->data->{sys}{use_db_fh}->quote($bond_uuid).",
@ -1817,6 +1831,8 @@ INSERT INTO
".$anvil->data->{sys}{use_db_fh}->quote($bond_mii_polling_interval).",
".$anvil->data->{sys}{use_db_fh}->quote($bond_up_delay).",
".$anvil->data->{sys}{use_db_fh}->quote($bond_down_delay).",
".$anvil->data->{sys}{use_db_fh}->quote($bond_mac_address).",
".$anvil->data->{sys}{use_db_fh}->quote($bond_operational).",
".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})."
);
";
@ -1839,7 +1855,9 @@ SELECT
bond_mii_status,
bond_mii_polling_interval,
bond_up_delay,
bond_down_delay
bond_down_delay,
bond_mac_address,
bond_operational
FROM
bonds
WHERE
@ -1866,6 +1884,8 @@ WHERE
my $old_bond_mii_polling_interval = defined $row->[8] ? $row->[8] : "NULL";
my $old_bond_up_delay = defined $row->[9] ? $row->[9] : "NULL";
my $old_bond_down_delay = defined $row->[10] ? $row->[10] : "NULL";
my $old_bond_mac_address = defined $row->[11] ? $row->[11] : "NULL";
my $old_bond_operational = defined $row->[12] ? $row->[12] : "NULL";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_bond_host_uuid => $old_bond_host_uuid,
old_bond_name => $old_bond_name,
@ -1878,6 +1898,8 @@ WHERE
old_bond_mii_polling_interval => $old_bond_mii_polling_interval,
old_bond_up_delay => $old_bond_up_delay,
old_bond_down_delay => $old_bond_down_delay,
old_bond_mac_address => $old_bond_mac_address,
old_bond_operational => $old_bond_operational,
}});
# Anything change?
@ -1891,7 +1913,9 @@ WHERE
($old_bond_mii_status ne $bond_mii_status) or
($old_bond_mii_polling_interval ne $bond_mii_polling_interval) or
($old_bond_up_delay ne $bond_up_delay) or
($old_bond_down_delay ne $bond_down_delay))
($old_bond_down_delay ne $bond_down_delay) or
($old_bond_mac_address ne $bond_mac_address) or
($old_bond_operational ne $bond_operational))
{
# Something changed, save.
my $query = "
@ -1909,6 +1933,8 @@ SET
bond_mii_polling_interval = ".$anvil->data->{sys}{use_db_fh}->quote($bond_mii_polling_interval).",
bond_up_delay = ".$anvil->data->{sys}{use_db_fh}->quote($bond_up_delay).",
bond_down_delay = ".$anvil->data->{sys}{use_db_fh}->quote($bond_down_delay).",
bond_mac_address = ".$anvil->data->{sys}{use_db_fh}->quote($bond_mac_address).",
bond_operational = ".$anvil->data->{sys}{use_db_fh}->quote($bond_operational).",
modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})."
WHERE
bond_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($bond_uuid)."

View File

@ -46,7 +46,7 @@ sub scan
{
my ($anvil) = @_;
my $directory = $anvil->data->{path}{sysfs}{network_interfaces};
my $directory = "/sys/class/net";
print $THIS_FILE." ".__LINE__."; directory: [".$directory."]\n";
local(*DIRECTORY);
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0018", variables => { directory => $directory }});

View File

@ -54,7 +54,7 @@ sub report_network
# We'll read through '/sys/class/net' looking for network interfaces.
# * 'sys::network::interface::<iface_name>::ip' - If an IP address is set
# * 'sys::network::interface::<iface_name>::subnet' - If an IP is set
my $directory = $anvil->data->{path}{sysfs}{network_interfaces};
my $directory = "/sys/class/net";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { directory => $directory }});
local(*DIRECTORY);
@ -64,7 +64,7 @@ sub report_network
{
next if $file eq ".";
next if $file eq "..";
next if $file eq "lo";
next if $file eq "lo";
next if $file =~ /virbr\d/;
my $full_path = "$directory/$file";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { full_path => $full_path }});
@ -77,12 +77,21 @@ sub report_network
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 $operational = -e $full_path."/operstate" ? $anvil->Storage->read_file({file => $full_path."/operstate"}) : "unknown"; # up or down
my $ip_address = "";
my $subnet_mask = "";
my $speed = $link_state ? $anvil->Storage->read_file({file => $full_path."/speed", debug => 2}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link
my $media = "unknown";
my $type = "interface";
# These are variables that will be needed if this is a bond interface.
my $ip_address = "";
my $subnet_mask = "";
my $bond_mode = "";
my $primary_slave = "";
my $primary_reselect = "";
my $active_slave = "";
my $mii_polling_interval = "";
my $up_delay = "";
my $down_delay = "";
if (exists $anvil->data->{sys}{network}{interface}{$interface})
{
$ip_address = $anvil->data->{sys}{network}{interface}{$interface}{ip} ? $anvil->data->{sys}{network}{interface}{$interface}{ip} : "";
@ -129,17 +138,43 @@ sub report_network
# Yup, we'll neet to dig into the bond proc files to get the proper slaved
# interface MAC addresses.
$type = "bond";
# Read the bond mode.
$bond_mode = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/mode"});
$bond_mode =~ s/\s.*//;
$primary_slave = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/primary"});
$primary_reselect = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/primary_reselect"});
$primary_reselect =~ s/\s.*//;
$active_slave = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/active_slave"});
$mii_polling_interval = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/miimon"});
$up_delay = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/updelay"});
$down_delay = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/downdelay"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
active_slave => $active_slave,
bond_mode => $bond_mode,
mii_polling_interval => $mii_polling_interval,
primary_reselect => $primary_reselect,
primary_slave => $primary_slave,
type => $type,
}});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
duplex => $duplex,
interface => $interface,
mac_address => $mac_address,
mtu => $mtu,
operational => $operational,
speed => $speed,
subnet_mask => $subnet_mask,
type => $type,
active_slave => $active_slave,
bond_mode => $bond_mode,
down_delay => $down_delay,
duplex => $duplex,
interface => $interface,
mac_address => $mac_address,
mii_polling_interval => $mii_polling_interval,
mtu => $mtu,
operational => $operational,
primary_reselect => $primary_reselect,
primary_slave => $primary_slave,
speed => $speed,
subnet_mask => $subnet_mask,
type => $type,
up_delay => $up_delay,
}});
# If the MAC address starts with '52:54:00', we've got a virtio NIC.
@ -175,28 +210,42 @@ sub report_network
# Log
$anvil->data->{network}{interfaces}{by_name}{$interface} = {
duplex => $duplex,
ip_address => $ip_address,
link_state => $link_state,
mac_address => $mac_address,
media => $media,
mtu => $mtu,
operational => $operational,
speed => $speed,
subnet_mask => $subnet_mask,
type => $type,
active_slave => $active_slave,
bond_mode => $bond_mode,
down_delay => $down_delay,
duplex => $duplex,
ip_address => $ip_address,
link_state => $link_state,
mac_address => $mac_address,
media => $media,
mii_polling_interval => $mii_polling_interval,
mtu => $mtu,
operational => $operational,
primary_reselect => $primary_reselect,
primary_slave => $primary_slave,
speed => $speed,
subnet_mask => $subnet_mask,
type => $type,
up_delay => $up_delay,
};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"network::interfaces::by_name::${interface}::duplex" => $duplex,
"network::interfaces::by_name::${interface}::ip_address" => $ip_address,
"network::interfaces::by_name::${interface}::link_state" => $link_state,
"network::interfaces::by_name::${interface}::mac_address" => $mac_address,
"network::interfaces::by_name::${interface}::media" => $media,
"network::interfaces::by_name::${interface}::mtu" => $mtu,
"network::interfaces::by_name::${interface}::operational" => $operational,
"network::interfaces::by_name::${interface}::speed" => $speed,
"network::interfaces::by_name::${interface}::subnet_mask" => $subnet_mask,
"network::interfaces::by_name::${interface}::type" => $type,
"network::interfaces::by_name::${interface}::active_slave" => $anvil->data->{network}{interfaces}{by_name}{$interface}{active_slave},
"network::interfaces::by_name::${interface}::bond_mode" => $anvil->data->{network}{interfaces}{by_name}{$interface}{bond_mode},
"network::interfaces::by_name::${interface}::down_delay" => $anvil->data->{network}{interfaces}{by_name}{$interface}{down_delay},
"network::interfaces::by_name::${interface}::duplex" => $anvil->data->{network}{interfaces}{by_name}{$interface}{duplex},
"network::interfaces::by_name::${interface}::ip_address" => $anvil->data->{network}{interfaces}{by_name}{$interface}{ip_address},
"network::interfaces::by_name::${interface}::link_state" => $anvil->data->{network}{interfaces}{by_name}{$interface}{link_state},
"network::interfaces::by_name::${interface}::mac_address" => $anvil->data->{network}{interfaces}{by_name}{$interface}{mac_address},
"network::interfaces::by_name::${interface}::media" => $anvil->data->{network}{interfaces}{by_name}{$interface}{media},
"network::interfaces::by_name::${interface}::mii_polling_interval" => $anvil->data->{network}{interfaces}{by_name}{$interface}{mii_polling_interval},
"network::interfaces::by_name::${interface}::mtu" => $anvil->data->{network}{interfaces}{by_name}{$interface}{mtu},
"network::interfaces::by_name::${interface}::operational" => $anvil->data->{network}{interfaces}{by_name}{$interface}{operational},
"network::interfaces::by_name::${interface}::primary_reselect" => $anvil->data->{network}{interfaces}{by_name}{$interface}{primary_reselect},
"network::interfaces::by_name::${interface}::primary_slave" => $anvil->data->{network}{interfaces}{by_name}{$interface}{primary_slave},
"network::interfaces::by_name::${interface}::speed" => $anvil->data->{network}{interfaces}{by_name}{$interface}{speed},
"network::interfaces::by_name::${interface}::subnet_mask" => $anvil->data->{network}{interfaces}{by_name}{$interface}{subnet_mask},
"network::interfaces::by_name::${interface}::type" => $anvil->data->{network}{interfaces}{by_name}{$interface}{type},
"network::interfaces::by_name::${interface}::up_delay" => $anvil->data->{network}{interfaces}{by_name}{$interface}{up_delay},
}});
}
}
@ -204,34 +253,48 @@ sub report_network
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{interfaces}{by_name}})
{
my $duplex = $anvil->data->{network}{interfaces}{by_name}{$interface}{duplex};
my $ip_address = $anvil->data->{network}{interfaces}{by_name}{$interface}{ip_address};
my $link_state = $anvil->data->{network}{interfaces}{by_name}{$interface}{link_state};
my $mac_address = $anvil->data->{network}{interfaces}{by_name}{$interface}{mac_address};
my $media = $anvil->data->{network}{interfaces}{by_name}{$interface}{media};
my $mtu = $anvil->data->{network}{interfaces}{by_name}{$interface}{mtu};
my $operational = $anvil->data->{network}{interfaces}{by_name}{$interface}{operational};
my $speed = $anvil->data->{network}{interfaces}{by_name}{$interface}{speed};
my $subnet_mask = $anvil->data->{network}{interfaces}{by_name}{$interface}{subnet_mask};
my $type = $anvil->data->{network}{interfaces}{by_name}{$interface}{type};
my $default_gateway = $anvil->data->{sys}{network}{interface}{$interface}{default_gateway};
my $gateway = $anvil->data->{sys}{network}{interface}{$interface}{gateway};
my $dns = $anvil->data->{sys}{network}{interface}{$interface}{dns};
my $active_slave = $anvil->data->{network}{interfaces}{by_name}{$interface}{active_slave};
my $bond_mode = $anvil->data->{network}{interfaces}{by_name}{$interface}{bond_mode};
my $down_delay = $anvil->data->{network}{interfaces}{by_name}{$interface}{down_delay};
my $duplex = $anvil->data->{network}{interfaces}{by_name}{$interface}{duplex};
my $ip_address = $anvil->data->{network}{interfaces}{by_name}{$interface}{ip_address};
my $link_state = $anvil->data->{network}{interfaces}{by_name}{$interface}{link_state};
my $mac_address = $anvil->data->{network}{interfaces}{by_name}{$interface}{mac_address};
my $media = $anvil->data->{network}{interfaces}{by_name}{$interface}{media};
my $mii_polling_interval = $anvil->data->{network}{interfaces}{by_name}{$interface}{mii_polling_interval};
my $mtu = $anvil->data->{network}{interfaces}{by_name}{$interface}{mtu};
my $operational = $anvil->data->{network}{interfaces}{by_name}{$interface}{operational};
my $primary_reselect = $anvil->data->{network}{interfaces}{by_name}{$interface}{primary_reselect};
my $primary_slave = $anvil->data->{network}{interfaces}{by_name}{$interface}{primary_slave};
my $speed = $anvil->data->{network}{interfaces}{by_name}{$interface}{speed};
my $subnet_mask = $anvil->data->{network}{interfaces}{by_name}{$interface}{subnet_mask};
my $type = $anvil->data->{network}{interfaces}{by_name}{$interface}{type};
my $up_delay = $anvil->data->{network}{interfaces}{by_name}{$interface}{up_delay};
my $default_gateway = $anvil->data->{sys}{network}{interface}{$interface}{default_gateway};
my $gateway = $anvil->data->{sys}{network}{interface}{$interface}{gateway};
my $dns = $anvil->data->{sys}{network}{interface}{$interface}{dns};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
default_gateway => $default_gateway,
dns => $dns,
duplex => $duplex,
gateway => $gateway,
interface => $interface,
ip_address => $ip_address,
link_state => $link_state,
mac_address => $mac_address,
media => $media,
mtu => $mtu,
operational => $operational,
speed => $speed,
subnet_mask => $subnet_mask,
type => $type,
active_slave => $active_slave,
bond_mode => $bond_mode,
default_gateway => $default_gateway,
down_delay => $down_delay,
dns => $dns,
duplex => $duplex,
gateway => $gateway,
interface => $interface,
ip_address => $ip_address,
link_state => $link_state,
mac_address => $mac_address,
media => $media,
mii_polling_interval => $mii_polling_interval,
mtu => $mtu,
operational => $operational,
primary_reselect => $primary_reselect,
primary_slave => $primary_slave,
speed => $speed,
subnet_mask => $subnet_mask,
type => $type,
up_delay => $up_delay,
}});
if ($type eq "interface")
@ -266,6 +329,37 @@ sub report_network
}
elsif ($type eq "bond")
{
my $bond_uuid = $anvil->Database->insert_or_update_bonds({
file => $THIS_FILE,
line => __LINE__,
bond_name => $interface,
bond_mode => $bond_mode,
bond_mtu => $mtu,
bond_link_state => $link_state,
bond_operational => $operational,
bond_mac_address => $mac_address,
bond_primary_slave => $primary_slave,
bond_primary_reselect => $primary_reselect,
bond_active_slave => $active_slave,
bond_mii_polling_interval => $mii_polling_interval,
bond_up_delay => $up_delay,
bond_down_delay => $down_delay,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bond_uuid => $bond_uuid }});
if (($bond_uuid) && ($ip_address))
{
my $ip_address_uuid = $anvil->Database->insert_or_update_ip_addresses({
debug => 2,
ip_address_on_type => $type,
ip_address_on_uuid => $bond_uuid,
ip_address_address => $ip_address,
ip_address_subnet_mask => $subnet_mask,
ip_address_gateway => $gateway,
ip_address_default_gateway => $default_gateway,
ip_address_dns => $dns,
});
}
}
}

View File

@ -520,7 +520,7 @@ CREATE TABLE bonds (
bond_uuid uuid not null primary key,
bond_host_uuid uuid not null,
bond_name text not null,
bond_mode integer not null, -- This is the numerical bond type (will translate to the user's language in the Anvil!)
bond_mode text not null, -- This is the numerical bond type (will translate to the user's language in the Anvil!)
bond_mtu bigint,
bond_primary_slave text,
bond_primary_reselect text,
@ -529,6 +529,8 @@ CREATE TABLE bonds (
bond_mii_polling_interval bigint,
bond_up_delay bigint,
bond_down_delay bigint,
bond_mac_address text,
bond_operational text, -- This is 'up', 'down' or 'unknown'
modified_date timestamp with time zone not null,
FOREIGN KEY(bond_host_uuid) REFERENCES hosts(host_uuid)
@ -540,7 +542,7 @@ CREATE TABLE history.bonds (
bond_uuid uuid,
bond_host_uuid uuid,
bond_name text,
bond_mode integer,
bond_mode text,
bond_mtu bigint,
bond_primary_slave text,
bond_primary_reselect text,
@ -549,6 +551,8 @@ CREATE TABLE history.bonds (
bond_mii_polling_interval bigint,
bond_up_delay bigint,
bond_down_delay bigint,
bond_mac_address text,
bond_operational text,
modified_date timestamp with time zone not null
);
ALTER TABLE history.bonds OWNER TO #!variable!user!#;
@ -572,6 +576,8 @@ BEGIN
bond_mii_polling_interval,
bond_up_delay,
bond_down_delay,
bond_mac_address,
bond_operational,
modified_date)
VALUES
(history_bonds.bond_uuid,
@ -586,6 +592,8 @@ BEGIN
history_bonds.bond_mii_polling_interval,
history_bonds.bond_up_delay,
history_bonds.bond_down_delay,
history_bonds.bond_mac_address,
history_bonds.bond_operational,
history_bonds.modified_date);
RETURN NULL;
END;