* Fixed bugs in Striker->parse_all_status_json() and System->generate_state_json() where the connected interfaces to bridges and bonds wasn't be stored properly.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 5 years ago
parent aba79cc457
commit 7aaef3d6d5
  1. 4
      Anvil/Tools/Network.pm
  2. 22
      Anvil/Tools/Striker.pm
  3. 47
      Anvil/Tools/System.pm

@ -758,7 +758,7 @@ sub load_interfces
my $parameter = shift; my $parameter = shift;
my $anvil = $self->parent; my $anvil = $self->parent;
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->find_matches()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Network->load_interfces()" }});
my $clear = defined $parameter->{clear} ? $parameter->{clear} : 1; my $clear = defined $parameter->{clear} ? $parameter->{clear} : 1;
my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : $anvil->data->{sys}{host_uuid}; my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : $anvil->data->{sys}{host_uuid};
@ -771,7 +771,7 @@ sub load_interfces
if (not $host_uuid) if (not $host_uuid)
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->get_network()", parameter => "ip" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->load_interfces()", parameter => "host_uuid" }});
return(""); return("");
} }

@ -350,9 +350,6 @@ sub parse_all_status_json
delete $anvil->data->{json}{all_status}; delete $anvil->data->{json}{all_status};
} }
# print Dumper $data;
# die;
# We'll be adding data to this JSON file over time. So this will be an ever evolving method. # We'll be adding data to this JSON file over time. So this will be an ever evolving method.
foreach my $host_hash (@{$data->{hosts}}) foreach my $host_hash (@{$data->{hosts}})
{ {
@ -393,6 +390,9 @@ sub parse_all_status_json
# This lets us easily map interface names to types. # This lets us easily map interface names to types.
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface_name_to_type}{$interface_name} = $interface_type; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface_name_to_type}{$interface_name} = $interface_type;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"json::all_status::hosts::${host_name}::network_interface_name_to_type::${interface_name}" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface_name_to_type}{$interface_name},
}});
# Record the rest of the data. # Record the rest of the data.
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{uuid} = $interface_hash->{uuid}; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{uuid} = $interface_hash->{uuid};
@ -412,14 +412,16 @@ sub parse_all_status_json
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::dns" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{dns}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::dns" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{dns},
}}); }});
if ((exists $interface_hash->{interfaces}) && (ref($interface_hash->{interfaces}) eq "ARRAY")) if ((exists $interface_hash->{connected_interfaces}) && (ref($interface_hash->{connected_interfaces}) eq "ARRAY"))
{ {
foreach my $connected_interface_name (sort {$a cmp $b} @{$interface_hash->{interfaces}}) my $connected_interfaces_count = @{$interface_hash->{connected_interfaces}};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { connected_interfaces_count => $connected_interfaces_count }});
foreach my $connected_interface_name (sort {$a cmp $b} @{$interface_hash->{connected_interfaces}})
{ {
# We'll sort out the types after # We'll sort out the types after
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{connected}{$connected_interface_name}{type} = ""; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{connected_interfaces}{$connected_interface_name}{type} = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${connected_interface_name}::mode" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$connected_interface_name}{mode}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::connected_interfaces::${connected_interface_name}::type" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{connected_interfaces}{$connected_interface_name}{type},
}}); }});
} }
} }
@ -632,14 +634,14 @@ sub parse_all_status_json
foreach my $interface_name (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}}) foreach my $interface_name (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}})
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { interface_name => $interface_name }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { interface_name => $interface_name }});
foreach my $connected_interface_name (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{connected}}) foreach my $connected_interface_name (sort {$a cmp $b} keys %{$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{connected_interfaces}})
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { connected_interface_name => $connected_interface_name }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { connected_interface_name => $connected_interface_name }});
if (defined $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface_name_to_type}{$connected_interface_name}) if (defined $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface_name_to_type}{$connected_interface_name})
{ {
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{connected}{$connected_interface_name}{type} = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface_name_to_type}{$connected_interface_name}; $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{connected_interfaces}{$connected_interface_name}{type} = $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface_name_to_type}{$connected_interface_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::connected::${connected_interface_name}::type" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{connected}{$connected_interface_name}{type}, "json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::connected_interfaces::${connected_interface_name}::type" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{connected_interfaces}{$connected_interface_name}{type},
}}); }});
} }
} }

@ -811,7 +811,7 @@ sub generate_state_json
my $parameter = shift; my $parameter = shift;
my $anvil = $self->parent; my $anvil = $self->parent;
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 => "System->get_bridges()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->generate_state_json()" }});
$anvil->data->{json}{all_systems}{hosts} = []; $anvil->data->{json}{all_systems}{hosts} = [];
$anvil->Database->get_hosts_info({debug => 3}); $anvil->Database->get_hosts_info({debug => 3});
@ -834,7 +834,7 @@ sub generate_state_json
}}); }});
$anvil->Network->load_interfces({ $anvil->Network->load_interfces({
debug => 2, debug => $debug,
host_uuid => $host_uuid, host_uuid => $host_uuid,
host => $short_host_name, host => $short_host_name,
}); });
@ -941,11 +941,15 @@ sub generate_state_json
operational => $operational, operational => $operational,
mii_polling_interval => $mii_polling_interval, mii_polling_interval => $mii_polling_interval,
}}); }});
my $connected = []; my $connected_interfaces = [];
foreach my $iface (sort {$a cmp $b} @{$interfaces}) foreach my $connected_interface_name (sort {$a cmp $b} @{$interfaces})
{ {
push @{$connected}, $iface; push @{$connected_interfaces}, $connected_interface_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { iface => $iface }}); 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->{say_mode} = $say_mode; $iface_hash->{say_mode} = $say_mode;
$iface_hash->{mode} = $mode; $iface_hash->{mode} = $mode;
@ -959,7 +963,7 @@ sub generate_state_json
$iface_hash->{say_operational} = $say_operational; $iface_hash->{say_operational} = $say_operational;
$iface_hash->{operational} = $operational; $iface_hash->{operational} = $operational;
$iface_hash->{mii_polling_interval} = $mii_polling_interval; $iface_hash->{mii_polling_interval} = $mii_polling_interval;
$iface_hash->{interfaces} = $connected; $iface_hash->{connected_interfaces} = $connected_interfaces;
} }
elsif ($type eq "bridge") elsif ($type eq "bridge")
{ {
@ -984,18 +988,22 @@ sub generate_state_json
stp_enabled => $stp_enabled, stp_enabled => $stp_enabled,
say_stp_enabled => $say_stp_enabled, say_stp_enabled => $say_stp_enabled,
}}); }});
my $connected = []; my $connected_interfaces = [];
foreach my $iface (sort {$a cmp $b} @{$interfaces}) foreach my $connected_interface_name (sort {$a cmp $b} @{$interfaces})
{ {
push @{$connected}, $iface; push @{$connected_interfaces}, $connected_interface_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { iface => $iface }}); 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->{bridge_id} = $id;
$iface_hash->{stp_enabled} = $stp_enabled; $iface_hash->{stp_enabled} = $stp_enabled;
$iface_hash->{say_stp_enabled} = $say_stp_enabled; $iface_hash->{say_stp_enabled} = $say_stp_enabled;
$iface_hash->{interfaces} = $connected; $iface_hash->{connected_interfaces} = $connected_interfaces;
} }
else else
{ {
@ -1131,7 +1139,7 @@ sub generate_state_json
my $json_file = $anvil->data->{path}{directories}{status}."/".$anvil->data->{path}{json}{all_status}; my $json_file = $anvil->data->{path}{directories}{status}."/".$anvil->data->{path}{json}{all_status};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { json_file => $json_file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { json_file => $json_file }});
my $error = $anvil->Storage->write_file({ my $error = $anvil->Storage->write_file({
debug => 2, debug => $debug,
overwrite => 1, overwrite => 1,
backup => 0, backup => 0,
file => $json_file, file => $json_file,
@ -1142,6 +1150,9 @@ sub generate_state_json
}); });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { error => $error }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { error => $error }});
# Clear out the records.
delete $anvil->data->{json}{all_systems};
return(0); return(0);
} }

Loading…
Cancel
Save