Merge pull request #37 from ClusterLabs/schema_work

* Updated the 'hosts' table and relevant Database methods to add colu…
main
digimer-bot 4 years ago committed by GitHub
commit 60cc90bec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 86
      Anvil/Tools/Database.pm
  2. 4
      Anvil/Tools/ScanCore.pm
  3. 10
      share/anvil.sql

@ -2594,6 +2594,8 @@ Each anonymous hash is structured as:
host_type => $host_type, host_type => $host_type,
host_key => $host_key, host_key => $host_key,
host_ipmi => $host_ipmi, host_ipmi => $host_ipmi,
host_health => $host_health,
host_status => $host_status,
modified_date => $modified_date, modified_date => $modified_date,
It also sets the variables; It also sets the variables;
@ -2602,6 +2604,8 @@ It also sets the variables;
hosts::host_uuid::<host_uuid>::host_type = <host_type; node, dr or dashboard> hosts::host_uuid::<host_uuid>::host_type = <host_type; node, dr or dashboard>
hosts::host_uuid::<host_uuid>::host_key = <Machine's public key / fingerprint, set to DELETED when the host is no longer used> hosts::host_uuid::<host_uuid>::host_key = <Machine's public key / fingerprint, set to DELETED when the host is no longer used>
hosts::host_uuid::<host_uuid>::host_ipmi = <If equiped, this is how to log into the host's IPMI BMC, including the password!> hosts::host_uuid::<host_uuid>::host_ipmi = <If equiped, this is how to log into the host's IPMI BMC, including the password!>
hosts::host_uuid::<host_uuid>::host_health = <A numeric score representing the health of the node; 0 == healthy and the higher the number, the worse its health>
hosts::host_uuid::<host_uuid>::host_status = <This is the power state of the host. Default is 'unknown', and can be "powered off", "online", "stopping" and "booting.>
hosts::host_uuid::<host_uuid>::anvil_name = <anvil_name if associated with an anvil> hosts::host_uuid::<host_uuid>::anvil_name = <anvil_name if associated with an anvil>
hosts::host_uuid::<host_uuid>::anvil_uuid = <anvil_uuid if associated with an anvil> hosts::host_uuid::<host_uuid>::anvil_uuid = <anvil_uuid if associated with an anvil>
@ -2649,6 +2653,8 @@ SELECT
host_type, host_type,
host_key, host_key,
host_ipmi, host_ipmi,
host_health,
host_status,
modified_date modified_date
FROM FROM
hosts "; hosts ";
@ -2676,13 +2682,17 @@ WHERE
my $host_type = defined $row->[2] ? $row->[2] : ""; my $host_type = defined $row->[2] ? $row->[2] : "";
my $host_key = defined $row->[3] ? $row->[3] : ""; my $host_key = defined $row->[3] ? $row->[3] : "";
my $host_ipmi = $row->[4]; my $host_ipmi = $row->[4];
my $modified_date = $row->[5]; my $host_health = $row->[5];
my $host_status = $row->[6];
my $modified_date = $row->[7];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_uuid => $host_uuid, host_uuid => $host_uuid,
host_name => $host_name, host_name => $host_name,
host_type => $host_type, host_type => $host_type,
host_key => $host_key, host_key => $host_key,
host_ipmi => $host_ipmi =~ /passw/ ? $anvil->Log->is_secure($host_ipmi) : $host_ipmi, host_ipmi => $host_ipmi =~ /passw/ ? $anvil->Log->is_secure($host_ipmi) : $host_ipmi,
host_health => $host_health,
host_status => $host_status,
modified_date => $modified_date, modified_date => $modified_date,
}}); }});
@ -2701,6 +2711,8 @@ WHERE
host_type => $host_type, host_type => $host_type,
host_key => $host_key, host_key => $host_key,
host_ipmi => $host_ipmi, host_ipmi => $host_ipmi,
host_health => $host_health,
host_status => $host_status,
modified_date => $modified_date, modified_date => $modified_date,
}; };
@ -2713,6 +2725,8 @@ WHERE
$anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type} = $host_type; $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type} = $host_type;
$anvil->data->{hosts}{host_uuid}{$host_uuid}{host_key} = $host_key; $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_key} = $host_key;
$anvil->data->{hosts}{host_uuid}{$host_uuid}{host_ipmi} = $host_ipmi; $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_ipmi} = $host_ipmi;
$anvil->data->{hosts}{host_uuid}{$host_uuid}{host_health} = $host_health;
$anvil->data->{hosts}{host_uuid}{$host_uuid}{host_status} = $host_status;
$anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name} = $anvil_name; $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name} = $anvil_name;
$anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_uuid} = $anvil_uuid; $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_uuid} = $anvil_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
@ -2721,6 +2735,8 @@ WHERE
"hosts::host_uuid::${host_uuid}::host_type" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type}, "hosts::host_uuid::${host_uuid}::host_type" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type},
"hosts::host_uuid::${host_uuid}::host_key" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_key}, "hosts::host_uuid::${host_uuid}::host_key" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_key},
"hosts::host_uuid::${host_uuid}::host_ipmi" => $host_ipmi =~ /passw/ ? $anvil->Log->is_secure($anvil->data->{hosts}{host_uuid}{$host_uuid}{host_ipmi}) : $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_ipmi}, "hosts::host_uuid::${host_uuid}::host_ipmi" => $host_ipmi =~ /passw/ ? $anvil->Log->is_secure($anvil->data->{hosts}{host_uuid}{$host_uuid}{host_ipmi}) : $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_ipmi},
"hosts::host_uuid::${host_uuid}::host_health" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_health},
"hosts::host_uuid::${host_uuid}::host_status" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_status},
"hosts::host_uuid::${host_uuid}::anvil_name" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name}, "hosts::host_uuid::${host_uuid}::anvil_name" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name},
"hosts::host_uuid::${host_uuid}::anvil_uuid" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_uuid}, "hosts::host_uuid::${host_uuid}::anvil_uuid" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_uuid},
}}); }});
@ -2740,6 +2756,7 @@ WHERE
} }
### TODO: Why does this method exist?
=head2 get_hosts_info =head2 get_hosts_info
This gathers up all the known information about all known hosts. This gathers up all the known information about all known hosts.
@ -2764,7 +2781,9 @@ SELECT
host_name, host_name,
host_type, host_type,
host_key, host_key,
host_ipmi host_ipmi,
host_health,
host_status
FROM FROM
hosts hosts
;"; ;";
@ -2783,22 +2802,30 @@ FROM
my $host_type = $row->[2]; my $host_type = $row->[2];
my $host_key = $row->[3]; my $host_key = $row->[3];
my $host_ipmi = $row->[4]; my $host_ipmi = $row->[4];
my $host_health = $row->[5];
my $host_status = $row->[6];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_uuid => $host_uuid, host_uuid => $host_uuid,
host_name => $host_name, host_name => $host_name,
host_type => $host_type, host_type => $host_type,
host_key => $host_key, host_key => $host_key,
host_ipmi => $anvil->Log->is_secure($host_ipmi), host_ipmi => $anvil->Log->is_secure($host_ipmi),
host_health => $host_health,
host_status => $host_status,
}}); }});
$anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_name} = $host_name; $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_name} = $host_name;
$anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_type} = $host_type; $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_type} = $host_type;
$anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_key} = $host_key; $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_key} = $host_key;
$anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_ipmi} = $host_ipmi; $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_ipmi} = $host_ipmi;
$anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_health} = $host_health;
$anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_status} = $host_status;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"machine::host_uuid::${host_uuid}::hosts::host_name" => $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_name}, "machine::host_uuid::${host_uuid}::hosts::host_name" => $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_name},
"machine::host_uuid::${host_uuid}::hosts::host_type" => $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_type}, "machine::host_uuid::${host_uuid}::hosts::host_type" => $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_type},
"machine::host_uuid::${host_uuid}::hosts::host_key" => $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_key}, "machine::host_uuid::${host_uuid}::hosts::host_key" => $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_key},
"machine::host_uuid::${host_uuid}::hosts::host_ipmi" => $anvil->Log->is_secure($anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_ipmi}), "machine::host_uuid::${host_uuid}::hosts::host_ipmi" => $anvil->Log->is_secure($anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_ipmi}),
"machine::host_uuid::${host_uuid}::hosts::host_health" => $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_health},
"machine::host_uuid::${host_uuid}::hosts::host_status" => $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_status},
}}); }});
# If this is an Anvil! member, pull it's IP. # If this is an Anvil! member, pull it's IP.
@ -6784,6 +6811,24 @@ This default value is the value returned by C<< Get->host_type >>.
The default value is the host's UUID (as returned by C<< Get->host_uuid >>. The default value is the host's UUID (as returned by C<< Get->host_uuid >>.
=head3 host_health (optional, default 'no_change')
This is a numerical representation of the health of the node. C<< 0 >> is healthy, and the higher the value, the more "sick" the node is. This guides ScanCore is determining when to proactive live migrate servers.
B<< Note >>: This can be set to C<< no_change >> and the existing value is left as it is.
=head3 host_status (optional, default 'no_change')
This is the power state of the host. Valid values are;
* C<< unknown >> - This should only be set when a node can not be reached and the previous setting was not C<< stopping >> or C<< booting >>.
* C<< powered off >> - This shoule be set only when the host is confirmed off via IPMI call
* C<< online >> - This is set by the host itself when it boots up and first connects to the anvil database. B<< Note >> - This does NOT indicate readiness! Only that the host is accessible
* C<< stopping >> - This is a transitional state set by the host when it begins powering off.
* C<< booting >> - This is a transitional state set by a Striker dashboard when it is powering on a host.
B<< Note >> - Given that most Striker dashboards do not have IPMI, it is expected that they will enter C<< stopping >> state and never transition to c<< powered off >>. This is OK as C<< powered off >> can only be set when a target is B<< confirmed >> off. There's no other way to ensure that a target is not stuck while shutting down. Lack of pings doesn't solve this, either, as the network can go down before the host powers off.
=cut =cut
sub insert_or_update_hosts sub insert_or_update_hosts
{ {
@ -6801,6 +6846,8 @@ sub insert_or_update_hosts
my $host_name = defined $parameter->{host_name} ? $parameter->{host_name} : $anvil->Get->host_name; my $host_name = defined $parameter->{host_name} ? $parameter->{host_name} : $anvil->Get->host_name;
my $host_type = defined $parameter->{host_type} ? $parameter->{host_type} : $anvil->Get->host_type; my $host_type = defined $parameter->{host_type} ? $parameter->{host_type} : $anvil->Get->host_type;
my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : $anvil->Get->host_uuid; my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : $anvil->Get->host_uuid;
my $host_health = defined $parameter->{host_health} ? $parameter->{host_health} : "no_change";
my $host_status = defined $parameter->{host_status} ? $parameter->{host_status} : "no_change";
$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,
@ -6810,6 +6857,8 @@ sub insert_or_update_hosts
host_name => $host_name, host_name => $host_name,
host_type => $host_type, host_type => $host_type,
host_uuid => $host_uuid, host_uuid => $host_uuid,
host_health => $host_health,
host_status => $host_status,
}}); }});
if (not $host_name) if (not $host_name)
@ -6838,12 +6887,16 @@ sub insert_or_update_hosts
my $old_host_name = ""; my $old_host_name = "";
my $old_host_type = ""; my $old_host_type = "";
my $old_host_key = ""; my $old_host_key = "";
my $old_host_health = "";
my $old_host_status = "";
my $query = " my $query = "
SELECT SELECT
host_ipmi, host_ipmi,
host_name, host_name,
host_type, host_type,
host_key host_key,
host_health,
host_status
FROM FROM
hosts hosts
WHERE WHERE
@ -6863,16 +6916,33 @@ WHERE
$old_host_name = $row->[1]; $old_host_name = $row->[1];
$old_host_type = $row->[2]; $old_host_type = $row->[2];
$old_host_key = $row->[3]; $old_host_key = $row->[3];
$old_host_health = $row->[4];
$old_host_status = $row->[5];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_host_ipmi => $old_host_ipmi =~ /passw/ ? $anvil->Log->is_secure($old_host_ipmi) : $old_host_ipmi, old_host_ipmi => $old_host_ipmi =~ /passw/ ? $anvil->Log->is_secure($old_host_ipmi) : $old_host_ipmi,
old_host_name => $old_host_name, old_host_name => $old_host_name,
old_host_type => $old_host_type, old_host_type => $old_host_type,
old_host_key => $old_host_key, old_host_key => $old_host_key,
old_host_health => $old_host_health,
old_host_status => $old_host_status,
}}); }});
if ($host_health eq "no_change")
{
$host_health = $old_host_health;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_health => $host_health }});
}
if ($host_status eq "no_change")
{
$host_status = $old_host_status;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_status => $host_status }});
}
} }
if (not $count) if (not $count)
{ {
# Add this host to the database # Add this host to the database
my $say_host_health = $host_health eq "no_change" ? 0 : $host_health;
my $say_host_status = $host_status eq "no_change" ? "unknown" : $host_status;
my $query = " my $query = "
INSERT INTO INSERT INTO
hosts hosts
@ -6882,6 +6952,8 @@ INSERT INTO
host_type, host_type,
host_key, host_key,
host_ipmi, host_ipmi,
host_health,
host_status,
modified_date modified_date
) VALUES ( ) VALUES (
".$anvil->Database->quote($host_uuid).", ".$anvil->Database->quote($host_uuid).",
@ -6889,6 +6961,8 @@ INSERT INTO
".$anvil->Database->quote($host_type).", ".$anvil->Database->quote($host_type).",
".$anvil->Database->quote($host_key).", ".$anvil->Database->quote($host_key).",
".$anvil->Database->quote($host_ipmi).", ".$anvil->Database->quote($host_ipmi).",
".$anvil->Database->quote($say_host_health).",
".$anvil->Database->quote($say_host_status).",
".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
); );
"; ";
@ -6897,7 +6971,9 @@ INSERT INTO
} }
elsif (($old_host_name ne $host_name) or elsif (($old_host_name ne $host_name) or
($old_host_type ne $host_type) or ($old_host_type ne $host_type) or
($old_host_key ne $host_key)) ($old_host_key ne $host_key) or
($old_host_health ne $host_health) or
($old_host_status ne $host_status))
{ {
# Clear the stop data. # Clear the stop data.
my $query = " my $query = "
@ -6908,6 +6984,8 @@ SET
host_type = ".$anvil->Database->quote($host_type).", host_type = ".$anvil->Database->quote($host_type).",
host_key = ".$anvil->Database->quote($host_key).", host_key = ".$anvil->Database->quote($host_key).",
host_ipmi = ".$anvil->Database->quote($host_ipmi).", host_ipmi = ".$anvil->Database->quote($host_ipmi).",
host_health = ".$anvil->Database->quote($host_health).",
host_status = ".$anvil->Database->quote($host_status).",
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE WHERE
host_uuid = ".$anvil->Database->quote($host_uuid)." host_uuid = ".$anvil->Database->quote($host_uuid)."

@ -646,6 +646,8 @@ sub post_scan_analysis_striker
my $host_type = $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_type}; my $host_type = $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_type};
my $host_key = $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_key}; my $host_key = $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_key};
my $host_ipmi = $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_ipmi}; my $host_ipmi = $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_ipmi};
my $host_health = $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_health};
my $host_status = $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_status};
my $password = $anvil->data->{machine}{host_uuid}{$host_uuid}{password}; my $password = $anvil->data->{machine}{host_uuid}{$host_uuid}{password};
my $anvil_name = $anvil->data->{machine}{host_uuid}{$host_uuid}{anvil}{name}; my $anvil_name = $anvil->data->{machine}{host_uuid}{$host_uuid}{anvil}{name};
my $anvil_uuid = $anvil->data->{machine}{host_uuid}{$host_uuid}{anvil}{uuid}; my $anvil_uuid = $anvil->data->{machine}{host_uuid}{$host_uuid}{anvil}{uuid};
@ -655,6 +657,8 @@ sub post_scan_analysis_striker
host_type => $host_type, host_type => $host_type,
host_key => $host_key, host_key => $host_key,
host_ipmi => $anvil->Log->is_secure($host_ipmi), host_ipmi => $anvil->Log->is_secure($host_ipmi),
host_health => $host_health,
host_status => $host_status,
password => $anvil->Log->is_secure($password), password => $anvil->Log->is_secure($password),
anvil_name => $anvil_name, anvil_name => $anvil_name,
anvil_uuid => $anvil_uuid, anvil_uuid => $anvil_uuid,

@ -3,7 +3,7 @@
-- The line below is used by machines in the Anvil! to know if their software version is compatible with the -- The line below is used by machines in the Anvil! to know if their software version is compatible with the
-- database servers. As such, do NOT edit the line below unless you know why you're changing it. -- database servers. As such, do NOT edit the line below unless you know why you're changing it.
-- - Version follows: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html -- - Version follows: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
-- SchemaVersion: 0.0.0 -- SchemaVersion: 0.0.1
-- --
-- It expects PostgreSQL v. 9.1+ -- It expects PostgreSQL v. 9.1+
-- --
@ -55,6 +55,8 @@ CREATE TABLE hosts (
host_type text not null, -- Either 'node' or 'dashboard' or 'dr'. It is left empty until the host is configured. host_type text not null, -- Either 'node' or 'dashboard' or 'dr'. It is left empty until the host is configured.
host_key text not null, -- This is the host's key used to authenticate it when other machines try to ssh to it. host_key text not null, -- This is the host's key used to authenticate it when other machines try to ssh to it.
host_ipmi text not null default '', -- This is an optional string, in 'fence_ipmilan' format, that tells how to access/fence this host. host_ipmi text not null default '', -- This is an optional string, in 'fence_ipmilan' format, that tells how to access/fence this host.
host_health numeric not null default 0, -- This is a numerical representation of the health of the node. 0 is healthy, and the higher the value, the more "sick" the node is. This guides ScanCore is determining when to proactive live migrate servers.
host_status text not null default 'unknown' -- This is the power state of the host. Default is 'unknown', and can be "powered off", "online", "stopping" and "booting.
modified_date timestamp with time zone not null modified_date timestamp with time zone not null
); );
ALTER TABLE hosts OWNER TO admin; ALTER TABLE hosts OWNER TO admin;
@ -66,6 +68,8 @@ CREATE TABLE history.hosts (
host_type text, host_type text,
host_key text, host_key text,
host_ipmi text, host_ipmi text,
host_health numeric,
host_status text,
modified_date timestamp with time zone not null modified_date timestamp with time zone not null
); );
ALTER TABLE history.hosts OWNER TO admin; ALTER TABLE history.hosts OWNER TO admin;
@ -82,6 +86,8 @@ BEGIN
host_type, host_type,
host_key, host_key,
host_ipmi, host_ipmi,
host_health,
host_status,
modified_date) modified_date)
VALUES VALUES
(history_hosts.host_uuid, (history_hosts.host_uuid,
@ -89,6 +95,8 @@ BEGIN
history_hosts.host_type, history_hosts.host_type,
history_hosts.host_key, history_hosts.host_key,
history_hosts.host_ipmi, history_hosts.host_ipmi,
history_hosts.host_health,
history_hosts.host_status,
history_hosts.modified_date); history_hosts.modified_date);
RETURN NULL; RETURN NULL;
END; END;

Loading…
Cancel
Save