Merge pull request #184 from ClusterLabs/anvil-tools-dev

Anvil tools dev
main
Digimer 3 years ago committed by GitHub
commit 8e5daa090a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 141
      Anvil/Tools/Database.pm
  2. 2
      Anvil/Tools/ScanCore.pm
  3. 2
      Anvil/Tools/Server.pm
  4. 1
      scancore-agents/scan-network/scan-network
  5. 21
      tools/anvil-update-states

@ -1347,67 +1347,6 @@ sub connect
} }
} }
# Before we try to connect, see if this is a local database and, if so, make sure it's setup.
my $is_local = $anvil->Network->is_local({debug => $debug, host => $host});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { is_local => $is_local }});
if ($is_local)
{
$anvil->data->{sys}{database}{read_uuid} = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::read_uuid" => $anvil->data->{sys}{database}{read_uuid} }});
# If requested, and if running with root access, set it up (or update it) if needed.
# This method just returns if nothing is needed.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
check_if_configured => $check_if_configured,
real_uid => $<,
effective_uid => $>,
}});
if (($check_if_configured) && ($< == 0) && ($> == 0))
{
$anvil->Database->configure_pgsql({debug => $debug, uuid => $uuid});
}
}
elsif (not $anvil->data->{sys}{database}{read_uuid})
{
$anvil->data->{sys}{database}{read_uuid} = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::read_uuid" => $anvil->data->{sys}{database}{read_uuid} }});
}
# If this isn't a local database, read the target's Anvil! version (if available) and make
# sure it matches ours. If it doesn't, skip this database.
if (not $is_local)
{
my ($local_anvil_version, $local_schema_version) = $anvil->_anvil_version({debug => $debug});
my ($remote_anvil_version, $remote_schema_version) = $anvil->Get->anvil_version({
debug => $debug,
target => $host,
password => $password,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:host' => $host,
's2:local_anvil_version' => $local_anvil_version,
's3:remote_anvil_version' => $remote_anvil_version,
's4:local_schema_version' => $local_schema_version,
's5:remote_schema_version' => $remote_schema_version,
}});
# TODO: Periodically, we fail to get the remote version. For now, we proceed if
# everything else is OK. Might be better to pause a re-try... To be determined.
if (($remote_schema_version) && ($remote_schema_version ne $local_schema_version))
{
# Version doesn't match,
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0145", variables => {
host => $host,
local_version => $local_schema_version,
target_version => $remote_schema_version,
}});
# Delete the information about this database. We'll try again on nexy
# ->connect().
delete $anvil->data->{database}{$uuid};
next;
}
}
# Connect! # Connect!
my $dbh = ""; my $dbh = "";
### NOTE: The Database->write() method, when passed an array, will automatically disable ### NOTE: The Database->write() method, when passed an array, will automatically disable
@ -1484,11 +1423,12 @@ sub connect
}; };
} }
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => $message_key, variables => $variables }); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => $message_key, variables => $variables });
next;
} }
elsif ($dbh =~ /^DBI::db=HASH/) elsif ($dbh =~ /^DBI::db=HASH/)
{ {
# Woot! # Woot!
$anvil->data->{sys}{database}{connections}++; $anvil->data->{sys}{database}{connections}++;
push @{$successful_connections}, $uuid; push @{$successful_connections}, $uuid;
$anvil->data->{cache}{database_handle}{$uuid} = $dbh; $anvil->data->{cache}{database_handle}{$uuid} = $dbh;
@ -1607,6 +1547,67 @@ sub connect
"sys::database::timestamp" => $anvil->data->{sys}{database}{timestamp}, "sys::database::timestamp" => $anvil->data->{sys}{database}{timestamp},
}}); }});
} }
# Before we try to connect, see if this is a local database and, if so, make sure it's setup.
my $is_local = $anvil->Network->is_local({debug => $debug, host => $host});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { is_local => $is_local }});
if ($is_local)
{
$anvil->data->{sys}{database}{read_uuid} = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::read_uuid" => $anvil->data->{sys}{database}{read_uuid} }});
# If requested, and if running with root access, set it up (or update it) if needed.
# This method just returns if nothing is needed.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
check_if_configured => $check_if_configured,
real_uid => $<,
effective_uid => $>,
}});
if (($check_if_configured) && ($< == 0) && ($> == 0))
{
$anvil->Database->configure_pgsql({debug => $debug, uuid => $uuid});
}
}
elsif (not $anvil->data->{sys}{database}{read_uuid})
{
$anvil->data->{sys}{database}{read_uuid} = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::read_uuid" => $anvil->data->{sys}{database}{read_uuid} }});
}
# If this isn't a local database, read the target's Anvil! version (if available) and make
# sure it matches ours. If it doesn't, skip this database.
if (not $is_local)
{
my ($local_anvil_version, $local_schema_version) = $anvil->_anvil_version({debug => $debug});
my ($remote_anvil_version, $remote_schema_version) = $anvil->Get->anvil_version({
debug => $debug,
target => $host,
password => $password,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:host' => $host,
's2:local_anvil_version' => $local_anvil_version,
's3:remote_anvil_version' => $remote_anvil_version,
's4:local_schema_version' => $local_schema_version,
's5:remote_schema_version' => $remote_schema_version,
}});
# TODO: Periodically, we fail to get the remote version. For now, we proceed if
# everything else is OK. Might be better to pause a re-try... To be determined.
if (($remote_schema_version) && ($remote_schema_version ne $local_schema_version))
{
# Version doesn't match,
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0145", variables => {
host => $host,
local_version => $local_schema_version,
target_version => $remote_schema_version,
}});
# Delete the information about this database. We'll try again on nexy
# ->connect().
delete $anvil->data->{database}{$uuid};
next;
}
}
} }
my $total = tv_interval ($start_time, [gettimeofday]); my $total = tv_interval ($start_time, [gettimeofday]);
@ -9111,16 +9112,21 @@ sub insert_or_update_network_interfaces
# If we don't have a network interface UUID, try to look one up using the MAC address # If we don't have a network interface UUID, try to look one up using the MAC address
if (not $network_interface_uuid) if (not $network_interface_uuid)
{ {
# See if I know this NIC by referencing it's MAC and name. The name is needed because virtual # See if I know this NIC by referencing it's MAC (if not a vnet device), host_uuid and name.
# devices can share the MAC with the real interface. # The name is needed because virtual devices can share the MAC with the real interface.
my $query = " my $query = "
SELECT SELECT
network_interface_uuid network_interface_uuid
FROM FROM
network_interfaces network_interfaces
WHERE WHERE ";
if ($network_interface_name !~ /^vnet/)
{
$query .= "
network_interface_mac_address = ".$anvil->Database->quote($network_interface_mac_address)." network_interface_mac_address = ".$anvil->Database->quote($network_interface_mac_address)."
AND AND ";
}
$query .= "
network_interface_name = ".$anvil->Database->quote($network_interface_name)." network_interface_name = ".$anvil->Database->quote($network_interface_name)."
AND AND
network_interface_host_uuid = ".$anvil->Database->quote($network_interface_host_uuid)." network_interface_host_uuid = ".$anvil->Database->quote($network_interface_host_uuid)."
@ -14991,7 +14997,7 @@ sub resync_databases
# Now read in the data from the different databases. # Now read in the data from the different databases.
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}}) foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}})
{ {
# ... $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { uuid => $uuid }});
$anvil->data->{db_resync}{$uuid}{public}{sql} = []; $anvil->data->{db_resync}{$uuid}{public}{sql} = [];
$anvil->data->{db_resync}{$uuid}{history}{sql} = []; $anvil->data->{db_resync}{$uuid}{history}{sql} = [];
@ -15313,6 +15319,7 @@ sub resync_databases
# Do the INSERTs now and then release the memory. # Do the INSERTs now and then release the memory.
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}}) foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}})
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { uuid => $uuid }});
# Merge the queries for both schemas into one array, with public schema # Merge the queries for both schemas into one array, with public schema
# queries being first, then delete the arrays holding them to free memory # queries being first, then delete the arrays holding them to free memory
# before we start the resync. # before we start the resync.

@ -271,7 +271,7 @@ sub agent_startup
} }
# Connect to DBs. # Connect to DBs.
$anvil->Database->connect({debug => 2}); $anvil->Database->connect({debug => $debug});
$anvil->Log->entry({source => $agent, line => __LINE__, level => $debug, secure => 0, key => "log_0132"}); $anvil->Log->entry({source => $agent, line => __LINE__, level => $debug, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections}) if (not $anvil->data->{sys}{database}{connections})
{ {

@ -1304,8 +1304,6 @@ sub parse_definition
} }
$anvil->data->{server}{$target}{$server}{$source}{parsed} = $server_xml; $anvil->data->{server}{$target}{$server}{$source}{parsed} = $server_xml;
#print Dumper $server_xml;
#die;
# Get the DRBD data that this server will almost certainly be using. # Get the DRBD data that this server will almost certainly be using.
$anvil->DRBD->get_devices({debug => $debug}); $anvil->DRBD->get_devices({debug => $debug});

@ -724,6 +724,7 @@ ORDER BY
}}); }});
my $query = "DELETE FROM network_interfaces WHERE network_interface_uuid = ".$anvil->Database->quote($network_interface_uuid).";"; my $query = "DELETE FROM network_interfaces WHERE network_interface_uuid = ".$anvil->Database->quote($network_interface_uuid).";";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
$count--; $count--;

@ -65,13 +65,13 @@ sub process_interface_cache
# Does the file exist? If so, read it in. # Does the file exist? If so, read it in.
if (-e $anvil->data->{path}{data}{network_cache}) if (-e $anvil->data->{path}{data}{network_cache})
{ {
my $body = $anvil->Storage->read_file({debug => 3, cache => 0, force_read => 1, file => $anvil->data->{path}{data}{network_cache}}); my $body = $anvil->Storage->read_file({debug => 2, cache => 0, force_read => 1, file => $anvil->data->{path}{data}{network_cache}});
foreach my $line (split/\n/, $body) foreach my $line (split/\n/, $body)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
next if $line =~ /^#/; next if $line =~ /^#/;
my ($interface, $timestamp, $mac_address, $speed, $link_state, $operational) = (split/,/, $line); my ($interface, $timestamp, $mac_address, $speed, $link_state, $operational) = (split/,/, $line);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
interface => $interface, interface => $interface,
timestamp => $timestamp, timestamp => $timestamp,
speed => $speed, speed => $speed,
@ -83,7 +83,7 @@ sub process_interface_cache
if ($anvil->data->{sys}{database}{connections}) if ($anvil->data->{sys}{database}{connections})
{ {
my ($network_interface_uuid) = $anvil->Database->insert_or_update_network_interfaces({ my ($network_interface_uuid) = $anvil->Database->insert_or_update_network_interfaces({
debug => 3, debug => 2,
link_only => 1, link_only => 1,
timestamp => $timestamp, timestamp => $timestamp,
network_interface_name => $interface, network_interface_name => $interface,
@ -222,10 +222,21 @@ sub update_network
$speed =~ s/\n$//; $speed =~ s/\n$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
interface => $interface, interface => $interface,
speed => $speed,
mac_address => $mac_address, mac_address => $mac_address,
link_state => $link_state,
mtu => $mtu,
duplex => $duplex,
operational => $operational,
speed => $speed,
}}); }});
# If this a vnet device, set 'operational' to 'up'.
if (($interface =~ /^vnet/) && ($operational ne "up"))
{
$operational = "up";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { operational => $operational }});
}
# These are variables that will be needed if this is a bond interface. # These are variables that will be needed if this is a bond interface.
my $ip_address = ""; my $ip_address = "";
my $subnet_mask = ""; my $subnet_mask = "";

Loading…
Cancel
Save