* Updated the SQL schema to convert all 'boolean' to 'integer' (using 0 for false). Also made all columns NOT NULL, given they should all always have an empty string. The logic behind this was to standardize the code and avoid bugs.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent 39c06f364f
commit 870a2eb803
  1. 2
      Anvil/Tools.pm
  2. 288
      Anvil/Tools/Database.pm
  3. 14
      cgi-bin/home
  4. 4
      tools/anvil-configure-striker
  5. 181
      tools/anvil-update-states
  6. 93
      tools/anvil.sql

@ -704,10 +704,12 @@ sub _set_defaults
"bridges",
"hosts",
"host_variable",
"ip_addresses",
"jobs",
"network_interfaces",
"states",
"updated",
"users",
"variables",
],
local_lock_active => 0,

@ -1449,8 +1449,8 @@ sub insert_or_update_bridges
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_name = defined $parameter->{bridge_name} ? $parameter->{bridge_name} : "";
my $bridge_id = $parameter->{bridge_id} ? $parameter->{bridge_id} : "NULL";
my $bridge_stp_enabled = $parameter->{bridge_stp_enabled} ? $parameter->{bridge_stp_enabled} : "NULL";
my $bridge_id = $parameter->{bridge_id} ? $parameter->{bridge_id} : "";
my $bridge_stp_enabled = $parameter->{bridge_stp_enabled} ? $parameter->{bridge_stp_enabled} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
file => $file,
@ -1546,7 +1546,6 @@ INSERT INTO
".$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->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -1574,10 +1573,10 @@ WHERE
}});
foreach my $row (@{$results})
{
my $old_bridge_host_uuid = $row->[0];
my $old_bridge_name = $row->[1];
my $old_bridge_id = defined $row->[2] ? $row->[2] : "NULL";
my $old_bridge_stp_enabled = defined $row->[3] ? $row->[3] : "NULL";
my $old_bridge_host_uuid = $row->[0];
my $old_bridge_name = $row->[1];
my $old_bridge_id = $row->[2];
my $old_bridge_stp_enabled = $row->[3];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_bridge_host_uuid => $old_bridge_host_uuid,
old_bridge_name => $old_bridge_name,
@ -1604,7 +1603,6 @@ SET
WHERE
bridge_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($bridge_uuid)."
";
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -1674,10 +1672,6 @@ This is the interface currently being used by the bond.
This is the current / active MAC address in use by the bond interface.
=head2 bond_mii_status (optional)
This is the current status of the interface (C<< up >> or C<< down >>).
=head2 bond_mii_polling_interval (optional)
This is how often, in milliseconds, that the link (mii) status is manually checked.
@ -1704,16 +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_name = defined $parameter->{bond_name} ? $parameter->{bond_name} : "";
my $bond_mode = defined $parameter->{bond_mode} ? $parameter->{bond_mode} : "";
my $bond_mtu = $parameter->{bond_mtu} ? $parameter->{bond_mtu} : "NULL";
my $bond_primary_slave = $parameter->{bond_primary_slave} ? $parameter->{bond_primary_slave} : "NULL";
my $bond_primary_reselect = $parameter->{bond_primary_reselect} ? $parameter->{bond_primary_reselect} : "NULL";
my $bond_active_slave = $parameter->{bond_active_slave} ? $parameter->{bond_active_slave} : "NULL";
my $bond_mii_status = $parameter->{bond_mii_status} ? $parameter->{bond_mii_status} : "NULL";
my $bond_mii_polling_interval = $parameter->{bond_mii_polling_interval} ? $parameter->{bond_mii_polling_interval} : "NULL";
my $bond_up_delay = $parameter->{bond_up_delay} ? $parameter->{bond_up_delay} : "NULL";
my $bond_down_delay = $parameter->{bond_down_delay} ? $parameter->{bond_down_delay} : "NULL";
my $bond_mac_address = $parameter->{bond_mac_address} ? $parameter->{bond_mac_address} : "NULL";
my $bond_operational = $parameter->{bond_operational} ? $parameter->{bond_operational} : "NULL";
my $bond_mtu = $parameter->{bond_mtu} ? $parameter->{bond_mtu} : "";
my $bond_primary_slave = $parameter->{bond_primary_slave} ? $parameter->{bond_primary_slave} : "";
my $bond_primary_reselect = $parameter->{bond_primary_reselect} ? $parameter->{bond_primary_reselect} : "";
my $bond_active_slave = $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_up_delay = $parameter->{bond_up_delay} ? $parameter->{bond_up_delay} : "";
my $bond_down_delay = $parameter->{bond_down_delay} ? $parameter->{bond_down_delay} : "";
my $bond_mac_address = $parameter->{bond_mac_address} ? $parameter->{bond_mac_address} : "";
my $bond_operational = $parameter->{bond_operational} ? $parameter->{bond_operational} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
file => $file,
@ -1726,7 +1719,6 @@ sub insert_or_update_bonds
bond_primary_slave => $bond_primary_slave,
bond_primary_reselect => $bond_primary_reselect,
bond_active_slave => $bond_active_slave,
bond_mii_status => $bond_mii_status,
bond_mii_polling_interval => $bond_mii_polling_interval,
bond_up_delay => $bond_up_delay,
bond_down_delay => $bond_down_delay,
@ -1817,7 +1809,6 @@ INSERT INTO
bond_primary_slave,
bond_primary_reselect,
bond_active_slave,
bond_mii_status,
bond_mii_polling_interval,
bond_up_delay,
bond_down_delay,
@ -1833,7 +1824,6 @@ INSERT INTO
".$anvil->data->{sys}{use_db_fh}->quote($bond_primary_slave).",
".$anvil->data->{sys}{use_db_fh}->quote($bond_primary_reselect).",
".$anvil->data->{sys}{use_db_fh}->quote($bond_active_slave).",
".$anvil->data->{sys}{use_db_fh}->quote($bond_mii_status).",
".$anvil->data->{sys}{use_db_fh}->quote($bond_mii_polling_interval).",
".$anvil->data->{sys}{use_db_fh}->quote($bond_up_delay).",
".$anvil->data->{sys}{use_db_fh}->quote($bond_down_delay).",
@ -1842,7 +1832,6 @@ INSERT INTO
".$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->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -1858,7 +1847,6 @@ SELECT
bond_primary_slave,
bond_primary_reselect,
bond_active_slave,
bond_mii_status,
bond_mii_polling_interval,
bond_up_delay,
bond_down_delay,
@ -1879,19 +1867,18 @@ WHERE
}});
foreach my $row (@{$results})
{
my $old_bond_host_uuid = $row->[0];
my $old_bond_name = $row->[1];
my $old_bond_mode = $row->[2];
my $old_bond_mtu = defined $row->[3] ? $row->[3] : "NULL";
my $old_bond_primary_slave = defined $row->[4] ? $row->[4] : "NULL";
my $old_bond_primary_reselect = defined $row->[5] ? $row->[5] : "NULL";
my $old_bond_active_slave = defined $row->[6] ? $row->[6] : "NULL";
my $old_bond_mii_status = defined $row->[7] ? $row->[7] : "NULL";
my $old_bond_mii_polling_interval = defined $row->[8] ? $row->[8] : "NULL";
my $old_bond_up_delay = defined $row->[9] ? $row->[9] : "NULL";
my $old_bond_down_delay = defined $row->[10] ? $row->[10] : "NULL";
my $old_bond_mac_address = defined $row->[11] ? $row->[11] : "NULL";
my $old_bond_operational = defined $row->[12] ? $row->[12] : "NULL";
my $old_bond_host_uuid = $row->[0];
my $old_bond_name = $row->[1];
my $old_bond_mode = $row->[2];
my $old_bond_mtu = $row->[3];
my $old_bond_primary_slave = $row->[4];
my $old_bond_primary_reselect = $row->[5];
my $old_bond_active_slave = $row->[6];
my $old_bond_mii_polling_interval = $row->[8];
my $old_bond_up_delay = $row->[9];
my $old_bond_down_delay = $row->[10];
my $old_bond_mac_address = $row->[11];
my $old_bond_operational = $row->[12];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_bond_host_uuid => $old_bond_host_uuid,
old_bond_name => $old_bond_name,
@ -1900,7 +1887,6 @@ WHERE
old_bond_primary_slave => $old_bond_primary_slave,
old_bond_primary_reselect => $old_bond_primary_reselect,
old_bond_active_slave => $old_bond_active_slave,
old_bond_mii_status => $old_bond_mii_status,
old_bond_mii_polling_interval => $old_bond_mii_polling_interval,
old_bond_up_delay => $old_bond_up_delay,
old_bond_down_delay => $old_bond_down_delay,
@ -1916,7 +1902,6 @@ WHERE
($old_bond_primary_slave ne $bond_primary_slave) or
($old_bond_primary_reselect ne $bond_primary_reselect) or
($old_bond_active_slave ne $bond_active_slave) or
($old_bond_mii_status ne $bond_mii_status) or
($old_bond_mii_polling_interval ne $bond_mii_polling_interval) or
($old_bond_up_delay ne $bond_up_delay) or
($old_bond_down_delay ne $bond_down_delay) or
@ -1935,7 +1920,6 @@ SET
bond_primary_slave = ".$anvil->data->{sys}{use_db_fh}->quote($bond_primary_slave).",
bond_primary_reselect = ".$anvil->data->{sys}{use_db_fh}->quote($bond_primary_reselect).",
bond_active_slave = ".$anvil->data->{sys}{use_db_fh}->quote($bond_active_slave).",
bond_mii_status = ".$anvil->data->{sys}{use_db_fh}->quote($bond_mii_status).",
bond_mii_polling_interval = ".$anvil->data->{sys}{use_db_fh}->quote($bond_mii_polling_interval).",
bond_up_delay = ".$anvil->data->{sys}{use_db_fh}->quote($bond_up_delay).",
bond_down_delay = ".$anvil->data->{sys}{use_db_fh}->quote($bond_down_delay).",
@ -1945,7 +1929,6 @@ SET
WHERE
bond_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($bond_uuid)."
";
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -2071,7 +2054,6 @@ INSERT INTO
".$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->Database->write({query => $query, uuid => $uuid, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -2088,7 +2070,6 @@ SET
WHERE
host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($host_uuid)."
;";
$query =~ s/'NULL'/NULL/g;
$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__});
}
@ -2171,9 +2152,9 @@ sub insert_or_update_ip_addresses
my $ip_address_on_uuid = defined $parameter->{ip_address_on_uuid} ? $parameter->{ip_address_on_uuid} : "";
my $ip_address_address = defined $parameter->{ip_address_address} ? $parameter->{ip_address_address} : "";
my $ip_address_subnet_mask = defined $parameter->{ip_address_subnet_mask} ? $parameter->{ip_address_subnet_mask} : "";
my $ip_address_gateway = $parameter->{ip_address_gateway} ? $parameter->{ip_address_gateway} : "NULL";
my $ip_address_gateway = defined $parameter->{ip_address_gateway} ? $parameter->{ip_address_gateway} : "";
my $ip_address_default_gateway = defined $parameter->{ip_address_default_gateway} ? $parameter->{ip_address_default_gateway} : 0;
my $ip_address_dns = $parameter->{ip_address_dns} ? $parameter->{ip_address_dns} : "NULL";
my $ip_address_dns = defined $parameter->{ip_address_dns} ? $parameter->{ip_address_dns} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
file => $file,
@ -2242,10 +2223,6 @@ AND
}
}
# default gateway is a boolean, so translate it.
my $say_ip_address_default_gateway = (($ip_address_default_gateway eq "1") or ($ip_address_default_gateway =~ /true/i)) ? "TRUE" : "FALSE";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { say_ip_address_default_gateway => $say_ip_address_default_gateway }});
# If I still don't have an ip_address_uuid, we're INSERT'ing .
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip_address_uuid => $ip_address_uuid }});
if (not $ip_address_uuid)
@ -2298,12 +2275,11 @@ INSERT INTO
".$anvil->data->{sys}{use_db_fh}->quote($ip_address_address).",
".$anvil->data->{sys}{use_db_fh}->quote($ip_address_subnet_mask).",
".$anvil->data->{sys}{use_db_fh}->quote($ip_address_gateway).",
$say_ip_address_default_gateway,
".$anvil->data->{sys}{use_db_fh}->quote($ip_address_default_gateway).",
".$anvil->data->{sys}{use_db_fh}->quote($ip_address_dns).",
".$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->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -2335,14 +2311,14 @@ WHERE
}});
foreach my $row (@{$results})
{
my $old_ip_address_host_uuid = $row->[0];
my $old_ip_address_on_type = $row->[1];
my $old_ip_address_on_uuid = $row->[2];
my $old_ip_address_address = $row->[3];
my $old_ip_address_subnet_mask = $row->[4];
my $old_ip_address_gateway = defined $row->[5] ? $row->[5] : "NULL";
my $old_ip_address_default_gateway = $row->[6];
my $old_ip_address_dns = defined $row->[7] ? $row->[7] : "NULL";
my $old_ip_address_host_uuid = $row->[0];
my $old_ip_address_on_type = $row->[1];
my $old_ip_address_on_uuid = $row->[2];
my $old_ip_address_address = $row->[3];
my $old_ip_address_subnet_mask = $row->[4];
my $old_ip_address_gateway = $row->[5];
my $old_ip_address_default_gateway = $row->[6];
my $old_ip_address_dns = $row->[7];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_ip_address_host_uuid => $old_ip_address_host_uuid,
old_ip_address_on_type => $old_ip_address_on_type,
@ -2354,18 +2330,15 @@ WHERE
old_ip_address_dns => $old_ip_address_dns,
}});
my $say_old_ip_address_default_gateway = (($old_ip_address_default_gateway eq "1") or ($old_ip_address_default_gateway =~ /true/i)) ? "TRUE" : "FALSE";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { say_old_ip_address_default_gateway => $say_old_ip_address_default_gateway }});
# Anything change?
if (($old_ip_address_host_uuid ne $ip_address_host_uuid) or
($old_ip_address_on_type ne $ip_address_on_type) or
($old_ip_address_on_uuid ne $ip_address_on_uuid) or
($old_ip_address_address ne $ip_address_address) or
($old_ip_address_subnet_mask ne $ip_address_subnet_mask) or
($old_ip_address_gateway ne $ip_address_gateway) or
($say_old_ip_address_default_gateway ne $say_ip_address_default_gateway) or
($old_ip_address_dns ne $ip_address_dns))
if (($old_ip_address_host_uuid ne $ip_address_host_uuid) or
($old_ip_address_on_type ne $ip_address_on_type) or
($old_ip_address_on_uuid ne $ip_address_on_uuid) or
($old_ip_address_address ne $ip_address_address) or
($old_ip_address_subnet_mask ne $ip_address_subnet_mask) or
($old_ip_address_gateway ne $ip_address_gateway) or
($old_ip_address_default_gateway ne $ip_address_default_gateway) or
($old_ip_address_dns ne $ip_address_dns))
{
# Something changed, save.
my $query = "
@ -2378,13 +2351,12 @@ SET
ip_address_address = ".$anvil->data->{sys}{use_db_fh}->quote($ip_address_address).",
ip_address_subnet_mask = ".$anvil->data->{sys}{use_db_fh}->quote($ip_address_subnet_mask).",
ip_address_gateway = ".$anvil->data->{sys}{use_db_fh}->quote($ip_address_gateway).",
ip_address_default_gateway = $say_ip_address_default_gateway,
ip_address_default_gateway = ".$anvil->data->{sys}{use_db_fh}->quote($ip_address_default_gateway).",
ip_address_dns = ".$anvil->data->{sys}{use_db_fh}->quote($ip_address_dns).",
modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})."
WHERE
ip_address_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($ip_address_uuid)."
";
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -2669,7 +2641,6 @@ INSERT INTO
".$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->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -2704,17 +2675,17 @@ WHERE
}});
foreach my $row (@{$results})
{
my $old_job_host_uuid = $row->[0];
my $old_job_command = $row->[1];
my $old_job_data = defined $row->[2] ? $row->[2] : "";
my $old_job_picked_up_by = $row->[3];
my $old_job_picked_up_at = $row->[4];
my $old_job_updated = $row->[5];
my $old_job_name = $row->[6];
my $old_job_progress = $row->[7];
my $old_job_title = $row->[8];
my $old_job_description = $row->[9];
my $old_job_status = $row->[10];
my $old_job_host_uuid = $row->[0];
my $old_job_command = $row->[1];
my $old_job_data = $row->[2];
my $old_job_picked_up_by = $row->[3];
my $old_job_picked_up_at = $row->[4];
my $old_job_updated = $row->[5];
my $old_job_name = $row->[6];
my $old_job_progress = $row->[7];
my $old_job_title = $row->[8];
my $old_job_description = $row->[9];
my $old_job_status = $row->[10];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_job_host_uuid => $old_job_host_uuid,
old_job_command => $old_job_command,
@ -2757,7 +2728,6 @@ WHERE
job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)."
";
}
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -2796,7 +2766,6 @@ SET
WHERE
job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)."
";
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -2968,17 +2937,17 @@ WHERE
}});
foreach my $row (@{$results})
{
my $old_network_interface_host_uuid = $row->[0];
my $old_network_interface_mac_address = $row->[1];
my $old_network_interface_name = $row->[2];
my $old_network_interface_speed = $row->[3];
my $old_network_interface_mtu = defined $row->[4] ? $row->[4] : "";
my $old_network_interface_link_state = $row->[5];
my $old_network_interface_operational = $row->[6];
my $old_network_interface_duplex = $row->[7];
my $old_network_interface_medium = defined $row->[8] ? $row->[8] : "";
my $old_network_interface_bond_uuid = defined $row->[9] ? $row->[9] : "";
my $old_network_interface_bridge_uuid = defined $row->[10] ? $row->[10] : "";
my $old_network_interface_host_uuid = $row->[0];
my $old_network_interface_mac_address = $row->[1];
my $old_network_interface_name = $row->[2];
my $old_network_interface_speed = $row->[3];
my $old_network_interface_mtu = $row->[4];
my $old_network_interface_link_state = $row->[5];
my $old_network_interface_operational = $row->[6];
my $old_network_interface_duplex = $row->[7];
my $old_network_interface_medium = $row->[8];
my $old_network_interface_bond_uuid = $row->[9];
my $old_network_interface_bridge_uuid = $row->[10];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_network_interface_host_uuid => $old_network_interface_host_uuid,
old_network_interface_mac_address => $old_network_interface_mac_address,
@ -3060,7 +3029,6 @@ SET
WHERE
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->Database->write({query => $query, uuid => $uuid, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -3085,8 +3053,8 @@ WHERE
}
# Convert unpassed values to their defaults.
$network_interface_bond_uuid = "NULL" if $network_interface_bond_uuid eq "--";
$network_interface_bridge_uuid = "NULL" if $network_interface_bridge_uuid eq "--";
$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 "--";
@ -3095,13 +3063,13 @@ WHERE
$network_interface_mtu = 0 if $network_interface_mtu eq "--";
# Make sure the UUIDs are sane.
if (($network_interface_bond_uuid ne "NULL") && (not $anvil->Validate->is_uuid({uuid => $network_interface_bond_uuid})))
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 "NULL") && (not $anvil->Validate->is_uuid({uuid => $network_interface_bridge_uuid})))
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 }});
@ -3145,7 +3113,6 @@ INSERT INTO
".$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->Database->write({query => $query, uuid => $uuid, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -3206,7 +3173,7 @@ sub insert_or_update_states
my $state_uuid = defined $parameter->{state_uuid} ? $parameter->{state_uuid} : "";
my $state_name = defined $parameter->{state_name} ? $parameter->{state_name} : "";
my $state_host_uuid = defined $parameter->{state_host_uuid} ? $parameter->{state_host_uuid} : $anvil->data->{sys}{host_uuid};
my $state_note = defined $parameter->{state_note} ? $parameter->{state_note} : "NULL";
my $state_note = defined $parameter->{state_note} ? $parameter->{state_note} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
file => $file,
@ -3303,7 +3270,6 @@ INSERT INTO
".$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->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -3330,9 +3296,9 @@ WHERE
}});
foreach my $row (@{$results})
{
my $old_state_name = $row->[0];
my $old_state_host_uuid = $row->[1];
my $old_state_note = defined $row->[2] ? $row->[2] : "NULL";
my $old_state_name = $row->[0];
my $old_state_host_uuid = $row->[1];
my $old_state_note = $row->[2];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_state_name => $old_state_name,
old_state_host_uuid => $old_state_host_uuid,
@ -3356,7 +3322,6 @@ SET
WHERE
state_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($state_uuid)."
";
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -3542,16 +3507,6 @@ WHERE
}
}
# Switch the values to be boolean friendly for the database.
my $say_user_is_admin = (($user_is_admin eq "1") or ($user_is_admin =~ /true/i)) ? "TRUE" : "FALSE";
my $say_user_is_experienced = (($user_is_experienced eq "1") or ($user_is_experienced =~ /true/i)) ? "TRUE" : "FALSE";
my $say_user_is_trusted = (($user_is_trusted eq "1") or ($user_is_trusted =~ /true/i)) ? "TRUE" : "FALSE";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
say_user_is_admin => $say_user_is_admin,
say_user_is_experienced => $say_user_is_experienced,
say_user_is_trusted => $say_user_is_trusted,
}});
# If I still don't have an user_uuid, we're INSERT'ing .
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { user_uuid => $user_uuid }});
if (not $user_uuid)
@ -3603,13 +3558,12 @@ INSERT INTO
".$anvil->data->{sys}{use_db_fh}->quote($user_algorithm).",
".$anvil->data->{sys}{use_db_fh}->quote($user_hash_count).",
".$anvil->data->{sys}{use_db_fh}->quote($user_language).",
".$say_user_is_admin.",
".$say_user_is_experienced.",
".$say_user_is_trusted.",
".$anvil->data->{sys}{use_db_fh}->quote($user_is_admin).",
".$anvil->data->{sys}{use_db_fh}->quote($user_is_experienced).",
".$anvil->data->{sys}{use_db_fh}->quote($user_is_trusted).",
".$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->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -3663,27 +3617,17 @@ WHERE
old_user_is_trusted => $old_user_is_trusted,
}});
# Switch the values to be boolean friendly for the database.
my $say_old_user_is_admin = (($old_user_is_admin eq "1") or ($old_user_is_admin =~ /true/i)) ? "TRUE" : "FALSE";
my $say_old_user_is_experienced = (($old_user_is_experienced eq "1") or ($old_user_is_experienced =~ /true/i)) ? "TRUE" : "FALSE";
my $say_old_user_is_trusted = (($old_user_is_trusted eq "1") or ($old_user_is_trusted =~ /true/i)) ? "TRUE" : "FALSE";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
say_old_user_is_admin => $say_old_user_is_admin,
say_old_user_is_experienced => $say_old_user_is_experienced,
say_old_user_is_trusted => $say_old_user_is_trusted,
}});
# Anything change?
if (($old_user_name ne $user_name) or
($old_user_name ne $user_name) or
($old_user_password_hash ne $user_password_hash) or
($old_user_salt ne $user_salt) or
($old_user_algorithm ne $user_algorithm) or
($old_user_hash_count ne $user_hash_count) or
($old_user_language ne $user_language) or
($say_old_user_is_admin ne $say_user_is_admin) or
($say_old_user_is_experienced ne $say_user_is_experienced) or
($say_old_user_is_trusted ne $say_user_is_trusted))
if (($old_user_name ne $user_name) or
($old_user_name ne $user_name) or
($old_user_password_hash ne $user_password_hash) or
($old_user_salt ne $user_salt) or
($old_user_algorithm ne $user_algorithm) or
($old_user_hash_count ne $user_hash_count) or
($old_user_language ne $user_language) or
($old_user_is_admin ne $user_is_admin) or
($old_user_is_experienced ne $user_is_experienced) or
($old_user_is_trusted ne $user_is_trusted))
{
# Something changed, save.
my $query = "
@ -3696,14 +3640,13 @@ SET
user_algorithm = ".$anvil->data->{sys}{use_db_fh}->quote($user_algorithm).",
user_hash_count = ".$anvil->data->{sys}{use_db_fh}->quote($user_hash_count).",
user_language = ".$anvil->data->{sys}{use_db_fh}->quote($user_language).",
user_is_admin = ".$say_user_is_admin.",
user_is_experienced = ".$say_user_is_experienced.",
user_is_trusted = ".$say_user_is_trusted.",
user_is_admin = ".$anvil->data->{sys}{use_db_fh}->quote($user_is_admin).",
user_is_experienced = ".$anvil->data->{sys}{use_db_fh}->quote($user_is_experienced).",
user_is_trusted = ".$anvil->data->{sys}{use_db_fh}->quote($user_is_trusted).",
modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})."
WHERE
user_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($user_uuid)."
";
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
}
@ -3718,7 +3661,7 @@ WHERE
This updates (or inserts) a record in the 'variables' table. The C<< state_uuid >> referencing the database row will be returned.
Unlike the other methods of this type, this method can be told to update the 'variable_value' only. This is so because the section, description and default columns rarely ever change. If this is set and the variable name is new, an INSERT will be done the same as if it weren't set, with the unset columns set to NULL.
Unlike the other methods of this type, this method can be told to update the 'variable_value' only. This is so because the section, description and default columns rarely ever change. If this is set and the variable name is new, an INSERT will be done the same as if it weren't set, with the unset columns set to an empty string.
If there is an error, C<< !!error!! >> is returned.
@ -3788,12 +3731,12 @@ sub insert_or_update_variables
my $line = defined $parameter->{line} ? $parameter->{line} : "";
my $variable_uuid = defined $parameter->{variable_uuid} ? $parameter->{variable_uuid} : "";
my $variable_name = defined $parameter->{variable_name} ? $parameter->{variable_name} : "";
my $variable_value = defined $parameter->{variable_value} ? $parameter->{variable_value} : "NULL";
my $variable_default = defined $parameter->{variable_default} ? $parameter->{variable_default} : "NULL";
my $variable_description = defined $parameter->{variable_description} ? $parameter->{variable_description} : "NULL";
my $variable_section = defined $parameter->{variable_section} ? $parameter->{variable_section} : "NULL";
my $variable_source_uuid = defined $parameter->{variable_source_uuid} ? $parameter->{variable_source_uuid} : "NULL";
my $variable_source_table = defined $parameter->{variable_source_table} ? $parameter->{variable_source_table} : "NULL";
my $variable_value = defined $parameter->{variable_value} ? $parameter->{variable_value} : "";
my $variable_default = defined $parameter->{variable_default} ? $parameter->{variable_default} : "";
my $variable_description = defined $parameter->{variable_description} ? $parameter->{variable_description} : "";
my $variable_section = defined $parameter->{variable_section} ? $parameter->{variable_section} : "";
my $variable_source_uuid = defined $parameter->{variable_source_uuid} ? $parameter->{variable_source_uuid} : "";
my $variable_source_table = defined $parameter->{variable_source_table} ? $parameter->{variable_source_table} : "";
my $update_value_only = defined $parameter->{update_value_only} ? $parameter->{update_value_only} : 1;
my $log_level = defined $parameter->{log_level} ? $parameter->{log_level} : 3; # Undocumented for now.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
@ -3847,7 +3790,7 @@ FROM
variables
WHERE
variable_name = ".$anvil->data->{sys}{use_db_fh}->quote($variable_name);
if (($variable_source_uuid ne "NULL") && ($variable_source_table ne "NULL"))
if (($variable_source_uuid ne "") && ($variable_source_table ne ""))
{
$query .= "
AND
@ -3903,7 +3846,6 @@ INSERT INTO
".$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 => $log_level, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
@ -3920,7 +3862,7 @@ FROM
variables
WHERE
variable_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($variable_uuid);
if (($variable_source_uuid ne "NULL") && ($variable_source_table ne "NULL"))
if (($variable_source_uuid ne "") && ($variable_source_table ne ""))
{
$query .= "
AND
@ -3940,7 +3882,7 @@ AND
}});
foreach my $row (@{$results})
{
my $old_variable_value = defined $row->[0] ? $row->[0] : "";
my $old_variable_value = $row->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { old_variable_value => $old_variable_value }});
# Anything change?
@ -3955,7 +3897,7 @@ SET
modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})."
WHERE
variable_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($variable_uuid);
if (($variable_source_uuid ne "NULL") && ($variable_source_table ne "NULL"))
if (($variable_source_uuid ne "") && ($variable_source_table ne ""))
{
$query .= "
AND
@ -3965,7 +3907,6 @@ AND
";
}
$query .= ";";
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
@ -3998,10 +3939,10 @@ WHERE
foreach my $row (@{$results})
{
my $old_variable_name = $row->[0];
my $old_variable_value = $row->[1] ? $row->[1] : "NULL";
my $old_variable_default = $row->[2] ? $row->[2] : "NULL";
my $old_variable_description = $row->[3] ? $row->[3] : "NULL";
my $old_variable_section = $row->[4] ? $row->[4] : "NULL";
my $old_variable_value = $row->[1];
my $old_variable_default = $row->[2];
my $old_variable_description = $row->[3];
my $old_variable_section = $row->[4];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
old_variable_name => $old_variable_name,
old_variable_value => $old_variable_value,
@ -4031,7 +3972,6 @@ SET
WHERE
variable_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($variable_uuid)."
";
$query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
@ -4538,8 +4478,8 @@ sub read_variable
my $variable_uuid = $parameter->{variable_uuid} ? $parameter->{variable_uuid} : "";
my $variable_name = $parameter->{variable_name} ? $parameter->{variable_name} : "";
my $variable_source_uuid = $parameter->{variable_source_uuid} ? $parameter->{variable_source_uuid} : "NULL";
my $variable_source_table = $parameter->{variable_source_table} ? $parameter->{variable_source_table} : "NULL";
my $variable_source_uuid = $parameter->{variable_source_uuid} ? $parameter->{variable_source_uuid} : "";
my $variable_source_table = $parameter->{variable_source_table} ? $parameter->{variable_source_table} : "";
my $uuid = $parameter->{uuid} ? $parameter->{uuid} : $anvil->data->{sys}{read_db_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
variable_uuid => $variable_uuid,
@ -4574,7 +4514,7 @@ WHERE ";
{
$query .= "
variable_name = ".$anvil->data->{sys}{use_db_fh}->quote($variable_name);
if (($variable_source_uuid ne "NULL") && ($variable_source_table ne "NULL"))
if (($variable_source_uuid ne "") && ($variable_source_table ne ""))
{
$query .= "
AND
@ -4597,9 +4537,9 @@ AND
}});
foreach my $row (@{$results})
{
$variable_value = defined $row->[0] ? $row->[0] : "";
$variable_uuid = $row->[1];
$modified_date = $row->[2];
$variable_value = $row->[0];
$variable_uuid = $row->[1];
$modified_date = $row->[2];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
variable_value => $variable_value,
variable_uuid => $variable_uuid,

@ -264,8 +264,8 @@ ORDER BY
}});
foreach my $row (@{$results})
{
my $variable_name = $row->[0];
my $variable_value = defined $row->[1] ? $row->[1] : "";
my $variable_name = $row->[0];
my $variable_value = $row->[1];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
variable_name => $variable_name,
variable_value => $variable_value,
@ -273,8 +273,8 @@ ORDER BY
if ($variable_name =~ /form::config_step2::(.*?)::value/)
{
my $variable = $1;
$cgi .= $variable.",";
my $variable = $1;
$cgi .= $variable.",";
$anvil->data->{cgi}{$variable}{value} = $variable_value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::${variable}::value" => $anvil->data->{cgi}{$variable}{value} }});
@ -412,8 +412,8 @@ ORDER BY
}});
foreach my $row (@{$results})
{
my $variable_name = $row->[0];
my $variable_value = defined $row->[1] ? $row->[1] : "";
my $variable_name = $row->[0];
my $variable_value = $row->[1];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
variable_name => $variable_name,
variable_value => $variable_value,
@ -421,7 +421,7 @@ ORDER BY
if ($variable_name =~ /form::config_step2::(.*?)::value/)
{
my $variable = $1;
my $variable = $1;
$anvil->data->{cgi}{$variable}{value} = $variable_value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "cgi::${variable}::value" => $anvil->data->{cgi}{$variable}{value} }});
}

@ -660,8 +660,8 @@ AND
}});
foreach my $row (@{$results})
{
my $this_variable = $row->[0];
my $this_value = defined $row->[1] ? $row->[1] : "";
my $this_variable = $row->[0];
my $this_value = $row->[1];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
this_variable => $this_variable,
this_value => $this_value,

@ -363,8 +363,167 @@ 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 $query = "
SELECT
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_on_type = $row->[0];
my $ip_address_on_uuid = $row->[1];
my $ip_address_address = $row->[2];
my $ip_address_subnet_mask = $row->[3];
my $ip_address_gateway = $row->[4];
my $ip_address_default_gateway = $row->[5];
my $ip_address_dns = $row->[6];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
ip_address_on_type => $ip_address_on_type,
ip_address_on_uuid => $ip_address_on_uuid,
ip_address_address => $ip_address_address,
ip_address_subnet_mask => $ip_address_subnet_mask,
ip_address_gateway => $ip_address_gateway,
ip_address_default_gateway => $ip_address_default_gateway,
ip_address_dns => $ip_address_dns,
}});
}
$query = "
SELECT
bond_uuid,
bond_name,
bond_mode,
bond_mtu,
bond_primary_slave,
bond_primary_reselect,
bond_active_slave,
bond_mii_polling_interval,
bond_up_delay,
bond_down_delay,
bond_mac_address,
bond_operational
FROM
bonds
WHERE
bond_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 $bond_uuid = $row->[0];
my $bond_name = $row->[1];
my $bond_mode = $row->[2];
my $bond_mtu = $row->[3];
my $bond_primary_slave = $row->[4];
my $bond_primary_reselect = $row->[5];
my $bond_active_slave = $row->[6];
my $bond_mii_polling_interval = $row->[7];
my $bond_up_delay = $row->[8];
my $bond_down_delay = $row->[9];
my $bond_mac_address = $row->[10];
my $bond_operational = $row->[11];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
bond_uuid => $bond_uuid,
bond_name => $bond_name,
bond_mode => $bond_mode,
bond_mtu => $bond_mtu,
bond_primary_slave => $bond_primary_slave,
bond_primary_reselect => $bond_primary_reselect,
bond_active_slave => $bond_active_slave,
bond_mii_polling_interval => $bond_mii_polling_interval,
bond_up_delay => $bond_up_delay,
bond_down_delay => $bond_down_delay,
bond_mac_address => $bond_mac_address,
bond_operational => $bond_operational,
}});
}
$query = "
SELECT
network_interface_uuid,
network_interface_mac_address,
network_interface_name,
network_interface_speed,
network_interface_mtu,
network_interface_link_state,
network_interface_operational,
network_interface_duplex,
network_interface_medium,
network_interface_bond_uuid,
network_interface_bridge_uuid
FROM
network_interfaces
WHERE
network_interface_host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid)."
ORDER BY
modified_date DESC
;";
$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,
}});
# The order will track the order the interfaces were last modified, which is a way to determine when
# they came up.
my $order = 1;
foreach my $row (@{$results})
{
my $network_interface_uuid = $row->[0];
my $network_interface_mac_address = $row->[1];
my $network_interface_name = $row->[2];
my $network_interface_speed = $row->[3];
my $network_interface_mtu = $row->[4];
my $network_interface_link_state = $row->[5];
my $network_interface_operational = $row->[6];
my $network_interface_duplex = $row->[7];
my $network_interface_medium = $row->[8];
my $network_interface_bond_uuid = $row->[9];
my $network_interface_bridge_uuid = $row->[10];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
network_interface_mac_address => $network_interface_mac_address,
network_interface_name => $network_interface_name,
network_interface_speed => $network_interface_speed,
network_interface_mtu => $network_interface_mtu,
network_interface_link_state => $network_interface_link_state,
network_interface_operational => $network_interface_operational,
network_interface_duplex => $network_interface_duplex,
network_interface_medium => $network_interface_medium,
network_interface_bond_uuid => $network_interface_bond_uuid,
network_interface_bridge_uuid => $network_interface_bridge_uuid,
order => $order,
}});
$order++;
}
die;
# Write out the XML file and JSON file.
my $order = 1;
my $network_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$network_xml .= "<network>\n";
my $network_json = "{\"networks\":[\n";
@ -396,16 +555,16 @@ ORDER BY
}});
foreach my $row (@{$results})
{
my $network_interface_mac_address = $row->[0];
my $network_interface_name = $row->[1];
my $network_interface_speed = $row->[2];
my $network_interface_mtu = defined $row->[3] ? $row->[3] : "";
my $network_interface_link_state = $row->[4];
my $network_interface_operational = $row->[5];
my $network_interface_duplex = $row->[6];
my $network_interface_medium = defined $row->[7] ? $row->[7] : "";
my $network_interface_bond_uuid = defined $row->[8] ? $row->[8] : "";
my $network_interface_bridge_uuid = defined $row->[9] ? $row->[9] : "";
my $network_interface_mac_address = $row->[0];
my $network_interface_name = $row->[1];
my $network_interface_speed = $row->[2];
my $network_interface_mtu = $row->[3];
my $network_interface_link_state = $row->[4];
my $network_interface_operational = $row->[5];
my $network_interface_duplex = $row->[6];
my $network_interface_medium = $row->[7];
my $network_interface_bond_uuid = $row->[8];
my $network_interface_bridge_uuid = $row->[9];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
network_interface_mac_address => $network_interface_mac_address,
network_interface_name => $network_interface_name,

@ -23,6 +23,15 @@
-- 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.
-- 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';
-- This doesn't work before 9.3 - CREATE SCHEMA IF NOT EXISTS history;
@ -48,9 +57,9 @@ CREATE TABLE users (
user_algorithm text not null, -- This is the algorithm used to encrypt the password and salt.
user_hash_count text not null, -- This is the number of times that the password+salt was re-hashed through the algorithm.
user_language text not null, -- If set, this will choose a different language over the default.
user_is_admin boolean not null default false, -- If true, all aspects of the program are available to the user.
user_is_experienced boolean not null default false, -- If true, user is allowed to delete a server, alter disk size, alter hardware and do other potentially risky things. They will also get fewer confirmation dialogues.
user_is_trusted boolean not null default false, -- If true, user is allowed to do things that would cause interruptions, like force-reset and gracefully stop servers, withdraw nodes, and stop the Anvil! entirely.
user_is_admin integer not null default 0, -- If 1, all aspects of the program are available to the user.
user_is_experienced integer not null default 0, -- If 1, user is allowed to delete a server, alter disk size, alter hardware and do other potentially risky things. They will also get fewer confirmation dialogues.
user_is_trusted integer not null default 0, -- If 1, user is allowed to do things that would cause interruptions, like force-reset and gracefully stop servers, withdraw nodes, and stop the Anvil! entirely.
modified_date timestamp with time zone not null
);
ALTER TABLE users OWNER TO #!variable!user!#;
@ -64,9 +73,9 @@ CREATE TABLE history.users (
user_algorithm text,
user_hash_count text,
user_language text,
user_is_admin boolean,
user_is_experienced boolean,
user_is_trusted boolean,
user_is_admin integer,
user_is_experienced integer,
user_is_trusted integer,
modified_date timestamp with time zone not null
);
ALTER TABLE history.users OWNER TO #!variable!user!#;
@ -164,14 +173,14 @@ CREATE TABLE host_variable (
host_variable_uuid uuid not null primary key, -- This is the single most important record in ScanCore. Everything links back to here.
host_variable_host_uuid uuid not null,
host_variable_name text not null,
host_variable_value text,
host_variable_value text not null,
modified_date timestamp with time zone not null
);
ALTER TABLE host_variable OWNER TO #!variable!user!#;
CREATE TABLE history.host_variable (
history_id bigserial,
host_variable_uuid uuid not null,
host_variable_uuid uuid,
host_variable_host_uuid uuid,
host_variable_name text,
host_variable_value text,
@ -215,11 +224,11 @@ CREATE TABLE alerts (
alert_set_by text not null,
alert_level text not null, -- debug (log only), info (+ admin email), notice (+ curious users), warning (+ client technical staff), critical (+ all)
alert_title_key text not null, -- ScanCore will read in the agents <name>.xml words file and look for this message key
alert_title_variables text, -- List of variables to substitute into the message key. Format is 'var1=val1 #!# var2 #!# val2 #!# ... #!# varN=valN'.
alert_title_variables text not null, -- List of variables to substitute into the message key. Format is 'var1=val1 #!# var2 #!# val2 #!# ... #!# varN=valN'.
alert_message_key text not null, -- ScanCore will read in the agents <name>.xml words file and look for this message key
alert_message_variables text, -- List of variables to substitute into the message key. Format is 'var1=val1 #!# var2 #!# val2 #!# ... #!# varN=valN'.
alert_sort text, -- The alerts will sort on this column. It allows for an optional sorting of the messages in the alert.
alert_header boolean not null default TRUE, -- This can be set to have the alert be printed with only the contents of the string, no headers.
alert_message_variables text not null, -- List of variables to substitute into the message key. Format is 'var1=val1 #!# var2 #!# val2 #!# ... #!# varN=valN'.
alert_sort text not null, -- The alerts will sort on this column. It allows for an optional sorting of the messages in the alert.
alert_header integer not null default 1, -- This can be set to have the alert be printed with only the contents of the string, no headers.
modified_date timestamp with time zone not null,
FOREIGN KEY(alert_host_uuid) REFERENCES hosts(host_uuid)
@ -237,7 +246,7 @@ CREATE TABLE history.alerts (
alert_message_key text,
alert_message_variables text,
alert_sort text,
alert_header boolean,
alert_header integer,
modified_date timestamp with time zone not null
);
ALTER TABLE history.alerts OWNER TO #!variable!user!#;
@ -287,12 +296,12 @@ CREATE TRIGGER trigger_alerts
CREATE TABLE variables (
variable_uuid uuid not null primary key,
variable_name text not null, -- This is the 'x::y::z' style variable name.
variable_value text, -- It is up to the software to sanity check variable values before they are stored
variable_default text, -- This acts as a reference for the user should they want to roll-back changes.
variable_description text, -- This is a string key that describes this variable's use.
variable_section text, -- This is a free-form field that is used when displaying the various entries to a user. This allows for the various variables to be grouped into sections.
variable_source_uuid text, -- Optional; Marks the variable as belonging to a specific X_uuid, where 'X' is a table name set in 'variable_source_table'
variable_source_table text, -- Optional; Marks the database table corresponding to the 'variable_source_uuid' value.
variable_value text not null, -- It is up to the software to sanity check variable values before they are stored
variable_default text not null, -- This acts as a reference for the user should they want to roll-back changes.
variable_description text not null, -- This is a string key that describes this variable's use.
variable_section text not null, -- This is a free-form field that is used when displaying the various entries to a user. This allows for the various variables to be grouped into sections.
variable_source_uuid text not null, -- Optional; Marks the variable as belonging to a specific X_uuid, where 'X' is a table name set in 'variable_source_table'
variable_source_table text not null, -- Optional; Marks the database table corresponding to the 'variable_source_uuid' value.
modified_date timestamp with time zone not null
);
ALTER TABLE variables OWNER TO #!variable!user!#;
@ -353,7 +362,7 @@ CREATE TABLE jobs (
job_uuid uuid not null primary key, --
job_host_uuid uuid not null, -- This is the host that requested the job
job_command text not null, -- This is the command to run (usually a shell call).
job_data text, -- This is optional data to be used by anvil-data
job_data text not null, -- This is optional data to be used by anvil-data
job_picked_up_by numeric not null default 0, -- This is the PID of the 'anvil-jobs' script that picked up the job.
job_picked_up_at numeric not null default 0, -- This is unix timestamp of when the job was picked up.
job_updated numeric not null default 0, -- This is unix timestamp that is perdiodically updated for jobs that take a long time. It is used to help determine when a job is hung.
@ -441,13 +450,13 @@ CREATE TABLE network_interfaces (
network_interface_mac_address text not null,
network_interface_name text not null, -- This is the current name of the interface.
network_interface_speed bigint not null, -- This is the speed, in bits-per-second, of the interface.
network_interface_mtu bigint, -- This is the MTU (Maximum Transmitable Size), in bytes, for this interface.
network_interface_mtu bigint not null, -- This is the MTU (Maximum Transmitable Size), in bytes, for this interface.
network_interface_link_state text not null, -- 0 or 1
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_medium text, -- This is 'tp' (twisted pair), 'fiber' or whatever they invent in the future.
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, -- If this iface is attached to a bridge, this will contain the 'bridgess -> bridge_uuid' that it is connected to.
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_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
);
ALTER TABLE network_interfaces OWNER TO #!variable!user!#;
@ -521,16 +530,15 @@ CREATE TABLE bonds (
bond_host_uuid uuid not null,
bond_name text not null,
bond_mode text not null, -- This is the numerical bond type (will translate to the user's language in the Anvil!)
bond_mtu bigint,
bond_primary_slave text,
bond_primary_reselect text,
bond_active_slave text,
bond_mii_status text,
bond_mii_polling_interval bigint,
bond_up_delay bigint,
bond_down_delay bigint,
bond_mac_address text,
bond_operational text, -- This is 'up', 'down' or 'unknown'
bond_mtu bigint not null,
bond_primary_slave text not null,
bond_primary_reselect text not null,
bond_active_slave text not null,
bond_mii_polling_interval bigint not null,
bond_up_delay bigint not null,
bond_down_delay bigint not null,
bond_mac_address text not null,
bond_operational text not null, -- This is 'up', 'down' or 'unknown'
modified_date timestamp with time zone not null,
FOREIGN KEY(bond_host_uuid) REFERENCES hosts(host_uuid)
@ -547,7 +555,6 @@ CREATE TABLE history.bonds (
bond_primary_slave text,
bond_primary_reselect text,
bond_active_slave text,
bond_mii_status text,
bond_mii_polling_interval bigint,
bond_up_delay bigint,
bond_down_delay bigint,
@ -572,7 +579,6 @@ BEGIN
bond_primary_slave,
bond_primary_reselect,
bond_active_slave,
bond_mii_status,
bond_mii_polling_interval,
bond_up_delay,
bond_down_delay,
@ -588,7 +594,6 @@ BEGIN
history_bonds.bond_primary_slave,
history_bonds.bond_primary_reselect,
history_bonds.bond_active_slave,
history_bonds.bond_mii_status,
history_bonds.bond_mii_polling_interval,
history_bonds.bond_up_delay,
history_bonds.bond_down_delay,
@ -611,8 +616,8 @@ CREATE TABLE bridges (
bridge_uuid uuid not null primary key,
bridge_host_uuid uuid not null,
bridge_name text not null,
bridge_id text,
bridge_stp_enabled text,
bridge_id text not null,
bridge_stp_enabled text not null,
modified_date timestamp with time zone not null,
FOREIGN KEY(bridge_host_uuid) REFERENCES hosts(host_uuid)
@ -671,9 +676,9 @@ CREATE TABLE ip_addresses (
ip_address_on_uuid uuid not null, -- This is the UUID of the interface, bond or bridge that has this IP
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_gateway text, -- If set, this is the gateway IP for this subnet
ip_address_default_gateway boolean default FALSE, -- If true, the gateway will be the default for the host.
ip_address_dns text, -- If set, this is a comma-separated list of DNS IPs to use (in the order given)
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_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,
FOREIGN KEY(ip_address_host_uuid) REFERENCES hosts(host_uuid)
@ -689,7 +694,7 @@ CREATE TABLE history.ip_addresses (
ip_address_address text,
ip_address_subnet_mask text,
ip_address_gateway text,
ip_address_default_gateway text,
ip_address_default_gateway integer,
ip_address_dns text,
modified_date timestamp with time zone not null
);
@ -773,7 +778,7 @@ CREATE TABLE states (
state_uuid uuid not null primary key,
state_name text not null, -- This is the name of the state (ie: 'migration', etc)
state_host_uuid uuid not null, -- The UUID of the machine that the state relates to. In migrations, this is the UUID of the target
state_note text, -- This is a free-form note section that the application setting the state can use for extra information (like the name of the server being migrated)
state_note text not null, -- This is a free-form note section that the application setting the state can use for extra information (like the name of the server being migrated)
modified_date timestamp with time zone not null,
FOREIGN KEY(state_host_uuid) REFERENCES hosts(host_uuid)

Loading…
Cancel
Save