* Renamed the 'defitintions' table to 'server_definitions' to clarify the purpose, and made all the 'server' columns have then 'not null' constraint.
* Created Database->insert_or_update_servers(), ->get_servers(), ->insert_or_update_server_definitions() and ->get_server_definitions().
* Updated scancore, anvil-daemon, and scan agents to not run unless they're run with root privs.
* Got scan-server to update the servers / server_definition tables and the on-disk file when needed.
Signed-off-by: Digimer <digimer@alteeve.ca>
Thismethodusesthelocalmachine's host UUID and finds the host names of the cluster memebers. If this host is in a cluster and it is a node, the peer'sshorthostnameisreturned.Otherwise,anemptystringisreturned.
Thismethodusesthelocalmachine's host UUID and finds the host names of the cluster memebers. If this host is in a cluster and it is a node, the peer'sshorthostnameisreturned.Otherwise,anemptystringisreturned.
Thisloadsallknownuser's SSH public keys and all known machine'spublickeysintothedatahash.Onsuccess,thismethodreturnsC<<0>>.Ifanyproblemsoccur,C<<1>>isreturned.
Thisloadsallknownuser's SSH public keys and all known machine'spublickeysintothedatahash.Onsuccess,thismethodreturnsC<<0>>.Ifanyproblemsoccur,C<<1>>isreturned.
@ -9274,7 +9360,7 @@ sub insert_or_update_servers
# Do we already know about this
# Do we already know about this
my$exists=0;
my$exists=0;
my$query="SELECT COUNT(*) FROM servers WHERE server_uuid = ".$anvil->Database->quote($server_uuid).";";
my$query="SELECT COUNT(*) FROM servers WHERE server_uuid = ".$anvil->Database->quote($server_uuid).";";
FOR EACH ROW EXECUTE PROCEDURE history_temperature();
FOR EACH ROW EXECUTE PROCEDURE history_temperature();
DROP FUNCTION history_definitions() CASCADE;
DROP TABLE history.definitions;
DROP TABLE definitions;
DROP FUNCTION history_servers() CASCADE;
DROP TABLE history.servers;
DROP TABLE servers;
-- This stores servers made available to Anvil! systems and DR hosts.
CREATE TABLE servers (
server_uuid uuid not null primary key,
server_name text not null, -- This is the server's name. It can change without re-uploading the server.
server_anvil_uuid uuid not null, -- This is the Anvil! system that the server lives on. It can move to another Anvil!, so this can change.
server_clean_stop boolean not null default FALSE, -- When set, the server was stopped by a user. The Anvil! will not start a server that has been cleanly stopped.
server_start_after_server_uuid uuid not null, -- This can be the server_uuid of another server. If set, this server will boot 'server_start_delay' seconds after the referenced server boots. A value of '00000000-0000-0000-0000-000000000000' will tell 'anvil-safe-start' to not boot the server at all. If a server is set not to start, any dependent servers will also stay off.
server_start_delay integer not null default 0, -- See above.
server_host_uuid uuid not null, -- This is the current hosts -> host_uuid for this server. If the server is off, this will be blank.
server_state text not null, -- This is the current state of this server.
server_live_migration boolean not null default TRUE, -- When false, servers will be stopped and then rebooted when a migration is requested. Also, when false, preventative migrations will not happen.
server_pre_migration_file_uuid uuid not null, -- This is set to the files -> file_uuid of a script to run BEFORE migrating a server. If the file isn't found or can't run, the script is ignored.
server_pre_migration_arguments text not null, -- These are arguments to pass to the pre-migration script
server_post_migration_file_uuid uuid not null, -- This is set to the files -> file_uuid of a script to run AFTER migrating a server. If the file isn't found or can't run, the script is ignored.
server_post_migration_arguments text not null, -- These are arguments to pass to the post-migration script
my ($output, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." list --all", source => $THIS_FILE, line => __LINE__});
my ($output, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." list --all", source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output => $output, return_code => $return_code }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output => $output, return_code => $return_code }});
foreach my $line (split/\n/, $output)
foreach my $line (split/\n/, $output)
@ -112,8 +130,8 @@ sub collect_data
if ($line =~ /^\d+ (.*?) (.*)$/)
if ($line =~ /^\d+ (.*?) (.*)$/)
{
{
my $server = $1;
my $server = $1;
my $state = $2;
my $state = $2;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
server => $server,
server => $server,
'state' => $state,
'state' => $state,
@ -165,25 +183,174 @@ sub collect_data
}
}
my $server_uuid = $anvil->data->{server}{$target}{$server}{$source}{info}{uuid};
my $server_uuid = $anvil->data->{server}{$target}{$server}{$source}{info}{uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { server_uuid => $server_uuid }});
my $server_name = $anvil->data->{server}{$target}{$server}{$source}{info}{name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
server_uuid => $server_uuid,
server_name => $server_name,
}});
# See if this server is in the database.
# See if this server is in the database.
my $query = "SELECT COUNT(*) FROM servers WHERE server_uuid = ".$anvil->Database->quote($server_uuid).";";
if (not exists $anvil->data->{servers}{server_uuid}{$server_uuid})
my $count = $anvil->Database->query({query => $function_query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { count => $count }});
if (not $count)
{
{
# Add it.
# Add it. I'll need my anvil_uuid first.
my $anvil_uuid = $anvil->Cluster->get_anvil_uuid({debug => 2});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }});
my $got_server_uuid = $anvil->Database->insert_or_update_servers({
@ -14,7 +14,20 @@ NOTE: All string keys MUST be prefixed with the agent name! ie: 'scan_server_log
<languagename="en_CA"long_name="Canadian English"description="ScanCore scan agent that monitors hardware, like RAM modules, CSS LED status, CPU information, etc.">
<languagename="en_CA"long_name="Canadian English"description="ScanCore scan agent that monitors hardware, like RAM modules, CSS LED status, CPU information, etc.">
<!-- Alert entries -->
<!-- Alert entries -->
<keyname="scan_server_alert_0001"></key>
<keyname="scan_server_alert_0001">
The definition file for the server: [#!variable!server!#] has changed relative to the database record. This is usually harmless.
The differences are:
====
#!variable!difference!#
====
</key>
<keyname="scan_server_alert_0002">
The definition file for the server: [#!variable!server!#] has changed relative to disk record. This is usually harmless.
@ -1058,6 +1058,11 @@ The file: [#!variable!file!#] needs to be updated. The difference is:
<keyname="log_0553">The server: [#!variable!server!#] has booted!</key>
<keyname="log_0553">The server: [#!variable!server!#] has booted!</key>
<keyname="log_0554">Waiting for the server: [#!variable!server!#] to shut down...</key>
<keyname="log_0554">Waiting for the server: [#!variable!server!#] to shut down...</key>
<keyname="log_0555">The server: [#!variable!server!#] is now off.</key>
<keyname="log_0555">The server: [#!variable!server!#] is now off.</key>
<keyname="log_0556">The server: [#!variable!server!#] (#!variable!server_uuid!#) has a definition change:
====
#!variable!difference!#
====
</key>
<!-- Messages for users (less technical than log entries), though sometimes used for logs, too. -->
<!-- Messages for users (less technical than log entries), though sometimes used for logs, too. -->
<keyname="message_0001">The host name: [#!variable!target!#] does not resolve to an IP address.</key>
<keyname="message_0001">The host name: [#!variable!target!#] does not resolve to an IP address.</key>
@ -1857,6 +1862,30 @@ The error was:
</key>
</key>
<keyname="warning_0064">[ Warning ] - The server: [#!variable!server!#] was asked to be migrated to: [#!variable!requested_node!#], but the server is shutting down. Aborting.</key>
<keyname="warning_0064">[ Warning ] - The server: [#!variable!server!#] was asked to be migrated to: [#!variable!requested_node!#], but the server is shutting down. Aborting.</key>
<keyname="warning_0065">[ Warning ] - The server: [#!variable!server!#] was asked to be migrated to: [#!variable!requested_node!#], but the server is already in the middle of a migration. Aborting.</key>
<keyname="warning_0065">[ Warning ] - The server: [#!variable!server!#] was asked to be migrated to: [#!variable!requested_node!#], but the server is already in the middle of a migration. Aborting.</key>
<keyname="warning_0066">[ Warning ] - Failed to parse the XML:
========
#!variable!xml!#
========
The error was:
========
#!variable!error!#
========
</key>
<keyname="warning_0067">[ Warning ] - Failed to find the server's UUID from the definition XML:
========
#!variable!xml!#
========
</key>
<keyname="warning_0068">[ Warning ] - The server UUID read: from the definition XML doesn't match the passed-in server UUID.