* Started working on adding IP data to network.json (and .xml).

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent 1245cfc547
commit 12afcb9731
  1. 107
      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 .= "</network>\n";
$network_xml .= "<ips>\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 .= "</ips>\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_xml => $network_xml }});
# Write the JSON file.

Loading…
Cancel
Save