diff --git a/tools/anvil-update-states b/tools/anvil-update-states index 71c096ca..968cbe39 100755 --- a/tools/anvil-update-states +++ b/tools/anvil-update-states @@ -403,54 +403,8 @@ sub report_network # I need to read back in the interface and bridge data and splice it together before I write out the # XML and JSON files. - my $ip_address = {}; - my $query = " -SELECT - ip_address_uuid, - ip_address_on_type, - ip_address_on_uuid, - ip_address_address, - ip_address_subnet_mask, - ip_address_gateway, - ip_address_default_gateway, - ip_address_dns -FROM - ip_addresses -WHERE - ip_address_host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_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, - }}); - foreach my $row (@{$results}) - { - my $ip_address_uuid = $row->[0]; - $ip_address->{$ip_address_uuid} = { - ip_address_on_type => $row->[1], - ip_address_on_uuid => $row->[2], - ip_address_address => $row->[3], - ip_address_subnet_mask => $row->[4], - ip_address_gateway => $row->[5], - ip_address_default_gateway => $row->[6], - ip_address_dns => $row->[7], - }; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { - "ip_address->{$ip_address_uuid}{ip_address_on_type}" => $ip_address->{$ip_address_uuid}{ip_address_on_type}, - "ip_address->{$ip_address_uuid}{ip_address_on_uuid}" => $ip_address->{$ip_address_uuid}{ip_address_on_uuid}, - "ip_address->{$ip_address_uuid}{ip_address_address}" => $ip_address->{$ip_address_uuid}{ip_address_address}, - "ip_address->{$ip_address_uuid}{ip_address_subnet_mask}" => $ip_address->{$ip_address_uuid}{ip_address_subnet_mask}, - "ip_address->{$ip_address_uuid}{ip_address_gateway}" => $ip_address->{$ip_address_uuid}{ip_address_gateway}, - "ip_address->{$ip_address_uuid}{ip_address_default_gateway}" => $ip_address->{$ip_address_uuid}{ip_address_default_gateway}, - "ip_address->{$ip_address_uuid}{ip_address_dns}" => $ip_address->{$ip_address_uuid}{ip_address_dns}, - }}); - } - my $bonds = {}; - $query = " + my $query = " SELECT bond_uuid, bond_name, @@ -520,8 +474,8 @@ WHERE bridge_host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid)." ;"; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }}); - $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); - $count = @{$results}; + 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, @@ -617,10 +571,63 @@ ORDER BY } $network_json =~ s/,$//s; - $network_json .= "]}\n"; + $network_json .= "]\n"; + $network_json .= "\"ips\":[\n"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_json => $network_json }}); $network_xml .= "\n"; + $network_xml .= "\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_xml => $network_xml }}); + + # Now record the IPs. + $query = " +SELECT + ip_address_uuid, + ip_address_on_type, + ip_address_on_uuid, + ip_address_address, + ip_address_subnet_mask, + ip_address_gateway, + ip_address_default_gateway, + ip_address_dns +FROM + ip_addresses +WHERE + ip_address_host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid)." +;"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, 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 => 3, list => { + results => $results, + count => $count, + }}); + foreach my $row (@{$results}) + { + my $ip_address_uuid = $row->[0]; + my $ip_address_on_type = $row->[1]; + my $ip_address_on_uuid = $row->[2]; + my $ip_address_address = $row->[3]; + my $ip_address_subnet_mask = $row->[4]; + my $ip_address_gateway = $row->[5]; + my $ip_address_default_gateway = $row->[6]; + my $ip_address_dns = $row->[7]; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "ip_address->{$ip_address_uuid}{ip_address_on_type}" => $ip_address->{$ip_address_uuid}{ip_address_on_type}, + "ip_address->{$ip_address_uuid}{ip_address_on_uuid}" => $ip_address->{$ip_address_uuid}{ip_address_on_uuid}, + "ip_address->{$ip_address_uuid}{ip_address_address}" => $ip_address->{$ip_address_uuid}{ip_address_address}, + "ip_address->{$ip_address_uuid}{ip_address_subnet_mask}" => $ip_address->{$ip_address_uuid}{ip_address_subnet_mask}, + "ip_address->{$ip_address_uuid}{ip_address_gateway}" => $ip_address->{$ip_address_uuid}{ip_address_gateway}, + "ip_address->{$ip_address_uuid}{ip_address_default_gateway}" => $ip_address->{$ip_address_uuid}{ip_address_default_gateway}, + "ip_address->{$ip_address_uuid}{ip_address_dns}" => $ip_address->{$ip_address_uuid}{ip_address_dns}, + }}); + } + + $network_json =~ s/,$//s; + $network_json .= "]}\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_json => $network_json }}); + + $network_xml .= "\n"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_xml => $network_xml }}); # Write the JSON file.