* Standardized 'subnet_mask' over 'subnet' naming throughout.

* Created (and haven't finished yet) Striker->parse_all_status_json().

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 5 years ago
parent b2ff4c4c53
commit d5672e77eb
  1. 14
      Anvil/Tools.pm
  2. 68
      Anvil/Tools.t
  3. 94
      Anvil/Tools/Convert.pm
  4. 2
      Anvil/Tools/Database.pm
  5. 122
      Anvil/Tools/Network.pm
  6. 312
      Anvil/Tools/Striker.pm
  7. 116
      Anvil/Tools/System.pm
  8. 30
      Anvil/Tools/Validate.pm
  9. 252
      cgi-bin/striker
  10. 1
      html/skins/alteeve/anvil.html
  11. 24
      html/skins/alteeve/anvil.js
  12. 12
      html/skins/alteeve/config.html
  13. 28
      html/skins/alteeve/config.js
  14. 17
      html/skins/alteeve/pxe.txt
  15. 1
      share/words.xml
  16. 20
      tools/anvil-configure-host
  17. 40
      tools/anvil-manage-files
  18. 8
      tools/anvil-manage-firewall
  19. 20
      tools/anvil-update-states
  20. 26
      tools/striker-manage-install-target
  21. 61
      tools/striker-scan-network

@ -964,8 +964,8 @@ sub _set_defaults
network => {
# BCN starts at 10.200(+n)/16
bcn => {
subnet => "10.200.0.0",
netmask => "255.255.0.0",
network => "10.200.0.0",
subnet_mask => "255.255.0.0",
switch_octet3 => "1",
pdu_octet3 => "2",
ups_octet3 => "3",
@ -976,14 +976,14 @@ sub _set_defaults
# The IFN will not be under our control. So for suggestion to the user purpose only,
# IFN starts at 10.255/16
ifn => {
subnet => "10.255.0.0",
netmask => "255.255.0.0",
striker_octet3 => "4",
network => "10.255.0.0",
subnet_mask => "255.255.0.0",
striker_octet3 => "4",
},
# SN starts at 10.100(+n)/16
sn => {
subnet => "10.100.0.0",
netmask => "255.255.0.0",
network => "10.100.0.0",
subnet_mask => "255.255.0.0",
},
test => {
domains => ["alteeve.com", "redhat.com", "google.com"],

@ -89,40 +89,40 @@ is($anvil->Convert->cidr({cidr => "29"}), "255.255.255.248", "Verifying that Con
is($anvil->Convert->cidr({cidr => "30"}), "255.255.255.252", "Verifying that Convert->cidr properly returned '255.255.255.252' when given a 'cidr' parameter of '30'.");
is($anvil->Convert->cidr({cidr => "31"}), "255.255.255.254", "Verifying that Convert->cidr properly returned '255.255.255.254' when given a 'cidr' parameter of '31'.");
is($anvil->Convert->cidr({cidr => "32"}), "255.255.255.255", "Verifying that Convert->cidr properly returned '255.255.255.255' when given a 'cidr' parameter of '32'.");
is($anvil->Convert->cidr({subnet => "fake"}), "", "Verifying that Convert->cidr properly returned an empty string for a bad 'subnet' parameter.");
is($anvil->Convert->cidr({subnet => "0.0.0.0"}), "0", "Verifying that Convert->cidr properly returned '0' when given a 'subnet' parameter of '0.0.0.0'.");
is($anvil->Convert->cidr({subnet => "128.0.0.0"}), "1", "Verifying that Convert->cidr properly returned '1' when given a 'subnet' parameter of '128.0.0.0'.");
is($anvil->Convert->cidr({subnet => "192.0.0.0"}), "2", "Verifying that Convert->cidr properly returned '2' when given a 'subnet' parameter of '192.0.0.0'.");
is($anvil->Convert->cidr({subnet => "224.0.0.0"}), "3", "Verifying that Convert->cidr properly returned '3' when given a 'subnet' parameter of '224.0.0.0'.");
is($anvil->Convert->cidr({subnet => "240.0.0.0"}), "4", "Verifying that Convert->cidr properly returned '4' when given a 'subnet' parameter of '240.0.0.0'.");
is($anvil->Convert->cidr({subnet => "248.0.0.0"}), "5", "Verifying that Convert->cidr properly returned '5' when given a 'subnet' parameter of '248.0.0.0'.");
is($anvil->Convert->cidr({subnet => "252.0.0.0"}), "6", "Verifying that Convert->cidr properly returned '6' when given a 'subnet' parameter of '252.0.0.0'.");
is($anvil->Convert->cidr({subnet => "254.0.0.0"}), "7", "Verifying that Convert->cidr properly returned '7' when given a 'subnet' parameter of '254.0.0.0'.");
is($anvil->Convert->cidr({subnet => "255.0.0.0"}), "8", "Verifying that Convert->cidr properly returned '8' when given a 'subnet' parameter of '255.0.0.0'.");
is($anvil->Convert->cidr({subnet => "255.128.0.0"}), "9", "Verifying that Convert->cidr properly returned '9' when given a 'subnet' parameter of '255.128.0.0'.");
is($anvil->Convert->cidr({subnet => "255.192.0.0"}), "10", "Verifying that Convert->cidr properly returned '10' when given a 'subnet' parameter of '255.192.0.0'.");
is($anvil->Convert->cidr({subnet => "255.224.0.0"}), "11", "Verifying that Convert->cidr properly returned '11' when given a 'subnet' parameter of '255.224.0.0'.");
is($anvil->Convert->cidr({subnet => "255.240.0.0"}), "12", "Verifying that Convert->cidr properly returned '12' when given a 'subnet' parameter of '255.240.0.0'.");
is($anvil->Convert->cidr({subnet => "255.248.0.0"}), "13", "Verifying that Convert->cidr properly returned '13' when given a 'subnet' parameter of '255.248.0.0'.");
is($anvil->Convert->cidr({subnet => "255.252.0.0"}), "14", "Verifying that Convert->cidr properly returned '14' when given a 'subnet' parameter of '255.252.0.0'.");
is($anvil->Convert->cidr({subnet => "255.254.0.0"}), "15", "Verifying that Convert->cidr properly returned '15' when given a 'subnet' parameter of '255.254.0.0'.");
is($anvil->Convert->cidr({subnet => "255.255.0.0"}), "16", "Verifying that Convert->cidr properly returned '16' when given a 'subnet' parameter of '255.255.0.0'.");
is($anvil->Convert->cidr({subnet => "255.255.128.0"}), "17", "Verifying that Convert->cidr properly returned '17' when given a 'subnet' parameter of '255.255.128.0'.");
is($anvil->Convert->cidr({subnet => "255.255.192.0"}), "18", "Verifying that Convert->cidr properly returned '18' when given a 'subnet' parameter of '255.255.192.0'.");
is($anvil->Convert->cidr({subnet => "255.255.224.0"}), "19", "Verifying that Convert->cidr properly returned '19' when given a 'subnet' parameter of '255.255.224.0'.");
is($anvil->Convert->cidr({subnet => "255.255.240.0"}), "20", "Verifying that Convert->cidr properly returned '20' when given a 'subnet' parameter of '255.255.240.0'.");
is($anvil->Convert->cidr({subnet => "255.255.248.0"}), "21", "Verifying that Convert->cidr properly returned '21' when given a 'subnet' parameter of '255.255.248.0'.");
is($anvil->Convert->cidr({subnet => "255.255.252.0"}), "22", "Verifying that Convert->cidr properly returned '22' when given a 'subnet' parameter of '255.255.252.0'.");
is($anvil->Convert->cidr({subnet => "255.255.254.0"}), "23", "Verifying that Convert->cidr properly returned '23' when given a 'subnet' parameter of '255.255.254.0'.");
is($anvil->Convert->cidr({subnet => "255.255.255.0"}), "24", "Verifying that Convert->cidr properly returned '24' when given a 'subnet' parameter of '255.255.255.0'.");
is($anvil->Convert->cidr({subnet => "255.255.255.128"}), "25", "Verifying that Convert->cidr properly returned '25' when given a 'subnet' parameter of '255.255.255.128'.");
is($anvil->Convert->cidr({subnet => "255.255.255.192"}), "26", "Verifying that Convert->cidr properly returned '26' when given a 'subnet' parameter of '255.255.255.192'.");
is($anvil->Convert->cidr({subnet => "255.255.255.224"}), "27", "Verifying that Convert->cidr properly returned '27' when given a 'subnet' parameter of '255.255.255.224'.");
is($anvil->Convert->cidr({subnet => "255.255.255.240"}), "28", "Verifying that Convert->cidr properly returned '28' when given a 'subnet' parameter of '255.255.255.240'.");
is($anvil->Convert->cidr({subnet => "255.255.255.248"}), "29", "Verifying that Convert->cidr properly returned '29' when given a 'subnet' parameter of '255.255.255.248'.");
is($anvil->Convert->cidr({subnet => "255.255.255.252"}), "30", "Verifying that Convert->cidr properly returned '30' when given a 'subnet' parameter of '255.255.255.252'.");
is($anvil->Convert->cidr({subnet => "255.255.255.254"}), "31", "Verifying that Convert->cidr properly returned '31' when given a 'subnet' parameter of '255.255.255.254'.");
is($anvil->Convert->cidr({subnet => "255.255.255.255"}), "32", "Verifying that Convert->cidr properly returned '32' when given a 'subnet' parameter of '255.255.255.255'.");
is($anvil->Convert->cidr({subnet_mask => "fake"}), "", "Verifying that Convert->cidr properly returned an empty string for a bad 'subnet' parameter.");
is($anvil->Convert->cidr({subnet_mask => "0.0.0.0"}), "0", "Verifying that Convert->cidr properly returned '0' when given a 'subnet' parameter of '0.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "128.0.0.0"}), "1", "Verifying that Convert->cidr properly returned '1' when given a 'subnet' parameter of '128.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "192.0.0.0"}), "2", "Verifying that Convert->cidr properly returned '2' when given a 'subnet' parameter of '192.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "224.0.0.0"}), "3", "Verifying that Convert->cidr properly returned '3' when given a 'subnet' parameter of '224.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "240.0.0.0"}), "4", "Verifying that Convert->cidr properly returned '4' when given a 'subnet' parameter of '240.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "248.0.0.0"}), "5", "Verifying that Convert->cidr properly returned '5' when given a 'subnet' parameter of '248.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "252.0.0.0"}), "6", "Verifying that Convert->cidr properly returned '6' when given a 'subnet' parameter of '252.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "254.0.0.0"}), "7", "Verifying that Convert->cidr properly returned '7' when given a 'subnet' parameter of '254.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.0.0.0"}), "8", "Verifying that Convert->cidr properly returned '8' when given a 'subnet' parameter of '255.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.128.0.0"}), "9", "Verifying that Convert->cidr properly returned '9' when given a 'subnet' parameter of '255.128.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.192.0.0"}), "10", "Verifying that Convert->cidr properly returned '10' when given a 'subnet' parameter of '255.192.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.224.0.0"}), "11", "Verifying that Convert->cidr properly returned '11' when given a 'subnet' parameter of '255.224.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.240.0.0"}), "12", "Verifying that Convert->cidr properly returned '12' when given a 'subnet' parameter of '255.240.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.248.0.0"}), "13", "Verifying that Convert->cidr properly returned '13' when given a 'subnet' parameter of '255.248.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.252.0.0"}), "14", "Verifying that Convert->cidr properly returned '14' when given a 'subnet' parameter of '255.252.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.254.0.0"}), "15", "Verifying that Convert->cidr properly returned '15' when given a 'subnet' parameter of '255.254.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.0.0"}), "16", "Verifying that Convert->cidr properly returned '16' when given a 'subnet' parameter of '255.255.0.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.128.0"}), "17", "Verifying that Convert->cidr properly returned '17' when given a 'subnet' parameter of '255.255.128.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.192.0"}), "18", "Verifying that Convert->cidr properly returned '18' when given a 'subnet' parameter of '255.255.192.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.224.0"}), "19", "Verifying that Convert->cidr properly returned '19' when given a 'subnet' parameter of '255.255.224.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.240.0"}), "20", "Verifying that Convert->cidr properly returned '20' when given a 'subnet' parameter of '255.255.240.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.248.0"}), "21", "Verifying that Convert->cidr properly returned '21' when given a 'subnet' parameter of '255.255.248.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.252.0"}), "22", "Verifying that Convert->cidr properly returned '22' when given a 'subnet' parameter of '255.255.252.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.254.0"}), "23", "Verifying that Convert->cidr properly returned '23' when given a 'subnet' parameter of '255.255.254.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.255.0"}), "24", "Verifying that Convert->cidr properly returned '24' when given a 'subnet' parameter of '255.255.255.0'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.255.128"}), "25", "Verifying that Convert->cidr properly returned '25' when given a 'subnet' parameter of '255.255.255.128'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.255.192"}), "26", "Verifying that Convert->cidr properly returned '26' when given a 'subnet' parameter of '255.255.255.192'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.255.224"}), "27", "Verifying that Convert->cidr properly returned '27' when given a 'subnet' parameter of '255.255.255.224'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.255.240"}), "28", "Verifying that Convert->cidr properly returned '28' when given a 'subnet' parameter of '255.255.255.240'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.255.248"}), "29", "Verifying that Convert->cidr properly returned '29' when given a 'subnet' parameter of '255.255.255.248'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.255.252"}), "30", "Verifying that Convert->cidr properly returned '30' when given a 'subnet' parameter of '255.255.255.252'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.255.254"}), "31", "Verifying that Convert->cidr properly returned '31' when given a 'subnet' parameter of '255.255.255.254'.");
is($anvil->Convert->cidr({subnet_mask => "255.255.255.255"}), "32", "Verifying that Convert->cidr properly returned '32' when given a 'subnet' parameter of '255.255.255.255'.");
### Anvil::Tools::Database tests
# <none yet>

@ -40,7 +40,7 @@ Provides all methods related to converting data.
# Access to methods using '$anvil->Convert->X'.
#
# Example using 'cidr()';
my $subnet = $anvil->Convert->codr({cidr => "24"});
my $subnet_mask = $anvil->Convert->codr({cidr => "24"});
=head1 METHODS
@ -488,15 +488,15 @@ sub bytes_to_human_readable
=head2 cidr
This takes an IPv4 CIDR notation and returns the dotted-decimal subnet, or the reverse.
This takes an IPv4 CIDR notation and returns the dotted-decimal subnet mask, or the reverse.
# Convert a CIDR notation to a subnet.
my $subnet = $anvil->Convert->cidr({cidr => "24"});
# Convert a CIDR notation to a subnet mask.
my $subnet_mask = $anvil->Convert->cidr({cidr => "24"});
In the other direction;
# Convert a subnet to a CIDR notation.
my $cidr = $anvil->Convert->cidr({subnet => "255.255.255.0"});
# Convert a subnet mask to a CIDR notation.
my $cidr = $anvil->Convert->cidr({subnet_mask => "255.255.255.0"});
If the input data is invalid, an empty string will be returned.
@ -508,9 +508,9 @@ There are two parameters, each of which is optional, but one of them is required
This is a CIDR notation (between 0 and 24) to convert to a dotted-decimal address.
=head3 subnet (optional)
=head3 subnet_mask (optional)
This is a dotted-decimal subnet to convert to a CIDR notation.
This is a dotted-decimal subnet mask to convert to a CIDR notation.
=cut
sub cidr
@ -520,17 +520,17 @@ sub cidr
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $cidr = defined $parameter->{cidr} ? $parameter->{cidr} : "";
my $subnet = defined $parameter->{subnet} ? $parameter->{subnet} : "";
my $cidr = defined $parameter->{cidr} ? $parameter->{cidr} : "";
my $subnet_mask = defined $parameter->{subnet_mask} ? $parameter->{subnet_mask} : "";
my $output = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
cidr => $cidr,
subnet => $subnet,
cidr => $cidr,
subnet_mask => $subnet_mask,
}});
if ($cidr =~ /^\d{1,2}$/)
{
# Convert a cidr to a subnet
# Convert a cidr to a subnet mask
if ($cidr eq "0") { $output = "0.0.0.0"; }
elsif ($cidr eq "1") { $output = "128.0.0.0"; }
elsif ($cidr eq "2") { $output = "192.0.0.0"; }
@ -565,41 +565,41 @@ sub cidr
elsif ($cidr eq "31") { $output = "255.255.255.254"; }
elsif ($cidr eq "32") { $output = "255.255.255.255"; }
}
elsif ($anvil->Validate->is_ipv4({ip => $subnet}))
elsif ($anvil->Validate->is_ipv4({ip => $subnet_mask}))
{
if ($subnet eq "0.0.0.0" ) { $output = "0"; }
elsif ($subnet eq "128.0.0.0" ) { $output = "1"; }
elsif ($subnet eq "192.0.0.0" ) { $output = "2"; }
elsif ($subnet eq "224.0.0.0" ) { $output = "3"; }
elsif ($subnet eq "240.0.0.0" ) { $output = "4"; }
elsif ($subnet eq "248.0.0.0" ) { $output = "5"; }
elsif ($subnet eq "252.0.0.0" ) { $output = "6"; }
elsif ($subnet eq "254.0.0.0" ) { $output = "7"; }
elsif ($subnet eq "255.0.0.0" ) { $output = "8"; }
elsif ($subnet eq "255.128.0.0" ) { $output = "9"; }
elsif ($subnet eq "255.192.0.0" ) { $output = "10"; }
elsif ($subnet eq "255.224.0.0" ) { $output = "11"; }
elsif ($subnet eq "255.240.0.0" ) { $output = "12"; }
elsif ($subnet eq "255.248.0.0" ) { $output = "13"; }
elsif ($subnet eq "255.252.0.0" ) { $output = "14"; }
elsif ($subnet eq "255.254.0.0" ) { $output = "15"; }
elsif ($subnet eq "255.255.0.0" ) { $output = "16"; }
elsif ($subnet eq "255.255.128.0" ) { $output = "17"; }
elsif ($subnet eq "255.255.192.0" ) { $output = "18"; }
elsif ($subnet eq "255.255.224.0" ) { $output = "19"; }
elsif ($subnet eq "255.255.240.0" ) { $output = "20"; }
elsif ($subnet eq "255.255.248.0" ) { $output = "21"; }
elsif ($subnet eq "255.255.252.0" ) { $output = "22"; }
elsif ($subnet eq "255.255.254.0" ) { $output = "23"; }
elsif ($subnet eq "255.255.255.0" ) { $output = "24"; }
elsif ($subnet eq "255.255.255.128" ) { $output = "25"; }
elsif ($subnet eq "255.255.255.192" ) { $output = "26"; }
elsif ($subnet eq "255.255.255.224" ) { $output = "27"; }
elsif ($subnet eq "255.255.255.240" ) { $output = "28"; }
elsif ($subnet eq "255.255.255.248" ) { $output = "29"; }
elsif ($subnet eq "255.255.255.252" ) { $output = "30"; }
elsif ($subnet eq "255.255.255.254" ) { $output = "31"; }
elsif ($subnet eq "255.255.255.255" ) { $output = "32"; }
if ($subnet_mask eq "0.0.0.0" ) { $output = "0"; }
elsif ($subnet_mask eq "128.0.0.0" ) { $output = "1"; }
elsif ($subnet_mask eq "192.0.0.0" ) { $output = "2"; }
elsif ($subnet_mask eq "224.0.0.0" ) { $output = "3"; }
elsif ($subnet_mask eq "240.0.0.0" ) { $output = "4"; }
elsif ($subnet_mask eq "248.0.0.0" ) { $output = "5"; }
elsif ($subnet_mask eq "252.0.0.0" ) { $output = "6"; }
elsif ($subnet_mask eq "254.0.0.0" ) { $output = "7"; }
elsif ($subnet_mask eq "255.0.0.0" ) { $output = "8"; }
elsif ($subnet_mask eq "255.128.0.0" ) { $output = "9"; }
elsif ($subnet_mask eq "255.192.0.0" ) { $output = "10"; }
elsif ($subnet_mask eq "255.224.0.0" ) { $output = "11"; }
elsif ($subnet_mask eq "255.240.0.0" ) { $output = "12"; }
elsif ($subnet_mask eq "255.248.0.0" ) { $output = "13"; }
elsif ($subnet_mask eq "255.252.0.0" ) { $output = "14"; }
elsif ($subnet_mask eq "255.254.0.0" ) { $output = "15"; }
elsif ($subnet_mask eq "255.255.0.0" ) { $output = "16"; }
elsif ($subnet_mask eq "255.255.128.0" ) { $output = "17"; }
elsif ($subnet_mask eq "255.255.192.0" ) { $output = "18"; }
elsif ($subnet_mask eq "255.255.224.0" ) { $output = "19"; }
elsif ($subnet_mask eq "255.255.240.0" ) { $output = "20"; }
elsif ($subnet_mask eq "255.255.248.0" ) { $output = "21"; }
elsif ($subnet_mask eq "255.255.252.0" ) { $output = "22"; }
elsif ($subnet_mask eq "255.255.254.0" ) { $output = "23"; }
elsif ($subnet_mask eq "255.255.255.0" ) { $output = "24"; }
elsif ($subnet_mask eq "255.255.255.128" ) { $output = "25"; }
elsif ($subnet_mask eq "255.255.255.192" ) { $output = "26"; }
elsif ($subnet_mask eq "255.255.255.224" ) { $output = "27"; }
elsif ($subnet_mask eq "255.255.255.240" ) { $output = "28"; }
elsif ($subnet_mask eq "255.255.255.248" ) { $output = "29"; }
elsif ($subnet_mask eq "255.255.255.252" ) { $output = "30"; }
elsif ($subnet_mask eq "255.255.255.254" ) { $output = "31"; }
elsif ($subnet_mask eq "255.255.255.255" ) { $output = "32"; }
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output }});

@ -1930,7 +1930,7 @@ sub get_local_uuid
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{'local'}{interface}})
{
my $ip_address = $anvil->data->{network}{'local'}{interface}{$interface}{ip};
my $subnet_mask = $anvil->data->{network}{'local'}{interface}{$interface}{subnet};
my $subnet_mask = $anvil->data->{network}{'local'}{interface}{$interface}{subnet_mask};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
ip_address => $ip_address,
subnet_mask => $subnet_mask,

@ -615,10 +615,10 @@ This takes two hash keys from prior C<< Network->get_ips() >> or C<< ->load_ips(
A hash reference is returned using the format:
* <first>::<interface>::ip = <ip_address>
* <first>::<interface>::subnet = <subnet_mask>
* <second>::<interface>::ip = <ip_address>
* <second>::<interface>::subnet = <subnet_mask>
* <first>::<interface>::ip = <ip_address>
* <first>::<interface>::subnet_mask = <subnet_mask>
* <second>::<interface>::ip = <ip_address>
* <second>::<interface>::subnet_mask = <subnet_mask>
Where C<< first >> and C<< second >> are the parameters passed in below and C<< interface >> is the name of the interface on the fist/second machine that can talk to one another.
@ -659,46 +659,46 @@ sub find_matches
return("");
}
# Loop through the first, and on each interface with an IP/subnet, look for a match in the second.
# Loop through the first, and on each interface with an IP/subnet mask, look for a match in the second.
my $match = {};
foreach my $first_interface (sort {$b cmp $a} keys %{$anvil->data->{network}{$first}{interface}})
{
my $first_ip = $anvil->data->{network}{$first}{interface}{$first_interface}{ip};
my $first_subnet = $anvil->data->{network}{$first}{interface}{$first_interface}{subnet};
my $first_ip = $anvil->data->{network}{$first}{interface}{$first_interface}{ip};
my $first_subnet_mask = $anvil->data->{network}{$first}{interface}{$first_interface}{subnet_mask};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
first => $first,
first_interface => $first_interface,
first_ip => $first_ip,
first_subnet => $first_subnet,
first => $first,
first_interface => $first_interface,
first_ip => $first_ip,
first_subnet_mask => $first_subnet_mask,
}});
if (($first_ip) && ($first_subnet))
if (($first_ip) && ($first_subnet_mask))
{
# Look for a match.
my $first_network = $anvil->Network->get_network({
debug => $debug,
ip => $first_ip,
subnet => $first_subnet,
debug => $debug,
ip => $first_ip,
subnet_mask => $first_subnet_mask,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { a_network => $first_network }});
foreach my $second_interface (sort {$b cmp $a} keys %{$anvil->data->{network}{$second}{interface}})
{
my $second_ip = $anvil->data->{network}{$second}{interface}{$second_interface}{ip};
my $second_subnet = $anvil->data->{network}{$second}{interface}{$second_interface}{subnet};
my $second_ip = $anvil->data->{network}{$second}{interface}{$second_interface}{ip};
my $second_subnet_mask = $anvil->data->{network}{$second}{interface}{$second_interface}{subnet_mask};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
second => $second,
second_interface => $second_interface,
second_ip => $second_ip,
second_subnet => $second_subnet,
second => $second,
second_interface => $second_interface,
second_ip => $second_ip,
second_subnet_mask => $second_subnet_mask,
}});
if (($second_ip) && ($second_subnet))
if (($second_ip) && ($second_subnet_mask))
{
# Do we have a match?
my $second_network = $anvil->Network->get_network({
debug => $debug,
ip => $second_ip,
subnet => $second_subnet,
debug => $debug,
ip => $second_ip,
subnet_mask => $second_subnet_mask,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
a_network => $first_network,
@ -708,15 +708,15 @@ sub find_matches
if ($first_network eq $second_network)
{
# Match!
$match->{$first}{$first_interface}{ip} = $first_ip;
$match->{$first}{$first_interface}{subnet} = $second_network;
$match->{$second}{$second_interface}{ip} = $second_ip;
$match->{$second}{$second_interface}{subnet} = $first_network;
$match->{$first}{$first_interface}{ip} = $first_ip;
$match->{$first}{$first_interface}{subnet_mask} = $second_network;
$match->{$second}{$second_interface}{ip} = $second_ip;
$match->{$second}{$second_interface}{subnet_mask} = $first_network;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"${first}::${first_interface}::ip" => $match->{$first}{$first_interface}{ip},
"${first}::${first_interface}::subnet" => $match->{$first}{$first_interface}{subnet},
"${second}::${second_interface}::ip" => $match->{$second}{$second_interface}{ip},
"${second}::${second_interface}::subnet" => $match->{$second}{$second_interface}{subnet},
"${first}::${first_interface}::ip" => $match->{$first}{$first_interface}{ip},
"${first}::${first_interface}::subnet_mask" => $match->{$first}{$first_interface}{subnet_mask},
"${second}::${second_interface}::ip" => $match->{$second}{$second_interface}{ip},
"${second}::${second_interface}::subnet_mask" => $match->{$second}{$second_interface}{subnet_mask},
}});
}
}
@ -1079,7 +1079,7 @@ C<< Note >>: IP addresses that have been deleted will be marked so by C<< ip >>
The loaded data will be stored as:
* C<< network::<target>::interface::<iface_name>::ip >> - If an IP address is set
* C<< network::<target>::interface::<iface_name>::subnet >> - If an IP is set
* C<< network::<target>::interface::<iface_name>::subnet_mask >> - If an IP is set
* C<< network::<target>::interface::<iface_name>::mac >> - Always set.
* C<< network::<target>::interface::<iface_name>::default_gateway >> = C<< 0 >> if not the default gateway, C<< 1 >> if so.
* C<< network::<target>::interface::<iface_name>::gateway >> = If the default gateway, this is the gateway IP address.
@ -1205,7 +1205,7 @@ WHERE
$anvil->data->{network}{$host}{interface}{$interface_name}{mac_address} = $interface_mac;
$anvil->data->{network}{$host}{interface}{$interface_name}{ip} = $ip_address_address;
$anvil->data->{network}{$host}{interface}{$interface_name}{subnet} = $ip_address_subnet_mask;
$anvil->data->{network}{$host}{interface}{$interface_name}{subnet_mask} = $ip_address_subnet_mask;
$anvil->data->{network}{$host}{interface}{$interface_name}{default_gateway} = $ip_address_default_gateway;
$anvil->data->{network}{$host}{interface}{$interface_name}{gateway} = $ip_address_gateway;
$anvil->data->{network}{$host}{interface}{$interface_name}{dns} = $ip_address_dns;
@ -1213,7 +1213,7 @@ WHERE
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"network::${host}::interface::${interface_name}::mac_address" => $anvil->data->{network}{$host}{interface}{$interface_name}{mac_address},
"network::${host}::interface::${interface_name}::ip" => $anvil->data->{network}{$host}{interface}{$interface_name}{ip},
"network::${host}::interface::${interface_name}::subnet" => $anvil->data->{network}{$host}{interface}{$interface_name}{subnet},
"network::${host}::interface::${interface_name}::subnet_mask" => $anvil->data->{network}{$host}{interface}{$interface_name}{subnet_mask},
"network::${host}::interface::${interface_name}::default_gateway" => $anvil->data->{network}{$host}{interface}{$interface_name}{default_gateway},
"network::${host}::interface::${interface_name}::gateway" => $anvil->data->{network}{$host}{interface}{$interface_name}{gateway},
"network::${host}::interface::${interface_name}::dns" => $anvil->data->{network}{$host}{interface}{$interface_name}{dns},
@ -1248,7 +1248,7 @@ WHERE
$anvil->data->{network}{$host}{interface}{$interface_name}{mac_address} = $interface_mac;
$anvil->data->{network}{$host}{interface}{$interface_name}{ip} = $ip_address_address;
$anvil->data->{network}{$host}{interface}{$interface_name}{subnet} = $ip_address_subnet_mask;
$anvil->data->{network}{$host}{interface}{$interface_name}{subnet_mask} = $ip_address_subnet_mask;
$anvil->data->{network}{$host}{interface}{$interface_name}{default_gateway} = $ip_address_default_gateway;
$anvil->data->{network}{$host}{interface}{$interface_name}{gateway} = $ip_address_gateway;
$anvil->data->{network}{$host}{interface}{$interface_name}{dns} = $ip_address_dns;
@ -1256,7 +1256,7 @@ WHERE
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"network::${host}::interface::${interface_name}::mac_address" => $anvil->data->{network}{$host}{interface}{$interface_name}{mac_address},
"network::${host}::interface::${interface_name}::ip" => $anvil->data->{network}{$host}{interface}{$interface_name}{ip},
"network::${host}::interface::${interface_name}::subnet" => $anvil->data->{network}{$host}{interface}{$interface_name}{subnet},
"network::${host}::interface::${interface_name}::subnet_mask" => $anvil->data->{network}{$host}{interface}{$interface_name}{subnet_mask},
"network::${host}::interface::${interface_name}::default_gateway" => $anvil->data->{network}{$host}{interface}{$interface_name}{default_gateway},
"network::${host}::interface::${interface_name}::gateway" => $anvil->data->{network}{$host}{interface}{$interface_name}{gateway},
"network::${host}::interface::${interface_name}::dns" => $anvil->data->{network}{$host}{interface}{$interface_name}{dns},
@ -1291,7 +1291,7 @@ WHERE
$anvil->data->{network}{$host}{interface}{$interface_name}{mac_address} = $interface_mac;
$anvil->data->{network}{$host}{interface}{$interface_name}{ip} = $ip_address_address;
$anvil->data->{network}{$host}{interface}{$interface_name}{subnet} = $ip_address_subnet_mask;
$anvil->data->{network}{$host}{interface}{$interface_name}{subnet_mask} = $ip_address_subnet_mask;
$anvil->data->{network}{$host}{interface}{$interface_name}{default_gateway} = $ip_address_default_gateway;
$anvil->data->{network}{$host}{interface}{$interface_name}{gateway} = $ip_address_gateway;
$anvil->data->{network}{$host}{interface}{$interface_name}{dns} = $ip_address_dns;
@ -1299,7 +1299,7 @@ WHERE
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"network::${host}::interface::${interface_name}::mac_address" => $anvil->data->{network}{$host}{interface}{$interface_name}{mac_address},
"network::${host}::interface::${interface_name}::ip" => $anvil->data->{network}{$host}{interface}{$interface_name}{ip},
"network::${host}::interface::${interface_name}::subnet" => $anvil->data->{network}{$host}{interface}{$interface_name}{subnet},
"network::${host}::interface::${interface_name}::subnet_mask" => $anvil->data->{network}{$host}{interface}{$interface_name}{subnet_mask},
"network::${host}::interface::${interface_name}::default_gateway" => $anvil->data->{network}{$host}{interface}{$interface_name}{default_gateway},
"network::${host}::interface::${interface_name}::gateway" => $anvil->data->{network}{$host}{interface}{$interface_name}{gateway},
"network::${host}::interface::${interface_name}::dns" => $anvil->data->{network}{$host}{interface}{$interface_name}{dns},
@ -1387,7 +1387,7 @@ sub get_company_from_mac
This method checks the local system for interfaces and stores them in:
* C<< network::<target>::interface::<iface_name>::ip >> - If an IP address is set
* C<< network::<target>::interface::<iface_name>::subnet >> - If an IP is set
* C<< network::<target>::interface::<iface_name>::subnet_mask >> - If an IP is set
* C<< network::<target>::interface::<iface_name>::mac >> - Always set.
* C<< network::<target>::interface::<iface_name>::default_gateway >> = C<< 0 >> if not the default gateway, C<< 1 >> if so.
* C<< network::<target>::interface::<iface_name>::gateway >> = If the default gateway, this is the gateway IP address.
@ -1488,7 +1488,7 @@ sub get_ips
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_iface => $in_iface }});
$anvil->data->{network}{$host}{interface}{$in_iface}{ip} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{ip};
$anvil->data->{network}{$host}{interface}{$in_iface}{subnet} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{subnet};
$anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask};
$anvil->data->{network}{$host}{interface}{$in_iface}{mac_address} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{mac_address};
$anvil->data->{network}{$host}{interface}{$in_iface}{default_gateway} = 0 if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{default_gateway};
$anvil->data->{network}{$host}{interface}{$in_iface}{gateway} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{gateway};
@ -1507,19 +1507,19 @@ sub get_ips
my $cidr = $2;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip, cidr => $cidr }});
my $subnet = $cidr;
my $subnet_mask = $cidr;
if (($cidr =~ /^\d{1,2}$/) && ($cidr >= 0) && ($cidr <= 32))
{
# Convert to subnet
$subnet = $anvil->Convert->cidr({cidr => $cidr});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { subnet => $subnet }});
# Convert to subnet mask
$subnet_mask = $anvil->Convert->cidr({cidr => $cidr});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { subnet_mask => $subnet_mask }});
}
$anvil->data->{network}{$host}{interface}{$in_iface}{ip} = $ip;
$anvil->data->{network}{$host}{interface}{$in_iface}{subnet} = $subnet;
$anvil->data->{network}{$host}{interface}{$in_iface}{ip} = $ip;
$anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask} = $subnet_mask;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"s1:network::${host}::interface::${in_iface}::ip" => $anvil->data->{network}{$host}{interface}{$in_iface}{ip},
"s2:network::${host}::interface::${in_iface}::subnet" => $anvil->data->{network}{$host}{interface}{$in_iface}{subnet},
"s1:network::${host}::interface::${in_iface}::ip" => $anvil->data->{network}{$host}{interface}{$in_iface}{ip},
"s2:network::${host}::interface::${in_iface}::subnet_mask" => $anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask},
}});
}
if ($line =~ /ether ([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}) /i)
@ -1791,7 +1791,7 @@ sub get_ips
This takes an IP address and subnet and returns the network it belongs too. For example;
my $network = $anvil->Network->get_network({ip => "10.2.4.1", subnet => "255.255.0.0"});
my $network = $anvil->Network->get_network({ip => "10.2.4.1", subnet_mask => "255.255.0.0"});
This would set C<< $network >> to C<< 10.2.0.0 >>.
@ -1803,9 +1803,9 @@ Parameters;
This is the IPv4 IP address being calculated.
=head3 subnet (required)
=head3 subnet_mask (required)
This is the subnet of the IP address being calculated.
This is the subnet mask of the IP address being calculated.
=cut
sub get_network
@ -1815,12 +1815,12 @@ sub get_network
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $network = "";
my $ip = defined $parameter->{ip} ? $parameter->{ip} : "";
my $subnet = defined $parameter->{subnet} ? $parameter->{subnet} : "";
my $network = "";
my $ip = defined $parameter->{ip} ? $parameter->{ip} : "";
my $subnet_mask = defined $parameter->{subnet_mask} ? $parameter->{subnet_mask} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
ip => $ip,
subnet => $subnet,
ip => $ip,
subnet_mask => $subnet_mask,
}});
if (not $ip)
@ -1828,13 +1828,13 @@ sub get_network
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->get_network()", parameter => "ip" }});
return("");
}
if (not $subnet)
if (not $subnet_mask)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->get_network()", parameter => "subnet" }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->get_network()", parameter => "subnet_mask" }});
return("");
}
my $block = Net::Netmask->new($ip."/".$subnet);
my $block = Net::Netmask->new($ip."/".$subnet_mask);
my $base = $block->base();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { base => $base }});

@ -7,6 +7,7 @@ use strict;
use warnings;
use Data::Dumper;
use Scalar::Util qw(weaken isweak);
use JSON;
our $VERSION = "3.0.0";
my $THIS_FILE = "Striker.pm";
@ -14,6 +15,7 @@ my $THIS_FILE = "Striker.pm";
### Methods;
# get_local_repo
# get_peer_data
# parse_all_status_json
=pod
@ -312,6 +314,316 @@ sub get_peer_data
return($connected, $data);
}
=head2 parse_all_status_json
This parses the c<< all_status.json >> file is a way that Striker can more readily use. If the read or parse failes, C<< 1 >> is returned. Otherwise C<< 0 >> is returned.
This method doesn't take any parameters.
=cut
sub parse_all_status_json
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Striker->get_peer_data()" }});
# Read it in
my $json_file = $anvil->data->{path}{directories}{status}."/".$anvil->data->{path}{json}{all_status};
if (not -e $json_file)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0105", variables => { file => $json_file }});
return(1);
}
my $body = $anvil->Storage->read_file({debug => $debug, file => $json_file});
if ($body eq "!!error!!")
{
return(1);
}
my $json = JSON->new->allow_nonref;
my $data = $json->decode($body);
if (exists $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.
foreach my $host_hash (@{$data->{hosts}})
{
my $host_name = $host_hash->{name};
my $short_name = $host_hash->{short_name};
$anvil->data->{json}{all_status}{hosts}{$host_name}{host_uuid} = $host_hash->{host_uuid};
$anvil->data->{json}{all_status}{hosts}{$host_name}{type} = $host_hash->{type};
$anvil->data->{json}{all_status}{hosts}{$host_name}{short_host_name} = $host_hash->{short_name};
$anvil->data->{json}{all_status}{hosts}{$host_name}{configured} = $host_hash->{configured};
$anvil->data->{json}{all_status}{hosts}{$host_name}{ssh_fingerprint} = $host_hash->{ssh_fingerprint};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"json::all_status::hosts::${host_name}::host_uuid" => $anvil->data->{json}{all_status}{hosts}{$host_name}{host_uuid},
"json::all_status::hosts::${host_name}::type" => $anvil->data->{json}{all_status}{hosts}{$host_name}{type},
"json::all_status::hosts::${host_name}::short_host_name" => $anvil->data->{json}{all_status}{hosts}{$host_name}{short_host_name},
"json::all_status::hosts::${host_name}::configured" => $anvil->data->{json}{all_status}{hosts}{$host_name}{configured},
"json::all_status::hosts::${host_name}::ssh_fingerprint" => $anvil->data->{json}{all_status}{hosts}{$host_name}{ssh_fingerprint},
}});
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 Dumper @{$host_hash->{network_interfaces}};
foreach my $interface_hash (@{$host_hash->{network_interfaces}})
{
my $interface_name = $interface_hash->{name};
my $interface_type = $interface_hash->{type};
my $ip = $interface_hash->{ip};
my $subnet_mask = $interface_hash->{subnet_mask};
my $default_gateway = $interface_hash->{default_gateway};
my $gateway = $interface_hash->{gateway};
my $dns = $interface_hash->{dns};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
interface_name => $interface_name,
interface_type => $interface_type,
ip => $ip,
subnet_mask => $subnet_mask,
default_gateway => $default_gateway,
gateway => $gateway,
dns => $dns,
}});
$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}{mtu} = $interface_hash->{mtu}." ".$anvil->Words->string({key => "suffix_0014"});
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{ip} = $interface_hash->{ip};
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{subnet_mask} = $interface_hash->{subnet_mask};
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{default_gateway} = $interface_hash->{default_gateway};
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{gateway} = $interface_hash->{gateway};
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{dns} = $interface_hash->{dns};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::uuid" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{uuid},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::mtu" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{mtu},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::ip" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{ip},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::subnet_mask" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{subnet_mask},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::default_gateway" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{default_gateway},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::gateway" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{gateway},
"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->{connected}) && (ref($interface_hash->{connected}) eq "ARRAY"))
{
foreach my $interface_name (sort {$a cmp $b} @{$interface_hash->{connected}})
{
# We'll sort out the types after
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{connected}{$interface_name}{type} = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::mode" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{mode},
}});
}
}
if ($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_slave};
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{primary_interface} = $interface_hash->{primary_slave};
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{primary_reselect} = $interface_hash->{primary_reselect};
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{up_delay} = $interface_hash->{up_delay};
$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"});
# Translate some values
my $say_mode = $interface_hash->{mode};
if (($say_mode eq "0") or ($say_mode eq "balance-rr"))
{
$say_mode = $anvil->Words->string({key => "unit_0006"});
}
elsif (($say_mode eq "1") or ($say_mode eq "active-backup"))
{
$say_mode = $anvil->Words->string({key => "unit_0007"});
}
elsif (($say_mode eq "2") or ($say_mode eq "balanced-xor"))
{
$say_mode = $anvil->Words->string({key => "unit_0008"});
}
elsif (($say_mode eq "3") or ($say_mode eq "broadcast"))
{
$say_mode = $anvil->Words->string({key => "unit_0009"});
}
elsif (($say_mode eq "4") or ($say_mode eq "802.3ad"))
{
$say_mode = $anvil->Words->string({key => "unit_0010"});
}
elsif (($say_mode eq "5") or ($say_mode eq "balanced-tlb"))
{
$say_mode = $anvil->Words->string({key => "unit_0011"});
}
elsif (($say_mode eq "6") or ($say_mode eq "balanced-alb"))
{
$say_mode = $anvil->Words->string({key => "unit_0012"});
}
my $say_operational = $interface_hash->{operational};
if ($say_operational eq "up")
{
$say_operational = $anvil->Words->string({key => "unit_0013"});
}
elsif ($say_operational eq "down")
{
$say_operational = $anvil->Words->string({key => "unit_0014"});
}
elsif ($say_operational eq "unknown")
{
$say_operational = $anvil->Words->string({key => "unit_0004"});
}
my $say_primary_reselect = $interface_hash->{primary_reselect};
if (($say_primary_reselect eq "always") or ($say_primary_reselect eq "0"))
{
$say_primary_reselect = $anvil->Words->string({key => "unit_0017"});
}
elsif (($say_primary_reselect eq "better") or ($say_primary_reselect eq "1"))
{
$say_primary_reselect = $anvil->Words->string({key => "unit_0018"});
}
elsif (($say_primary_reselect eq "failure") or ($say_primary_reselect eq "2"))
{
$say_primary_reselect = $anvil->Words->string({key => "unit_0019"});
}
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_up_delay} = $interface_hash->{up_delay}." ".$anvil->Words->string({key => "suffix_0012"});
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_down_delay} = $interface_hash->{say_down_delay}." ".$anvil->Words->string({key => "suffix_0012"});
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_mode} = $say_mode;
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_operational} = $say_operational;
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_primary_reselect} = $say_primary_reselect;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::mode" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{mode},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::active_interface" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{active_interface},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::primary_interface" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{primary_interface},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::primary_reselect" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{primary_reselect},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::up_delay" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{up_delay},
"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}::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},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_operational" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_operational},
"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};
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{link_state} = $interface_hash->{link_state};
$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_name} = $interface_hash->{bond_name};
$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};
my $say_speed = $anvil->Convert->add_commas({number => $interface_hash->{speed}})." ".$anvil->Words->string({key => "suffix_0050"});
if ($interface_hash->{speed} >= 1000)
{
# Report in Gbps
$say_speed = $anvil->Convert->add_commas({number => ($interface_hash->{speed} / 1000)})." ".$anvil->Words->string({key => "suffix_0051"});
}
my $say_duplex = $interface_hash->{duplex};
if ($say_duplex eq "full")
{
$say_duplex = $anvil->Words->string({key => "unit_0015"});
}
elsif ($say_duplex eq "half")
{
$say_duplex = $anvil->Words->string({key => "unit_0016"});
}
elsif ($say_duplex eq "unknown")
{
$say_duplex = $anvil->Words->string({key => "unit_0004"});
}
my $say_link_state = $interface_hash->{link_state};
if ($say_link_state eq "1")
{
$say_link_state = $anvil->Words->string({key => "unit_0013"});
}
elsif ($say_link_state eq "0")
{
$say_link_state = $anvil->Words->string({key => "unit_0014"});
}
my $say_operational = $interface_hash->{operational};
if ($say_operational eq "up")
{
$say_operational = $anvil->Words->string({key => "unit_0013"});
}
elsif ($say_operational eq "down")
{
$say_operational = $anvil->Words->string({key => "unit_0014"});
}
elsif ($say_operational eq "unknown")
{
$say_operational = $anvil->Words->string({key => "unit_0004"});
}
# This will be flushed out later. For now, we just send out what we've got.
my $say_medium = $interface_hash->{medium};
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_speed} = $say_speed;
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_duplex} = $say_duplex;
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_link_state} = $say_link_state;
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_operationa} = $say_operational;
$anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_medium} = $say_medium;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::speed" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{speed},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::link_state" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{link_state},
"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_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_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},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_duplex" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_duplex},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_link_state" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_link_state},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_operationa" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_operationa},
"json::all_status::hosts::${host_name}::network_interface::${interface_type}::${interface_name}::say_medium" => $anvil->data->{json}{all_status}{hosts}{$host_name}{network_interface}{$interface_type}{$interface_name}{say_medium},
}});
}
}
}
return(0);
}
1;

@ -798,7 +798,9 @@ sub check_storage
=head2 generate_state_json
This method generates the C<< all_status.json >> file.
This method generates the C<< all_status.json >> file.
B<< Note >>: Contained in are translations of some values, for the sake of JSON readers. Developers should note to translate values in-situ as the language used here may not be the user's desired language.
This method takes no parameters.
@ -831,6 +833,10 @@ sub generate_state_json
"s6:host_key" => $host_key,
}});
$anvil->Network->load_interfces({
host_uuid => $host_uuid,
host => $short_host_name,
});
$anvil->Network->load_interfces({
host_uuid => $host_uuid,
host => $short_host_name,
@ -839,7 +845,7 @@ sub generate_state_json
{
my $type = $anvil->data->{network}{$host}{interface}{$interface}{type};
my $uuid = $anvil->data->{network}{$host}{interface}{$interface}{uuid};
my $mtu = $anvil->data->{network}{$host}{interface}{$interface}{mtu}." ".$anvil->Words->string({key => "suffix_0014"});;
my $mtu = $anvil->data->{network}{$host}{interface}{$interface}{mtu};
my $mac_address = $anvil->data->{network}{$host}{interface}{$interface}{mac_address};