From c608ebb232c3f4fd1207fa5d45ee73333e319ccd Mon Sep 17 00:00:00 2001 From: Digimer Date: Tue, 26 Nov 2019 00:15:37 -0500 Subject: [PATCH] * Added bonds -> bond_bridge_uuid to track which bridge, if any, that a bond is connected to. Updated Network->load_interfces() to record this. * Added missing foreign key references to the SQL schema. * Added support to tools/anvil-update-states to connect bonds to bridges, as appropriate. * Finished the logic in test.pl to pull the network data (with connections between bridges, bonds and interfaces) needed for the WebUI. Signed-off-by: Digimer --- Anvil/Tools/Database.pm | 43 +++++++---- Anvil/Tools/Network.pm | 153 +++++++++++++++++++++----------------- Anvil/Tools/Striker.pm | 66 ++++++++-------- Anvil/Tools/System.pm | 95 ++++++++++++----------- share/anvil.sql | 13 +++- tools/anvil-update-states | 79 ++++++++++++++------ tools/test.pl | 96 +++++++++++++++--------- 7 files changed, 333 insertions(+), 212 deletions(-) diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index e33eaaf4..190dc517 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -2342,55 +2342,61 @@ If set, this is the file name logged as the source of any INSERTs or UPDATEs. If set, this is the file line number logged as the source of any INSERTs or UPDATEs. -=head2 bond_uuid (optional) +=head3 bond_uuid (optional) If not passed, a check will be made to see if an existing entry is found for C<< bond_name >>. If found, that entry will be updated. If not found, a new record will be inserted. -=head2 bond_host_uuid (optional) +=head3 bond_host_uuid (optional) This is the host that the IP address is on. If not passed, the local C<< sys::host_uuid >> will be used (indicating it is a local IP address). -=head2 bond_name (required) +=head3 bond_name (required) This is the bond's device name. -=head2 bond_mode (required) +=head3 bond_mode (required) This is the bonding mode used for this bond. -=head2 bond_mtu (optional) +=head3 bond_mtu (optional) This is the MTU for the bonded interface. -=head2 bond_operational (optional) +=head3 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_interface (optional) +=head3 bond_primary_interface (optional) This is the primary interface name in the bond. -=head2 bond_primary_reselect (optional) +=head3 bond_primary_reselect (optional) This is the primary interface reselect policy. -=head2 bond_active_interface (optional) +=head3 bond_active_interface (optional) This is the interface currently being used by the bond. -=head2 bond_mac_address (optional) +=head3 bond_mac_address (optional) This is the current / active MAC address in use by the bond interface. -=head2 bond_mii_polling_interval (optional) +=head3 bond_mii_polling_interval (optional) This is how often, in milliseconds, that the link (mii) status is manually checked. -=head2 bond_up_delay (optional) +=head3 bond_up_delay (optional) This is how long the bond waits, in millisecinds, after an interfaces comes up before considering it for use. -=head2 bond_down_delay (optional) +=head3 bond_down_delay (optional) + +This is how long the bond waits, in millisecinds, after an interfaces goes down before considering it failed. + +head3 bond_bridge_uuid (optional) + +This is the C<< briges >> -> C<< bridge_uuid >> of the bridge this bond is connected to, if any. =cut sub insert_or_update_bonds @@ -2417,6 +2423,7 @@ sub insert_or_update_bonds my $bond_down_delay = defined $parameter->{bond_down_delay} ? $parameter->{bond_down_delay} : ""; my $bond_mac_address = defined $parameter->{bond_mac_address} ? $parameter->{bond_mac_address} : ""; my $bond_operational = defined $parameter->{bond_operational} ? $parameter->{bond_operational} : ""; + my $bond_bridge_uuid = defined $parameter->{bond_bridge_uuid} ? $parameter->{bond_bridge_uuid} : ""; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { uuid => $uuid, file => $file, @@ -2434,6 +2441,7 @@ sub insert_or_update_bonds bond_down_delay => $bond_down_delay, bond_mac_address => $bond_mac_address, bond_operational => $bond_operational, + bond_bridge_uuid => $bond_bridge_uuid, }}); if (not $bond_name) @@ -2524,6 +2532,7 @@ INSERT INTO bond_down_delay, bond_mac_address, bond_operational, + bond_bridge_uuid, modified_date ) VALUES ( ".$anvil->Database->quote($bond_uuid).", @@ -2539,6 +2548,7 @@ INSERT INTO ".$anvil->Database->quote($bond_down_delay).", ".$anvil->Database->quote($bond_mac_address).", ".$anvil->Database->quote($bond_operational).", + ".$anvil->Database->quote($bond_bridge_uuid).", ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." ); "; @@ -2561,7 +2571,8 @@ SELECT bond_up_delay, bond_down_delay, bond_mac_address, - bond_operational + bond_operational, + bond_bridge_uuid FROM bonds WHERE @@ -2595,6 +2606,7 @@ WHERE my $old_bond_down_delay = $row->[9]; my $old_bond_mac_address = $row->[10]; my $old_bond_operational = $row->[11]; + my $old_bond_bridge_uuid = $row->[12]; $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, @@ -2608,6 +2620,7 @@ WHERE old_bond_down_delay => $old_bond_down_delay, old_bond_mac_address => $old_bond_mac_address, old_bond_operational => $old_bond_operational, + old_bond_bridge_uuid => $old_bond_bridge_uuid, }}); # Anything change? @@ -2622,6 +2635,7 @@ WHERE ($old_bond_up_delay ne $bond_up_delay) or ($old_bond_down_delay ne $bond_down_delay) or ($old_bond_mac_address ne $bond_mac_address) or + ($old_bond_bridge_uuid ne $bond_bridge_uuid) or ($old_bond_operational ne $bond_operational)) { # Something changed, save. @@ -2641,6 +2655,7 @@ SET bond_down_delay = ".$anvil->Database->quote($bond_down_delay).", bond_mac_address = ".$anvil->Database->quote($bond_mac_address).", bond_operational = ".$anvil->Database->quote($bond_operational).", + bond_bridge_uuid = ".$anvil->Database->quote($bond_bridge_uuid).", modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." WHERE bond_uuid = ".$anvil->Database->quote($bond_uuid)." diff --git a/Anvil/Tools/Network.pm b/Anvil/Tools/Network.pm index 073d96f7..3c9eb8e1 100755 --- a/Anvil/Tools/Network.pm +++ b/Anvil/Tools/Network.pm @@ -786,8 +786,72 @@ sub load_interfces delete $anvil->data->{network}{$host}; } - # Now load bond info + # Now load bridge info my $query = " +SELECT + bridge_uuid, + bridge_name, + bridge_id, + bridge_mac_address, + bridge_mtu, + bridge_stp_enabled +FROM + bridges +WHERE + bridge_id != 'DELETED' +AND + bridge_host_uuid = ".$anvil->Database->quote($host_uuid)." +;"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0124", variables => { query => $query }}); + my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); + my $count = @{$results}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + results => $results, + count => $count, + }}); + foreach my $row (@{$results}) + { + my $bridge_uuid = defined $row->[0] ? $row->[0] : ""; + my $bridge_name = defined $row->[1] ? $row->[1] : ""; + my $bridge_id = defined $row->[2] ? $row->[2] : ""; + my $bridge_mac_address = defined $row->[3] ? $row->[3] : ""; + my $bridge_mtu = defined $row->[4] ? $row->[4] : ""; + my $bridge_stp_enabled = defined $row->[5] ? $row->[5] : ""; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + bridge_uuid => $bridge_uuid, + bridge_name => $bridge_name, + bridge_id => $bridge_id, + bridge_mac_address => $bridge_mac_address, + bridge_mtu => $bridge_mtu, + bridge_stp_enabled => $bridge_stp_enabled, + }}); + + # Record the bridge_uuid -> name + $anvil->data->{network}{$host}{bridge_uuid}{$bridge_uuid}{name} = $bridge_name; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "network::${host}::bridge_uuid::${bridge_uuid}::name" => $anvil->data->{network}{$host}{bridge_uuid}{$bridge_uuid}{name}, + }}); + + # We'll initially load empty strings for what would be the IP information. Any interface with IPs will be populated when we call + $anvil->data->{network}{$host}{interface}{$bridge_name}{uuid} = $bridge_uuid; + $anvil->data->{network}{$host}{interface}{$bridge_name}{id} = $bridge_id; + $anvil->data->{network}{$host}{interface}{$bridge_name}{mac_address} = $bridge_mac_address; + $anvil->data->{network}{$host}{interface}{$bridge_name}{mtu} = $bridge_mtu; + $anvil->data->{network}{$host}{interface}{$bridge_name}{stp_enabled} = $bridge_stp_enabled; + $anvil->data->{network}{$host}{interface}{$bridge_name}{type} = "bridge"; + $anvil->data->{network}{$host}{interface}{$bridge_name}{interfaces} = []; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "network::${host}::interface::${bridge_name}::uuid" => $anvil->data->{network}{$host}{interface}{$bridge_name}{uuid}, + "network::${host}::interface::${bridge_name}::id" => $anvil->data->{network}{$host}{interface}{$bridge_name}{id}, + "network::${host}::interface::${bridge_name}::mac_address" => $anvil->data->{network}{$host}{interface}{$bridge_name}{mac_address}, + "network::${host}::interface::${bridge_name}::mtu" => $anvil->data->{network}{$host}{interface}{$bridge_name}{mtu}, + "network::${host}::interface::${bridge_name}::stp_enabled" => $anvil->data->{network}{$host}{interface}{$bridge_name}{stp_enabled}, + "network::${host}::interface::${bridge_name}::type" => $anvil->data->{network}{$host}{interface}{$bridge_name}{type}, + }}); + } + + # Now load bond info + $query = " SELECT bond_uuid, bond_name, @@ -800,15 +864,16 @@ SELECT bond_up_delay, bond_down_delay, bond_mac_address, - bond_operational + bond_operational, + bond_bridge_uuid FROM bonds WHERE bond_mode != 'DELETED' AND bond_host_uuid = ".$anvil->Database->quote($host_uuid)." ;"; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0124", variables => { query => $query }}); - my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); - my $count = @{$results}; + $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); + $count = @{$results}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { results => $results, count => $count, @@ -827,6 +892,8 @@ AND my $bond_down_delay = defined $row->[9] ? $row->[9] : ""; my $bond_mac_address = defined $row->[10] ? $row->[10] : ""; my $bond_operational = defined $row->[11] ? $row->[11] : ""; + my $bond_bridge_uuid = defined $row->[12] ? $row->[12] : ""; + my $bridge_name = ""; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { bond_uuid => $bond_uuid, bond_name => $bond_name, @@ -840,8 +907,20 @@ AND bond_down_delay => $bond_down_delay, bond_mac_address => $bond_mac_address, bond_operational => $bond_operational, + bond_bridge_uuid => $bond_bridge_uuid, }}); + # If this bond is connected to a bridge, get the bridge name. + if (($bond_bridge_uuid) && (defined $anvil->data->{network}{$host}{bridge_uuid}{$bond_bridge_uuid}{name})) + { + $bridge_name = $anvil->data->{network}{$host}{bridge_uuid}{$bond_bridge_uuid}{name}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + bond_bridge_uuid => $bond_bridge_uuid, + bridge_name => $bridge_name, + }}); + push @{$anvil->data->{network}{$host}{interface}{$bridge_name}{interfaces}}, $bond_name; + } + # Record the bond_uuid -> name $anvil->data->{network}{$host}{bond_uuid}{$bond_uuid}{name} = $bond_name; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { @@ -860,6 +939,7 @@ AND $anvil->data->{network}{$host}{interface}{$bond_name}{down_delay} = $bond_down_delay; $anvil->data->{network}{$host}{interface}{$bond_name}{mac_address} = $bond_mac_address; $anvil->data->{network}{$host}{interface}{$bond_name}{operational} = $bond_operational; + $anvil->data->{network}{$host}{interface}{$bond_name}{bridge_uuid} = $bond_bridge_uuid; $anvil->data->{network}{$host}{interface}{$bond_name}{type} = "bond"; $anvil->data->{network}{$host}{interface}{$bond_name}{interfaces} = []; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { @@ -874,74 +954,11 @@ AND "network::${host}::interface::${bond_name}::down_delay" => $anvil->data->{network}{$host}{interface}{$bond_name}{down_delay}, "network::${host}::interface::${bond_name}::mac_address" => $anvil->data->{network}{$host}{interface}{$bond_name}{mac_address}, "network::${host}::interface::${bond_name}::operational" => $anvil->data->{network}{$host}{interface}{$bond_name}{operational}, + "network::${host}::interface::${bond_name}::bridge_uuid" => $anvil->data->{network}{$host}{interface}{$bond_name}{bridge}, "network::${host}::interface::${bond_name}::type" => $anvil->data->{network}{$host}{interface}{$bond_name}{type}, }}); } - # Now load bridge info - $query = " -SELECT - bridge_uuid, - bridge_name, - bridge_id, - bridge_mac_address, - bridge_mtu, - bridge_stp_enabled -FROM - bridges -WHERE - bridge_id != 'DELETED' -AND - bridge_host_uuid = ".$anvil->Database->quote($host_uuid)." -;"; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0124", variables => { query => $query }}); - $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); - $count = @{$results}; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - results => $results, - count => $count, - }}); - foreach my $row (@{$results}) - { - my $bridge_uuid = defined $row->[0] ? $row->[0] : ""; - my $bridge_name = defined $row->[1] ? $row->[1] : ""; - my $bridge_id = defined $row->[2] ? $row->[2] : ""; - my $bridge_mac_address = defined $row->[3] ? $row->[3] : ""; - my $bridge_mtu = defined $row->[4] ? $row->[4] : ""; - my $bridge_stp_enabled = defined $row->[5] ? $row->[5] : ""; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - bridge_uuid => $bridge_uuid, - bridge_name => $bridge_name, - bridge_id => $bridge_id, - bridge_mac_address => $bridge_mac_address, - bridge_mtu => $bridge_mtu, - bridge_stp_enabled => $bridge_stp_enabled, - }}); - - # Record the bridge_uuid -> name - $anvil->data->{network}{$host}{bridge_uuid}{$bridge_uuid}{name} = $bridge_name; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - "network::${host}::bridge_uuid::${bridge_uuid}::name" => $anvil->data->{network}{$host}{bridge_uuid}{$bridge_uuid}{name}, - }}); - - # We'll initially load empty strings for what would be the IP information. Any interface with IPs will be populated when we call - $anvil->data->{network}{$host}{interface}{$bridge_name}{uuid} = $bridge_uuid; - $anvil->data->{network}{$host}{interface}{$bridge_name}{id} = $bridge_id; - $anvil->data->{network}{$host}{interface}{$bridge_name}{mac_address} = $bridge_mac_address; - $anvil->data->{network}{$host}{interface}{$bridge_name}{mtu} = $bridge_mtu; - $anvil->data->{network}{$host}{interface}{$bridge_name}{stp_enabled} = $bridge_stp_enabled; - $anvil->data->{network}{$host}{interface}{$bridge_name}{type} = "bridge"; - $anvil->data->{network}{$host}{interface}{$bridge_name}{interfaces} = []; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - "network::${host}::interface::${bridge_name}::uuid" => $anvil->data->{network}{$host}{interface}{$bridge_name}{uuid}, - "network::${host}::interface::${bridge_name}::id" => $anvil->data->{network}{$host}{interface}{$bridge_name}{id}, - "network::${host}::interface::${bridge_name}::mac_address" => $anvil->data->{network}{$host}{interface}{$bridge_name}{mac_address}, - "network::${host}::interface::${bridge_name}::mtu" => $anvil->data->{network}{$host}{interface}{$bridge_name}{mtu}, - "network::${host}::interface::${bridge_name}::stp_enabled" => $anvil->data->{network}{$host}{interface}{$bridge_name}{stp_enabled}, - "network::${host}::interface::${bridge_name}::type" => $anvil->data->{network}{$host}{interface}{$bridge_name}{type}, - }}); - } - # The order will allow us to show the order in which the interfaces were changed, which the user can # use to track interfaces as they unplug and plug cables back in. my $order = 1; diff --git a/Anvil/Tools/Striker.pm b/Anvil/Tools/Striker.pm index 188aac63..72a96e4c 100644 --- a/Anvil/Tools/Striker.pm +++ b/Anvil/Tools/Striker.pm @@ -426,7 +426,33 @@ sub parse_all_status_json } } - if ($interface_type eq "bond") + if ($interface_type eq "bridge") + { + $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_id} = $interface_hash->{bridge_id}; + $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{stp_enabled} = $interface_hash->{stp_enabled}; + + my $say_stp_enabled = $interface_hash->{stp_enabled}; + if (($say_stp_enabled eq "0") or ($say_stp_enabled eq "disabled")) + { + $say_stp_enabled = $anvil->Words->string({key => "unit_0020"}); + } + elsif (($say_stp_enabled eq "1") or ($say_stp_enabled eq "enabled_kernel")) + { + $say_stp_enabled = $anvil->Words->string({key => "unit_0021"}); + } + elsif (($say_stp_enabled eq "2") or ($say_stp_enabled eq "enabled_userland")) + { + $say_stp_enabled = $anvil->Words->string({key => "unit_0022"}); + } + $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_stp_enabled} = $interface_hash->{say_stp_enabled}; + + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::bridge_id" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_id}, + "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::stp_enabled" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{stp_enabled}, + "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_stp_enabled" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_stp_enabled}, + }}); + } + elsif ($interface_type eq "bond") { $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{mode} = $interface_hash->{mode}; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{active_interface} = $interface_hash->{active_interface}; @@ -436,6 +462,8 @@ sub parse_all_status_json $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{down_delay} = $interface_hash->{down_delay}; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{operational} = $interface_hash->{operational}; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{mii_polling_interval} = $interface_hash->{mii_polling_interval}." ".$anvil->Words->string({key => "suffix_0012"}); + $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_uuid} = $interface_hash->{bridge_uuid}; + $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_name} = $interface_hash->{bridge_name}; # Translate some values my $say_mode = $interface_hash->{mode}; @@ -471,11 +499,11 @@ sub parse_all_status_json my $say_operational = $interface_hash->{operational}; if ($say_operational eq "up") { - $say_operational = $anvil->Words->string({key => "unit_0013"}); + $say_operational = $anvil->Words->string({key => "unit_0001"}); } elsif ($say_operational eq "down") { - $say_operational = $anvil->Words->string({key => "unit_0014"}); + $say_operational = $anvil->Words->string({key => "unit_0002"}); } elsif ($say_operational eq "unknown") { @@ -509,6 +537,8 @@ sub parse_all_status_json "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::down_delay" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{down_delay}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::operational" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{operational}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::mii_polling_interval" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{mii_polling_interval}, + "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::bridge_uuid" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_uuid}, + "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::bridge_name" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_name}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_up_delay" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_up_delay}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_down_delay" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_down_delay}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_mode" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_mode}, @@ -516,32 +546,6 @@ sub parse_all_status_json "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_primary_reselect" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_primary_reselect}, }}); } - elsif ($interface_type eq "bridge") - { - $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_id} = $interface_hash->{bridge_id}; - $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{stp_enabled} = $interface_hash->{stp_enabled}; - - my $say_stp_enabled = $interface_hash->{stp_enabled}; - if (($say_stp_enabled eq "0") or ($say_stp_enabled eq "disabled")) - { - $say_stp_enabled = $anvil->Words->string({key => "unit_0020"}); - } - elsif (($say_stp_enabled eq "1") or ($say_stp_enabled eq "enabled_kernel")) - { - $say_stp_enabled = $anvil->Words->string({key => "unit_0021"}); - } - elsif (($say_stp_enabled eq "2") or ($say_stp_enabled eq "enabled_userland")) - { - $say_stp_enabled = $anvil->Words->string({key => "unit_0022"}); - } - $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_stp_enabled} = $interface_hash->{say_stp_enabled}; - - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::bridge_id" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_id}, - "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::stp_enabled" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{stp_enabled}, - "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_stp_enabled" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_stp_enabled}, - }}); - } else { $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{speed} = $interface_hash->{speed}; @@ -549,7 +553,9 @@ sub parse_all_status_json $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{operational} = $interface_hash->{operational}; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{duplex} = $interface_hash->{duplex}; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{medium} = $interface_hash->{medium}; + $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bond_uuid} = $interface_hash->{bond_uuid}; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bond_name} = $interface_hash->{bond_name}; + $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_uuid} = $interface_hash->{bridge_uuid}; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_name} = $interface_hash->{bridge_name}; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{changed_order} = $interface_hash->{changed_order}; @@ -612,7 +618,9 @@ sub parse_all_status_json "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::operational" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{operational}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::duplex" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{duplex}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::medium" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{medium}, + "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::bond_uuid" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bond_uuid}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::bond_name" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bond_name}, + "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::bridge_uuid" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_uuid}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::bridge_name" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{bridge_name}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::changed_order" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{changed_order}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_speed" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_speed}, diff --git a/Anvil/Tools/System.pm b/Anvil/Tools/System.pm index 1074d032..f5d34f32 100644 --- a/Anvil/Tools/System.pm +++ b/Anvil/Tools/System.pm @@ -858,7 +858,47 @@ sub generate_state_json $iface_hash->{type} = $type; $iface_hash->{mtu} = $mtu; $iface_hash->{uuid} = $uuid; - if ($type eq "bond") + if ($type eq "bridge") + { + my $id = $anvil->data->{network}{$host}{interface}{$interface}{id}; + my $stp_enabled = $anvil->data->{network}{$host}{interface}{$interface}{stp_enabled}; + my $interfaces = $anvil->data->{network}{$host}{interface}{$interface}{interfaces}; + my $say_stp_enabled = $stp_enabled; + if (($stp_enabled eq "0") or ($stp_enabled eq "disabled")) + { + $say_stp_enabled = $anvil->Words->string({key => "unit_0020"}); + } + elsif (($stp_enabled eq "1") or ($stp_enabled eq "enabled_kernel")) + { + $say_stp_enabled = $anvil->Words->string({key => "unit_0021"}); + } + elsif (($stp_enabled eq "2") or ($stp_enabled eq "enabled_userland")) + { + $say_stp_enabled = $anvil->Words->string({key => "unit_0022"}); + } + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + bridge_id => $id, + stp_enabled => $stp_enabled, + say_stp_enabled => $say_stp_enabled, + }}); + + my $connected_interfaces = []; + foreach my $connected_interface_name (sort {$a cmp $b} @{$interfaces}) + { + push @{$connected_interfaces}, $connected_interface_name; + my $connected_interface_count = @{$connected_interfaces}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + connected_interface_count => $connected_interface_count, + connected_interface_name => $connected_interface_name, + }}); + } + + $iface_hash->{bridge_id} = $id; + $iface_hash->{stp_enabled} = $stp_enabled; + $iface_hash->{say_stp_enabled} = $say_stp_enabled; + $iface_hash->{connected_interfaces} = $connected_interfaces; + } + elsif ($type eq "bond") { my $mode = $anvil->data->{network}{$host}{interface}{$interface}{mode}; my $primary_interface = $anvil->data->{network}{$host}{interface}{$interface}{primary_interface}; @@ -871,6 +911,8 @@ sub generate_state_json my $down_delay = $anvil->data->{network}{$host}{interface}{$interface}{down_delay}; my $operational = $anvil->data->{network}{$host}{interface}{$interface}{operational}; my $interfaces = $anvil->data->{network}{$host}{interface}{$interface}{interfaces}; + my $bridge_uuid = $anvil->data->{network}{$host}{interface}{$interface}{bridge_uuid}; + my $bridge_name = $anvil->data->{network}{$host}{interface}{$interface}{bridge_name} ? $anvil->data->{network}{$host}{interface}{$interface}{bridge_name} : $anvil->Words->string({key => "unit_0005"}); my $say_mode = $mode; my $say_operational = $operational; my $say_primary_reselect = $primary_reselect; @@ -940,6 +982,8 @@ sub generate_state_json say_operational => $say_operational, operational => $operational, mii_polling_interval => $mii_polling_interval, + bridge_uuid => $bridge_uuid, + bridge_name => $bridge_name, }}); my $connected_interfaces = []; foreach my $connected_interface_name (sort {$a cmp $b} @{$interfaces}) @@ -964,46 +1008,8 @@ sub generate_state_json $iface_hash->{operational} = $operational; $iface_hash->{mii_polling_interval} = $mii_polling_interval; $iface_hash->{connected_interfaces} = $connected_interfaces; - } - elsif ($type eq "bridge") - { - my $id = $anvil->data->{network}{$host}{interface}{$interface}{id}; - my $stp_enabled = $anvil->data->{network}{$host}{interface}{$interface}{stp_enabled}; - my $interfaces = $anvil->data->{network}{$host}{interface}{$interface}{interfaces}; - my $say_stp_enabled = $stp_enabled; - if (($stp_enabled eq "0") or ($stp_enabled eq "disabled")) - { - $say_stp_enabled = $anvil->Words->string({key => "unit_0020"}); - } - elsif (($stp_enabled eq "1") or ($stp_enabled eq "enabled_kernel")) - { - $say_stp_enabled = $anvil->Words->string({key => "unit_0021"}); - } - elsif (($stp_enabled eq "2") or ($stp_enabled eq "enabled_userland")) - { - $say_stp_enabled = $anvil->Words->string({key => "unit_0022"}); - } - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - bridge_id => $id, - stp_enabled => $stp_enabled, - say_stp_enabled => $say_stp_enabled, - }}); - - my $connected_interfaces = []; - foreach my $connected_interface_name (sort {$a cmp $b} @{$interfaces}) - { - push @{$connected_interfaces}, $connected_interface_name; - my $connected_interface_count = @{$connected_interfaces}; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - connected_interface_count => $connected_interface_count, - connected_interface_name => $connected_interface_name, - }}); - } - - $iface_hash->{bridge_id} = $id; - $iface_hash->{stp_enabled} = $stp_enabled; - $iface_hash->{say_stp_enabled} = $say_stp_enabled; - $iface_hash->{connected_interfaces} = $connected_interfaces; + $iface_hash->{bridge_uuid} = $bridge_uuid; + $iface_hash->{bridge_name} = $bridge_name; } else { @@ -1013,7 +1019,9 @@ sub generate_state_json my $operational = $anvil->data->{network}{$host}{interface}{$interface}{operational}; my $duplex = $anvil->data->{network}{$host}{interface}{$interface}{duplex}; my $medium = $anvil->data->{network}{$host}{interface}{$interface}{medium}; + my $bond_uuid = $anvil->data->{network}{$host}{interface}{$interface}{bond_uuid}; my $bond_name = $anvil->data->{network}{$host}{interface}{$interface}{bond_name} ? $anvil->data->{network}{$host}{interface}{$interface}{bond_name} : $anvil->Words->string({key => "unit_0005"}); + my $bridge_uuid = $anvil->data->{network}{$host}{interface}{$interface}{bridge_uuid}; my $bridge_name = $anvil->data->{network}{$host}{interface}{$interface}{bridge_name} ? $anvil->data->{network}{$host}{interface}{$interface}{bridge_name} : $anvil->Words->string({key => "unit_0005"}); my $changed_order = $anvil->data->{network}{$host}{interface}{$interface}{changed_order}; my $say_link_state = $link_state; @@ -1068,7 +1076,9 @@ sub generate_state_json duplex => $duplex, say_medium => $say_medium, medium => $medium, + bond_uuid => $bond_uuid, bond_name => $bond_name, + bridge_uuid => $bridge_uuid, bridge_name => $bridge_name, changed_order => $changed_order, }}); @@ -1083,7 +1093,9 @@ sub generate_state_json $iface_hash->{duplex} = $duplex; $iface_hash->{say_medium} = $say_medium; $iface_hash->{medium} = $medium; + $iface_hash->{bond_uuid} = $bond_uuid; $iface_hash->{bond_name} = $bond_name; + $iface_hash->{bridge_uuid} = $bridge_uuid; $iface_hash->{bridge_name} = $bridge_name; $iface_hash->{changed_order} = $changed_order; }; @@ -1128,7 +1140,6 @@ sub generate_state_json ssh_fingerprint => $host_key, network_interfaces => $ifaces_array, }; - } # Write out the JSON file. diff --git a/share/anvil.sql b/share/anvil.sql index 166e2082..31fb91ce 100644 --- a/share/anvil.sql +++ b/share/anvil.sql @@ -223,7 +223,9 @@ CREATE TABLE host_variable ( host_variable_host_uuid uuid not null, host_variable_name text not null, host_variable_value text not null, - modified_date timestamp with time zone not null + modified_date timestamp with time zone not null, + + FOREIGN KEY(host_variable_host_uuid) REFERENCES hosts(host_uuid) ); ALTER TABLE host_variable OWNER TO admin; @@ -823,6 +825,10 @@ CREATE TABLE network_interfaces ( network_interface_bond_uuid uuid, -- If this iface is in a bond, this will contain the 'bonds -> bond_uuid' that it is slaved to. network_interface_bridge_uuid uuid, -- If this iface is attached to a bridge, this will contain the 'bridgess -> bridge_uuid' that it is connected to. modified_date timestamp with time zone not null + + FOREIGN KEY(network_interface_bridge_uuid) REFERENCES bridges(bridge_uuid), + FOREIGN KEY(network_interface_bond_uuid) REFERENCES bonds(bond_uuid), + FOREIGN KEY(network_interface_host_uuid) REFERENCES hosts(host_uuid) ); ALTER TABLE network_interfaces OWNER TO admin; @@ -904,8 +910,10 @@ CREATE TABLE bonds ( bond_down_delay bigint not null, bond_mac_address text not null, bond_operational text not null, -- This is 'up', 'down' or 'unknown' + bond_bridge_uuid uuid, modified_date timestamp with time zone not null, + FOREIGN KEY(bond_bridge_uuid) REFERENCES bridges(bridge_uuid), FOREIGN KEY(bond_host_uuid) REFERENCES hosts(host_uuid) ); ALTER TABLE bonds OWNER TO admin; @@ -925,6 +933,7 @@ CREATE TABLE history.bonds ( bond_down_delay bigint, bond_mac_address text, bond_operational text, + bond_bridge_uuid uuid, modified_date timestamp with time zone not null ); ALTER TABLE history.bonds OWNER TO admin; @@ -949,6 +958,7 @@ BEGIN bond_down_delay, bond_mac_address, bond_operational, + bond_bridge_uuid, modified_date) VALUES (history_bonds.bond_uuid, @@ -964,6 +974,7 @@ BEGIN history_bonds.bond_down_delay, history_bonds.bond_mac_address, history_bonds.bond_operational, + history_bonds.bond_bridge_uuid, history_bonds.modified_date); RETURN NULL; END; diff --git a/tools/anvil-update-states b/tools/anvil-update-states index 2383dca0..62ef4aaf 100755 --- a/tools/anvil-update-states +++ b/tools/anvil-update-states @@ -319,7 +319,7 @@ sub update_network $anvil->data->{network}{'local'}{interface}{$interface}{speed} = $speed; $anvil->data->{network}{'local'}{interface}{$interface}{subnet_mask} = $subnet_mask; $anvil->data->{network}{'local'}{interface}{$interface}{type} = $type; - $anvil->data->{network}{'local'}{interface}{$interface}{up_delay} $up_delay; + $anvil->data->{network}{'local'}{interface}{$interface}{up_delay} = $up_delay; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "network::local::interface::${interface}::active_interface" => $anvil->data->{network}{'local'}{interface}{$interface}{active_interface}, "network::local::interface::${interface}::bond_mode" => $anvil->data->{network}{'local'}{interface}{$interface}{bond_mode}, @@ -847,34 +847,39 @@ WHERE foreach my $bridge_name (sort {$a cmp $b} keys %{$anvil->data->{bridge}{'local'}}) { my $bridge_uuid = $anvil->data->{bridge_by_name}{$bridge_name}; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bridge_name => $bridge_name, bridge_uuid => $bridge_uuid, }}); foreach my $interface_name (sort {$a cmp $b} @{$anvil->data->{bridge}{'local'}{$bridge_name}{interfaces}}) { - my $interface_uuid = exists $anvil->data->{bond_by_name}{$interface_name} ? $anvil->data->{bond_by_name}{$interface_name} : $anvil->data->{interface_by_name}{$interface_name}; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { - interface_name => $interface_name, - interface_uuid => $interface_uuid, + my $interface_uuid = exists $anvil->data->{interface_by_name}{$interface_name} ? $anvil->data->{interface_by_name}{$interface_name} : ""; + my $bond_uuid = exists $anvil->data->{bond_by_name}{$interface_name} ? $anvil->data->{bond_by_name}{$interface_name} : ""; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:interface_name' => $interface_name, + 's2:interface_uuid' => $interface_uuid, + 's3:bond_uuid' => $bond_uuid, }}); - # Read the interface_bridge_uuid and, if it doesn't match, update it. - my $query = "SELECT network_interface_bridge_uuid FROM network_interfaces WHERE network_interface_uuid = ".$anvil->Database->quote($interface_uuid).";"; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }}); - my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); - my $count = @{$results}; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { - results => $results, - count => $count, - }}); - my $interface_bridge_uuid = defined $results->[0]->[0] ? $results->[0]->[0] : ""; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { interface_bridge_uuid => $interface_bridge_uuid }}); - if (($bridge_uuid) && ($interface_bridge_uuid ne $bridge_uuid)) + # Is this interface a bond or an interface? + if ($interface_uuid) { - # Update it. - my $query = " + # Read the interface_bridge_uuid and, if it doesn't match, update it. + my $query = "SELECT network_interface_bridge_uuid FROM network_interfaces WHERE network_interface_uuid = ".$anvil->Database->quote($interface_uuid).";"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }}); + my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); + my $count = @{$results}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + results => $results, + count => $count, + }}); + my $interface_bridge_uuid = defined $results->[0]->[0] ? $results->[0]->[0] : ""; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { interface_bridge_uuid => $interface_bridge_uuid }}); + if (($bridge_uuid) && ($interface_bridge_uuid ne $bridge_uuid)) + { + # Update it. + my $query = " UPDATE network_interfaces SET @@ -883,8 +888,38 @@ SET WHERE network_interface_uuid = ".$anvil->Database->quote($interface_uuid)." ;" ; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); - $anvil->Database->write({debug => 3, query => $query, source => $THIS_FILE, line => __LINE__}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); + $anvil->Database->write({debug => 3, query => $query, source => $THIS_FILE, line => __LINE__}); + } + } + elsif ($bond_uuid) + { + # Read the interface_bridge_uuid and, if it doesn't match, update it. + my $query = "SELECT bond_bridge_uuid FROM bonds WHERE bond_uuid = ".$anvil->Database->quote($bond_uuid).";"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }}); + my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); + my $count = @{$results}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + results => $results, + count => $count, + }}); + my $bond_bridge_uuid = defined $results->[0]->[0] ? $results->[0]->[0] : ""; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bond_bridge_uuid => $bond_bridge_uuid }}); + if (($bridge_uuid) && ($bond_bridge_uuid ne $bridge_uuid)) + { + # Update it. + my $query = " +UPDATE + bonds +SET + bond_bridge_uuid = ".$anvil->Database->quote($bridge_uuid).", + modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." +WHERE + bond_uuid = ".$anvil->Database->quote($bond_uuid)." +;" ; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); + $anvil->Database->write({debug => 3, query => $query, source => $THIS_FILE, line => __LINE__}); + } } } } diff --git a/tools/test.pl b/tools/test.pl index 922d4b57..9a6771fb 100755 --- a/tools/test.pl +++ b/tools/test.pl @@ -70,13 +70,16 @@ $anvil->Striker->parse_all_status_json({debug => 3}); # } # print Dumper $anvil->data->{json}{all_status}{hosts}; -#die; +# print Dumper $anvil->data->{json}{all_status}{hosts}{'el8-a01n02.digimer.ca'}{network_interface}; +# die; -foreach my $host_name (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{hosts}}) +#foreach my $host_name (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{hosts}}) +foreach my $host_name ("el8-a01n02.digimer.ca") { + print "\n"; print "Host: [".$host_name." (".$anvil->data->{json}{all_status}{hosts}{$host_name}{short_host_name}.")], Type: [".$anvil->data->{json}{all_status}{hosts}{$host_name}{type}."], Configured: [".$anvil->data->{json}{all_status}{hosts}{$host_name}{configured}."], \n"; - print " - Host UUID: ..... [".$anvil->data->{json}{all_status}{hosts}{$host_name}{host_uuid}."]\n"; - print " - SSH Fingerprint: [".$anvil->data->{json}{all_status}{hosts}{$host_name}{ssh_fingerprint}."]\n"; + #print " - Host UUID: ..... [".$anvil->data->{json}{all_status}{hosts}{$host_name}{host_uuid}."]\n"; + #print " - SSH Fingerprint: [".$anvil->data->{json}{all_status}{hosts}{$host_name}{ssh_fingerprint}."]\n"; foreach my $interface_name (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bridge}}) { @@ -89,37 +92,45 @@ foreach my $host_name (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{ my $default_gateway = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bridge}{$interface_name}{default_gateway}; my $gateway = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bridge}{$interface_name}{gateway}; my $dns = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bridge}{$interface_name}{dns}; - print " - Bridge: [".$interface_name."], MTU: [".$mtu."], ID: [".$bridge_id."], STP: [".$stp_enabled."]\n"; + print "- Bridge: [".$interface_name."], MTU: [".$mtu."], ID: [".$bridge_id."], STP: [".$stp_enabled."]\n"; if ($ip) { if ($gateway) { - print " - IP: [".$ip."/".$subnet_mask."], Gateway (default?): [".$gateway." (".$default_gateway.")], DNS: [".$dns."]\n"; + print " - IP: [".$ip."/".$subnet_mask."], Gateway (default?): [".$gateway." (".$default_gateway.")], DNS: [".$dns."]\n"; } else { - print " - IP: [".$ip."/".$subnet_mask."]\n"; + print " - IP: [".$ip."/".$subnet_mask."]\n"; } } else { - print " - No IP on this device\n"; + print " - No IP on this bridge\n"; } - foreach my $connected_interface (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bridge}{$interface_name}{connected_interfaces}}) + + my $connected_interfaces = keys %{$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bridge}{$interface_name}{connected_interfaces}}; + if ($connected_interfaces) { - my $type = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bridge}{$interface_name}{connected_interfaces}{$connected_interface}{type}; - print " - Connected: [".$connected_interface."], type: [".$type."]\n"; - if ($type eq "bond") - { - show_bond($anvil, $host_name, $connected_interface, " "); - } - else + print "==[ Interfaces connected to this bridge ]==\n"; + foreach my $connected_interface (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bridge}{$interface_name}{connected_interfaces}}) { - show_interface($anvil, $host_name, $connected_interface, " "); + my $type = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bridge}{$interface_name}{connected_interfaces}{$connected_interface}{type}; + if ($type eq "bond") + { + show_bond($anvil, $host_name, $connected_interface); + } + else + { + show_interface($anvil, $host_name, $connected_interface); + } } + print "===========================================\n"; + } + else + { + print "==[ Nothing connected to this bridge ]===\n"; } - - print "\n"; $anvil->data->{json}{all_status}{hosts}{$host_name}{shown}{$interface_name} = 1; } @@ -141,8 +152,9 @@ $anvil->nice_exit({exit_code => 0}); sub show_bond { - my ($anvil, $host_name, $interface_name, $spaces) = @_; + my ($anvil, $host_name, $interface_name) = @_; + print "Bond: [".$interface_name."]\n"; my $uuid = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{uuid}; my $mtu = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{mtu}." ".$anvil->Words->string({key => "suffix_0014"}); my $ip = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{ip}; @@ -158,34 +170,45 @@ sub show_bond my $down_delay = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{down_delay}; my $operational = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{operational}; my $mii_polling_interval = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{mii_polling_interval}; + my $bridge_name = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{bridge_name}; my $say_up_delay = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{say_up_delay}; my $say_down_delay = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{say_down_delay}; my $say_mode = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{say_mode}; my $say_operational = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{say_operational}; my $say_primary_reselect = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{say_primary_reselect}; - print $spaces."- Bond: [".$interface_name."], Mode: [".$say_mode." (".$mode.")], MTU: [".$mtu."], Operational: [".$say_operational." (".$operational.")]\n"; - print $spaces." Active interface: [".$active_interface."], Primary interface: [".$primary_interface."], Primary reselect policy: [".$say_primary_reselect." (".$primary_reselect.")]\n"; - print $spaces." Up delay: [".$say_up_delay." (".$up_delay.")], Down delay: [".$say_down_delay." (".$down_delay.")], MII polling interval: [".$mii_polling_interval."]\n"; + print "- Bond: [".$interface_name."], Mode: [".$say_mode." (".$mode.")], MTU: [".$mtu."], Operational: [".$say_operational." (".$operational.")], Bridge: [".$bridge_name."]\n"; + print " Active interface: [".$active_interface."], Primary interface: [".$primary_interface."], Primary reselect policy: [".$say_primary_reselect." (".$primary_reselect.")]\n"; + print " Up delay: [".$say_up_delay." (".$up_delay.")], Down delay: [".$say_down_delay." (".$down_delay.")], MII polling interval: [".$mii_polling_interval."]\n"; if ($ip) { if ($gateway) { - print " - IP: [".$ip."/".$subnet_mask."], Gateway (default?): [".$gateway." (".$default_gateway.")], DNS: [".$dns."]\n"; + print " - IP: [".$ip."/".$subnet_mask."], Gateway (default?): [".$gateway." (".$default_gateway.")], DNS: [".$dns."]\n"; } else { - print " - IP: [".$ip."/".$subnet_mask."]\n"; + print " - IP: [".$ip."/".$subnet_mask."]\n"; } } else { - print " - No IP on this device\n"; + print " - No IP on this bond\n"; + } + + my $connected_interfaces = keys %{$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{connected_interfaces}}; + if ($connected_interfaces) + { + print "--[ Interfaces connected to this bond ]----\n"; + foreach my $connected_interface (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bond}{$interface_name}{connected_interfaces}}) + { + show_interface($anvil, $host_name, $connected_interface); + } + print "-------------------------------------------"; } - foreach my $connected_interface (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bridge}{$interface_name}{connected_interfaces}}) + else { - print " - Connected: [".$connected_interface."], type: [".$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{bridge}{$interface_name}{connected_interfaces}{$connected_interface}{type}."]\n"; - show_interface($anvil, $host_name, $connected_interface, $spaces." "); + print "--[ Nothing connected to this bond ]-----\n"; } print "\n"; @@ -196,7 +219,8 @@ sub show_bond sub show_interface { - my ($anvil, $host_name, $interface_name, $spaces) = @_; + my ($anvil, $host_name, $interface_name) = @_; + print "Interface: [".$interface_name."]\n"; my $uuid = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{interface}{$interface_name}{uuid}; my $mtu = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{interface}{$interface_name}{mtu}." ".$anvil->Words->string({key => "suffix_0014"}); @@ -219,23 +243,23 @@ sub show_interface my $say_operational = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{interface}{$interface_name}{say_operationa}; my $say_medium = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{interface}{$interface_name}{say_medium}; - print $spaces."- Interface: [".$interface_name."], MTU: [".$mtu."], Operational: [".$say_operational." (".$operational.")], Link state: [".$say_link_state." (".$link_state.")]\n"; - print $spaces." Change Order: [".$changed_order."], Speed: [".$say_speed." (".$speed.")], Duplex: [".$say_duplex." (".$duplex.")], Medium: [".$say_medium." (".$medium.")]\n"; - print $spaces." Connected to bond: [".$bond_name."], bridge: [".$bridge_name."]\n"; + print "- Interface: [".$interface_name."], MTU: [".$mtu."], Operational: [".$say_operational." (".$operational.")], Link state: [".$say_link_state." (".$link_state.")]\n"; + print " Change Order: [".$changed_order."], Speed: [".$say_speed." (".$speed.")], Duplex: [".$say_duplex." (".$duplex.")], Medium: [".$say_medium." (".$medium.")]\n"; + print " Connected to bond: [".$bond_name."], bridge: [".$bridge_name."]\n"; if ($ip) { if ($gateway) { - print " - IP: [".$ip."/".$subnet_mask."], Gateway (default?): [".$gateway." (".$default_gateway.")], DNS: [".$dns."]\n"; + print " - IP: [".$ip."/".$subnet_mask."], Gateway (default?): [".$gateway." (".$default_gateway.")], DNS: [".$dns."]\n"; } else { - print " - IP: [".$ip."/".$subnet_mask."]\n"; + print " - IP: [".$ip."/".$subnet_mask."]\n"; } } else { - print " - No IP on this device\n"; + print " - No IP on this interface\n"; } print "\n";