* Updated Database->insert_or_update_network_interfaces() to work like other similar methods. Also re-enabled NULL for 'network_interface_bond_uuid' as an empty string can't be used on a 'uuid' column type and it's not always set.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent 870a2eb803
commit 67c4f50bdc
  1. 205
      Anvil/Tools/Database.pm
  2. 51
      tools/anvil-update-states
  3. 13
      tools/anvil.sql

@ -1449,8 +1449,8 @@ sub insert_or_update_bridges
my $bridge_uuid = defined $parameter->{bridge_uuid} ? $parameter->{bridge_uuid} : ""; my $bridge_uuid = defined $parameter->{bridge_uuid} ? $parameter->{bridge_uuid} : "";
my $bridge_host_uuid = defined $parameter->{bridge_host_uuid} ? $parameter->{bridge_host_uuid} : $anvil->data->{sys}{host_uuid}; my $bridge_host_uuid = defined $parameter->{bridge_host_uuid} ? $parameter->{bridge_host_uuid} : $anvil->data->{sys}{host_uuid};
my $bridge_name = defined $parameter->{bridge_name} ? $parameter->{bridge_name} : ""; my $bridge_name = defined $parameter->{bridge_name} ? $parameter->{bridge_name} : "";
my $bridge_id = $parameter->{bridge_id} ? $parameter->{bridge_id} : ""; my $bridge_id = defined $parameter->{bridge_id} ? $parameter->{bridge_id} : "";
my $bridge_stp_enabled = $parameter->{bridge_stp_enabled} ? $parameter->{bridge_stp_enabled} : ""; my $bridge_stp_enabled = defined $parameter->{bridge_stp_enabled} ? $parameter->{bridge_stp_enabled} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid, uuid => $uuid,
file => $file, file => $file,
@ -1698,15 +1698,15 @@ sub insert_or_update_bonds
my $bond_host_uuid = defined $parameter->{bond_host_uuid} ? $parameter->{bond_host_uuid} : $anvil->data->{sys}{host_uuid}; my $bond_host_uuid = defined $parameter->{bond_host_uuid} ? $parameter->{bond_host_uuid} : $anvil->data->{sys}{host_uuid};
my $bond_name = defined $parameter->{bond_name} ? $parameter->{bond_name} : ""; my $bond_name = defined $parameter->{bond_name} ? $parameter->{bond_name} : "";
my $bond_mode = defined $parameter->{bond_mode} ? $parameter->{bond_mode} : ""; my $bond_mode = defined $parameter->{bond_mode} ? $parameter->{bond_mode} : "";
my $bond_mtu = $parameter->{bond_mtu} ? $parameter->{bond_mtu} : ""; my $bond_mtu = defined $parameter->{bond_mtu} ? $parameter->{bond_mtu} : "";
my $bond_primary_slave = $parameter->{bond_primary_slave} ? $parameter->{bond_primary_slave} : ""; my $bond_primary_slave = defined $parameter->{bond_primary_slave} ? $parameter->{bond_primary_slave} : "";
my $bond_primary_reselect = $parameter->{bond_primary_reselect} ? $parameter->{bond_primary_reselect} : ""; my $bond_primary_reselect = defined $parameter->{bond_primary_reselect} ? $parameter->{bond_primary_reselect} : "";
my $bond_active_slave = $parameter->{bond_active_slave} ? $parameter->{bond_active_slave} : ""; my $bond_active_slave = defined $parameter->{bond_active_slave} ? $parameter->{bond_active_slave} : "";
my $bond_mii_polling_interval = $parameter->{bond_mii_polling_interval} ? $parameter->{bond_mii_polling_interval} : ""; my $bond_mii_polling_interval = defined $parameter->{bond_mii_polling_interval} ? $parameter->{bond_mii_polling_interval} : "";
my $bond_up_delay = $parameter->{bond_up_delay} ? $parameter->{bond_up_delay} : ""; my $bond_up_delay = defined $parameter->{bond_up_delay} ? $parameter->{bond_up_delay} : "";
my $bond_down_delay = $parameter->{bond_down_delay} ? $parameter->{bond_down_delay} : ""; my $bond_down_delay = defined $parameter->{bond_down_delay} ? $parameter->{bond_down_delay} : "";
my $bond_mac_address = $parameter->{bond_mac_address} ? $parameter->{bond_mac_address} : ""; my $bond_mac_address = defined $parameter->{bond_mac_address} ? $parameter->{bond_mac_address} : "";
my $bond_operational = $parameter->{bond_operational} ? $parameter->{bond_operational} : ""; my $bond_operational = defined $parameter->{bond_operational} ? $parameter->{bond_operational} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid, uuid => $uuid,
file => $file, file => $file,
@ -2858,17 +2858,17 @@ sub insert_or_update_network_interfaces
my $uuid = defined $parameter->{uuid} ? $parameter->{uuid} : ""; my $uuid = defined $parameter->{uuid} ? $parameter->{uuid} : "";
my $file = defined $parameter->{file} ? $parameter->{file} : ""; my $file = defined $parameter->{file} ? $parameter->{file} : "";
my $line = defined $parameter->{line} ? $parameter->{line} : ""; my $line = defined $parameter->{line} ? $parameter->{line} : "";
my $network_interface_bond_uuid = defined $parameter->{network_interface_bond_uuid} ? $parameter->{network_interface_bond_uuid} : "--"; my $network_interface_bond_uuid = defined $parameter->{network_interface_bond_uuid} ? $parameter->{network_interface_bond_uuid} : 'NULL';
my $network_interface_bridge_uuid = defined $parameter->{network_interface_bridge_uuid} ? $parameter->{network_interface_bridge_uuid} : "--"; my $network_interface_bridge_uuid = defined $parameter->{network_interface_bridge_uuid} ? $parameter->{network_interface_bridge_uuid} : "";
my $network_interface_duplex = defined $parameter->{network_interface_duplex} ? $parameter->{network_interface_duplex} : "--"; my $network_interface_duplex = defined $parameter->{network_interface_duplex} ? $parameter->{network_interface_duplex} : "unknown";
my $network_interface_host_uuid = defined $parameter->{network_interface_host_uuid} ? $parameter->{network_interface_host_uuid} : $anvil->Get->host_uuid; my $network_interface_host_uuid = defined $parameter->{network_interface_host_uuid} ? $parameter->{network_interface_host_uuid} : $anvil->Get->host_uuid;
my $network_interface_link_state = defined $parameter->{network_interface_link_state} ? $parameter->{network_interface_link_state} : "--"; my $network_interface_link_state = defined $parameter->{network_interface_link_state} ? $parameter->{network_interface_link_state} : "unknown";
my $network_interface_operational = defined $parameter->{network_interface_operational} ? $parameter->{network_interface_operational} : "--"; my $network_interface_operational = defined $parameter->{network_interface_operational} ? $parameter->{network_interface_operational} : "unknown";
my $network_interface_mac_address = defined $parameter->{network_interface_mac_address} ? $parameter->{network_interface_mac_address} : "--"; my $network_interface_mac_address = defined $parameter->{network_interface_mac_address} ? $parameter->{network_interface_mac_address} : "";
my $network_interface_medium = defined $parameter->{network_interface_medium} ? $parameter->{network_interface_medium} : "--"; my $network_interface_medium = defined $parameter->{network_interface_medium} ? $parameter->{network_interface_medium} : "";
my $network_interface_mtu = defined $parameter->{network_interface_mtu} ? $parameter->{network_interface_mtu} : "--"; my $network_interface_mtu = defined $parameter->{network_interface_mtu} ? $parameter->{network_interface_mtu} : 0;
my $network_interface_name = defined $parameter->{network_interface_name} ? $parameter->{network_interface_name} : "--"; my $network_interface_name = defined $parameter->{network_interface_name} ? $parameter->{network_interface_name} : "";
my $network_interface_speed = defined $parameter->{network_interface_speed} ? $parameter->{network_interface_speed} : "--"; my $network_interface_speed = defined $parameter->{network_interface_speed} ? $parameter->{network_interface_speed} : 0;
my $network_interface_uuid = defined $parameter->{network_interface_uuid} ? $parameter->{interface_uuid} : ""; my $network_interface_uuid = defined $parameter->{network_interface_uuid} ? $parameter->{interface_uuid} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid, uuid => $uuid,
@ -2888,13 +2888,31 @@ sub insert_or_update_network_interfaces
network_interface_uuid => $network_interface_uuid, network_interface_uuid => $network_interface_uuid,
}}); }});
# I will need a MAC address and a UUID. If I don't have one, use the other to look it up. # INSERT, but make sure we have enough data first.
if ((not $network_interface_mac_address) && (not $network_interface_uuid)) if (not $network_interface_mac_address)
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_mac_address" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_mac_address" }});
return(""); return("");
} }
elsif (not $network_interface_uuid) else
{
# Always lower-case the MAC address.
$network_interface_mac_address = lc($network_interface_mac_address);
}
if (not $network_interface_name)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_name" }});
return("");
}
if (($network_interface_bridge_uuid ne 'NULL') && (not $anvil->Validate->is_uuid({uuid => $network_interface_bridge_uuid})))
{
# Bad UUID.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0130", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_name", uuid => $network_interface_bridge_uuid }});
return("");
}
# If we don't have a network interface UUID, try to look one up using the MAC address
if (not $network_interface_uuid)
{ {
# See if I know this NIC by referencing it's MAC. # See if I know this NIC by referencing it's MAC.
my $query = "SELECT network_interface_uuid FROM network_interfaces WHERE network_interface_mac_address = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_mac_address).";"; my $query = "SELECT network_interface_uuid FROM network_interfaces WHERE network_interface_mac_address = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_mac_address).";";
@ -2937,17 +2955,17 @@ WHERE
}}); }});
foreach my $row (@{$results}) foreach my $row (@{$results})
{ {
my $old_network_interface_host_uuid = $row->[0]; my $old_network_interface_host_uuid = $row->[0];
my $old_network_interface_mac_address = $row->[1]; my $old_network_interface_mac_address = $row->[1];
my $old_network_interface_name = $row->[2]; my $old_network_interface_name = $row->[2];
my $old_network_interface_speed = $row->[3]; my $old_network_interface_speed = $row->[3];
my $old_network_interface_mtu = $row->[4]; my $old_network_interface_mtu = $row->[4];
my $old_network_interface_link_state = $row->[5]; my $old_network_interface_link_state = $row->[5];
my $old_network_interface_operational = $row->[6]; my $old_network_interface_operational = $row->[6];
my $old_network_interface_duplex = $row->[7]; my $old_network_interface_duplex = $row->[7];
my $old_network_interface_medium = $row->[8]; my $old_network_interface_medium = $row->[8];
my $old_network_interface_bond_uuid = $row->[9]; my $old_network_interface_bond_uuid = defined $row->[9] ? $row->[9] : 'NULL';
my $old_network_interface_bridge_uuid = $row->[10]; my $old_network_interface_bridge_uuid = $row->[10];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_network_interface_host_uuid => $old_network_interface_host_uuid, old_network_interface_host_uuid => $old_network_interface_host_uuid,
old_network_interface_mac_address => $old_network_interface_mac_address, old_network_interface_mac_address => $old_network_interface_mac_address,
@ -2966,17 +2984,17 @@ WHERE
# Anything to update? This is a little extra complicated because if a variable was # Anything to update? This is a little extra complicated because if a variable was
# not passed in, we want to not compare it. # not passed in, we want to not compare it.
if ((($network_interface_bond_uuid ne "--") && ($network_interface_bond_uuid ne $old_network_interface_bond_uuid)) or if (($network_interface_bond_uuid ne $old_network_interface_bond_uuid) or
(($network_interface_bridge_uuid ne "--") && ($network_interface_bridge_uuid ne $old_network_interface_bridge_uuid)) or ($network_interface_bridge_uuid ne $old_network_interface_bridge_uuid) or
(($network_interface_name ne "--") && ($network_interface_name ne $old_network_interface_name)) or ($network_interface_name ne $old_network_interface_name) or
(($network_interface_duplex ne "--") && ($network_interface_duplex ne $old_network_interface_duplex)) or ($network_interface_duplex ne $old_network_interface_duplex) or
(($network_interface_link_state ne "--") && ($network_interface_link_state ne $old_network_interface_link_state)) or ($network_interface_link_state ne $old_network_interface_link_state) or
(($network_interface_operational ne "--") && ($network_interface_operational ne $old_network_interface_operational)) or ($network_interface_operational ne $old_network_interface_operational) or
(($network_interface_mac_address ne "--") && ($network_interface_mac_address ne $old_network_interface_mac_address)) or ($network_interface_mac_address ne $old_network_interface_mac_address) or
(($network_interface_medium ne "--") && ($network_interface_medium ne $old_network_interface_medium)) or ($network_interface_medium ne $old_network_interface_medium) or
(($network_interface_mtu ne "--") && ($network_interface_mtu ne $old_network_interface_mtu)) or ($network_interface_mtu ne $old_network_interface_mtu) or
(($network_interface_speed ne "--") && ($network_interface_speed ne $old_network_interface_speed)) or ($network_interface_speed ne $old_network_interface_speed) or
($network_interface_host_uuid ne $old_network_interface_host_uuid)) ($network_interface_host_uuid ne $old_network_interface_host_uuid))
{ {
# UPDATE any rows passed to us. # UPDATE any rows passed to us.
my $query = " my $query = "
@ -2984,98 +3002,28 @@ UPDATE
network_interfaces network_interfaces
SET SET
network_interface_host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_host_uuid).", network_interface_host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_host_uuid).",
"; network_interface_bond_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_bond_uuid).",
if ($network_interface_bond_uuid ne "--") network_interface_bridge_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_bridge_uuid).",
{ network_interface_name = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_name).",
$query .= " network_interface_bond_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_bond_uuid).", \n"; network_interface_duplex = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_duplex).",
} network_interface_link_state = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_link_state).",
if ($network_interface_bridge_uuid ne "--") network_interface_operational = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_operational).",
{ network_interface_mac_address = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_mac_address).",
$query .= " network_interface_bridge_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_bridge_uuid).", \n"; network_interface_medium = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_medium).",
} network_interface_mtu = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_mtu).",
if ($network_interface_name ne "--") network_interface_speed = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_speed).",
{ modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})."
$query .= " network_interface_name = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_name).", \n";
}
if ($network_interface_duplex ne "--")
{
$query .= " network_interface_duplex = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_duplex).", \n";
}
if ($network_interface_link_state ne "--")
{
$query .= " network_interface_link_state = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_link_state).", \n";
}
if ($network_interface_operational ne "--")
{
$query .= " network_interface_operational = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_operational).", \n";
}
if ($network_interface_mac_address ne "--")
{
$query .= " network_interface_mac_address = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_mac_address).", \n";
}
if ($network_interface_medium ne "--")
{
$query .= " network_interface_medium = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_medium).", \n";
}
if ($network_interface_mtu ne "--")
{
$query .= " network_interface_mtu = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_mtu).", \n";
}
if ($network_interface_speed ne "--")
{
$query .= " network_interface_speed = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_speed).", \n";
}
$query .= " modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})."
WHERE WHERE
network_interface_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_uuid)." network_interface_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($network_interface_uuid)."
;"; ;";
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, uuid => $uuid, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__}); $anvil->Database->write({query => $query, uuid => $uuid, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
} }
else
{
# No change.
}
} }
} }
else else
{ {
# INSERT, but make sure we have enough data first.
if (($network_interface_mac_address eq "--") or (not $network_interface_mac_address))
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_mac_address" }});
return("");
}
if (($network_interface_name eq "--") or (not $network_interface_name))
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_name" }});
return("");
}
# Convert unpassed values to their defaults.
$network_interface_bond_uuid = "" if $network_interface_bond_uuid eq "--";
$network_interface_bridge_uuid = "" if $network_interface_bridge_uuid eq "--";
$network_interface_duplex = "unknown" if $network_interface_duplex eq "--";
$network_interface_link_state = 0 if $network_interface_link_state eq "--";
$network_interface_operational = "unknown" if $network_interface_operational eq "--";
$network_interface_medium = "" if $network_interface_medium eq "--";
$network_interface_speed = 0 if $network_interface_speed eq "--";
$network_interface_mtu = 0 if $network_interface_mtu eq "--";
# Make sure the UUIDs are sane.
if (($network_interface_bond_uuid ne "") && (not $anvil->Validate->is_uuid({uuid => $network_interface_bond_uuid})))
{
# Bad UUID.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0130", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_name", uuid => $network_interface_bond_uuid }});
return("");
}
if (($network_interface_bridge_uuid ne "") && (not $anvil->Validate->is_uuid({uuid => $network_interface_bridge_uuid})))
{
# Bad UUID.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0130", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_name", uuid => $network_interface_bridge_uuid }});
return("");
}
# And INSERT # And INSERT
$network_interface_uuid = $anvil->Get->uuid; $network_interface_uuid = $anvil->Get->uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { network_interface_uuid => $network_interface_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { network_interface_uuid => $network_interface_uuid }});
@ -3113,6 +3061,7 @@ INSERT INTO
".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})." ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})."
); );
"; ";
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, uuid => $uuid, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__}); $anvil->Database->write({query => $query, uuid => $uuid, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
} }

@ -300,6 +300,7 @@ sub report_network
if ($type eq "interface") if ($type eq "interface")
{ {
my $network_interface_uuid = $anvil->Database->insert_or_update_network_interfaces({ my $network_interface_uuid = $anvil->Database->insert_or_update_network_interfaces({
debug => 2,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
network_interface_name => $interface, network_interface_name => $interface,
@ -494,17 +495,17 @@ ORDER BY
my $order = 1; my $order = 1;
foreach my $row (@{$results}) foreach my $row (@{$results})
{ {
my $network_interface_uuid = $row->[0]; my $network_interface_uuid = $row->[0];
my $network_interface_mac_address = $row->[1]; my $network_interface_mac_address = $row->[1];
my $network_interface_name = $row->[2]; my $network_interface_name = $row->[2];
my $network_interface_speed = $row->[3]; my $network_interface_speed = $row->[3];
my $network_interface_mtu = $row->[4]; my $network_interface_mtu = $row->[4];
my $network_interface_link_state = $row->[5]; my $network_interface_link_state = $row->[5];
my $network_interface_operational = $row->[6]; my $network_interface_operational = $row->[6];
my $network_interface_duplex = $row->[7]; my $network_interface_duplex = $row->[7];
my $network_interface_medium = $row->[8]; my $network_interface_medium = $row->[8];
my $network_interface_bond_uuid = $row->[9]; my $network_interface_bond_uuid = defined $row->[9] ? $row->[9] : 'NULL';
my $network_interface_bridge_uuid = $row->[10]; my $network_interface_bridge_uuid = $row->[10];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
network_interface_mac_address => $network_interface_mac_address, network_interface_mac_address => $network_interface_mac_address,
network_interface_name => $network_interface_name, network_interface_name => $network_interface_name,
@ -521,13 +522,13 @@ ORDER BY
$order++; $order++;
} }
die; die;
# Write out the XML file and JSON file. # Write out the XML file and JSON file.
my $network_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; my $network_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$network_xml .= "<network>\n"; $network_xml .= "<network>\n";
my $network_json = "{\"networks\":[\n"; my $network_json = "{\"networks\":[\n";
my $query = " $query = "
SELECT SELECT
network_interface_mac_address, network_interface_mac_address,
network_interface_name, network_interface_name,
@ -547,24 +548,24 @@ ORDER BY
modified_date DESC modified_date DESC
;"; ;";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }}); $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__}); $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results, results => $results,
count => $count, count => $count,
}}); }});
foreach my $row (@{$results}) foreach my $row (@{$results})
{ {
my $network_interface_mac_address = $row->[0]; my $network_interface_mac_address = $row->[0];
my $network_interface_name = $row->[1]; my $network_interface_name = $row->[1];
my $network_interface_speed = $row->[2]; my $network_interface_speed = $row->[2];
my $network_interface_mtu = $row->[3]; my $network_interface_mtu = $row->[3];
my $network_interface_link_state = $row->[4]; my $network_interface_link_state = $row->[4];
my $network_interface_operational = $row->[5]; my $network_interface_operational = $row->[5];
my $network_interface_duplex = $row->[6]; my $network_interface_duplex = $row->[6];
my $network_interface_medium = $row->[7]; my $network_interface_medium = $row->[7];
my $network_interface_bond_uuid = $row->[8]; my $network_interface_bond_uuid = defined $row->[8] ? $row->[8] : 'NULL';
my $network_interface_bridge_uuid = $row->[9]; my $network_interface_bridge_uuid = $row->[9];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
network_interface_mac_address => $network_interface_mac_address, network_interface_mac_address => $network_interface_mac_address,
network_interface_name => $network_interface_name, network_interface_name => $network_interface_name,

@ -23,15 +23,6 @@
-- each that you plan to link, still use a '*_host_uuid' column (if the data is host-specific). This is -- each that you plan to link, still use a '*_host_uuid' column (if the data is host-specific). This is
-- needed by the resync method. -- needed by the resync method.
-- COLUMN TYPE NOTE!
--
-- To minimize the risk of coding errors translating NULL (versus "") or boolean (1 vs TRUE) in the code and
-- agents, it is recommended to use only 'text' and '[big]int' column types, and that all columns have the
-- 'NOT NULL' constraint. This is a recommendation, not a hard requirement. Remember, reliability comes from
-- simplicity and consistency!
--
-- COLUMN TYPE NOTE!
SET client_encoding = 'UTF8'; SET client_encoding = 'UTF8';
-- This doesn't work before 9.3 - CREATE SCHEMA IF NOT EXISTS history; -- This doesn't work before 9.3 - CREATE SCHEMA IF NOT EXISTS history;
@ -455,7 +446,7 @@ CREATE TABLE network_interfaces (
network_interface_operational text not null, -- This is 'up', 'down' or 'unknown' network_interface_operational text not null, -- This is 'up', 'down' or 'unknown'
network_interface_duplex text not null, -- This is 'full', 'half' or 'unknown' network_interface_duplex text not null, -- This is 'full', 'half' or 'unknown'
network_interface_medium text not null, -- This is 'tp' (twisted pair), 'fiber' or whatever they invent in the future. network_interface_medium text not null, -- This is 'tp' (twisted pair), 'fiber' or whatever they invent in the future.
network_interface_bond_uuid uuid not null, -- If this iface is in a bond, this will contain the 'bonds -> bond_uuid' that it is slaved to. 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 not null, -- If this iface is attached to a bridge, this will contain the 'bridgess -> bridge_uuid' that it is connected to. network_interface_bridge_uuid uuid not null, -- 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 modified_date timestamp with time zone not null
); );
@ -677,7 +668,7 @@ CREATE TABLE ip_addresses (
ip_address_address text not null, -- The actual IP address ip_address_address text not null, -- The actual IP address
ip_address_subnet_mask text not null, -- The subnet mask (in dotted decimal format) ip_address_subnet_mask text not null, -- The subnet mask (in dotted decimal format)
ip_address_gateway text not null, -- If set, this is the gateway IP for this subnet ip_address_gateway text not null, -- If set, this is the gateway IP for this subnet
ip_address_default_gateway integer not null, default 0, -- If true, the gateway will be the default for the host. ip_address_default_gateway integer not null default 0, -- If true, the gateway will be the default for the host.
ip_address_dns text not null, -- If set, this is a comma-separated list of DNS IPs to use (in the order given) ip_address_dns text not null, -- If set, this is a comma-separated list of DNS IPs to use (in the order given)
modified_date timestamp with time zone not null, modified_date timestamp with time zone not null,

Loading…
Cancel
Save