* Moved the '_host_name', '_short_host_name', and '_domain_name' private methods in Tools.pm over to Get.pm (removing the leading '_' in the method names).

* Created 'Cluster->which_node' that returns 'node1' or 'node2' to indicate which node a host is.
* Continued working on scan_cluster; decided to make it not host-dependent.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 4 years ago
parent b86251c9d6
commit 0f7267eae1
  1. 60
      Anvil/Tools.pm
  2. 99
      Anvil/Tools/Cluster.pm
  3. 12
      Anvil/Tools/DRBD.pm
  4. 28
      Anvil/Tools/Database.pm
  5. 4
      Anvil/Tools/Email.pm
  6. 83
      Anvil/Tools/Get.pm
  7. 12
      Anvil/Tools/Network.pm
  8. 2
      Anvil/Tools/Remote.pm
  9. 14
      Anvil/Tools/Server.pm
  10. 12
      Anvil/Tools/Striker.pm
  11. 12
      Anvil/Tools/System.pm
  12. 12
      cgi-bin/striker
  13. 32
      ocf/alteeve/server
  14. 33
      scancore-agents/scan-cluster/scan-cluster
  15. 72
      scancore-agents/scan-cluster/scan-cluster.sql
  16. 2
      tools/anvil-configure-host
  17. 4
      tools/anvil-join-anvil
  18. 2
      tools/anvil-manage-files
  19. 2
      tools/anvil-manage-firewall
  20. 2
      tools/anvil-update-states
  21. 4
      tools/striker-initialize-host
  22. 14
      tools/striker-manage-install-target
  23. 2
      tools/striker-manage-peers

@ -26,11 +26,9 @@ my $THIS_FILE = "Tools.pm";
# refresh # refresh
# _add_hash_reference # _add_hash_reference
# _anvil_version # _anvil_version
# _host_name
# _make_hash_reference # _make_hash_reference
# _set_defaults # _set_defaults
# _set_paths # _set_paths
# _short_host_name
use utf8; use utf8;
binmode(STDERR, ':encoding(utf-8)'); binmode(STDERR, ':encoding(utf-8)');
@ -746,48 +744,6 @@ sub _anvil_version
return($anvil->{HOST}{ANVIL_VERSION}); return($anvil->{HOST}{ANVIL_VERSION});
} }
=head3 _domain_name
This returns the domain name portion of the systen's host name. That is to say, the host name after the first '.'. If there is no domain portion, nothing is returned.
=cut
sub _domain_name
{
my $self = shift;
my $anvil = $self;
my $domain_name = $anvil->_host_name;
$domain_name =~ s/^.*?\.//;
$domain_name = "" if not defined $domain_name;
return($domain_name);
}
=head2 _host_name
This returns the (full) host name for the machine this is running on.
=cut
sub _host_name
{
my $self = shift;
my $anvil = $self;
my $host_name = "";
if ($ENV{HOSTNAME})
{
# We have an environment variable, so use it.
$host_name = $ENV{HOSTNAME};
}
else
{
# The environment variable isn't set. Call 'hostnamectl' on the command line.
($host_name, my $return_code) = $anvil->System->call({debug => 9999, shell_call => $anvil->data->{path}{exe}{hostnamectl}." --static"});
}
return($host_name);
}
=head2 _get_hash_reference =head2 _get_hash_reference
This is called when we need to parse a double-colon separated string into two or more elements which represent keys in the 'C<< $anvil->data >>' hash. Once suitably split up, the value is read and returned. This is called when we need to parse a double-colon separated string into two or more elements which represent keys in the 'C<< $anvil->data >>' hash. Once suitably split up, the value is read and returned.
@ -1322,22 +1278,6 @@ sub _set_paths
return(0); return(0);
} }
=head3 _short_host_name
This returns the short host name for the machine this is running on. That is to say, the host name up to the first '.'.
=cut
sub _short_host_name
{
my $self = shift;
my $anvil = $self;
my $short_host_name = $anvil->_host_name;
$short_host_name =~ s/\..*$//;
return($short_host_name);
}
=head1 Exit Codes =head1 Exit Codes
=head2 C<1> =head2 C<1>

@ -18,6 +18,7 @@ my $THIS_FILE = "Cluster.pm";
# get_peers # get_peers
# parse_cib # parse_cib
# start_cluster # start_cluster
# which_node
=pod =pod
@ -564,7 +565,7 @@ sub parse_cib
}}); }});
# Is this me or the peer? # Is this me or the peer?
if (($node_name ne $anvil->_host_name) && ($node_name ne $anvil->_short_host_name)) if (($node_name ne $anvil->Get->host_name) && ($node_name ne $anvil->Get->short_host_name))
{ {
# It's our peer. # It's our peer.
$anvil->data->{cib}{parsed}{peer}{ready} = $ready; $anvil->data->{cib}{parsed}{peer}{ready} = $ready;
@ -613,7 +614,7 @@ sub parse_cib
{ {
$anvil->data->{cib}{parsed}{data}{cluster}{'maintenance-mode'} = $value; $anvil->data->{cib}{parsed}{data}{cluster}{'maintenance-mode'} = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"cib::parsed::data::cluster::name" => $anvil->data->{cib}{parsed}{data}{cluster}{name}, "cib::parsed::data::cluster::maintenance-mode" => $anvil->data->{cib}{parsed}{data}{cluster}{'maintenance-mode'},
}}); }});
} }
} }
@ -703,6 +704,7 @@ sub parse_cib
return($problem); return($problem);
} }
=head2 start_cluster =head2 start_cluster
This will join the local node to the pacemaker cluster. Optionally, it can try to start the cluster on both nodes if C<< all >> is set. This will join the local node to the pacemaker cluster. Optionally, it can try to start the cluster on both nodes if C<< all >> is set.
@ -746,6 +748,99 @@ sub start_cluster
return($success); return($success);
} }
=head2 which_node
This method returns which node a given machine is in the cluster, returning either C<< node1 >> or C<< node2 >>. If the host is not a node, an empty string is returned.
This method is meant to compliment C<< Database->get_anvils() >> to make it easy for tasks that only need to run on one node in the cluster to decide it that is them or not.
Parameters;
=head3 host_name (optional, default Get->short_host_name)
This is the host name to look up. If not set, B<< and >> C<< node_uuid >> is also not set, the short host name of the local system is used.
B<< Note >>; If the host name is passed and the host UUID is not, and the host UUID can not be located (or the host name is invalid), this method will return C<< !!error!! >>.
=head3 host_uuid (optional, default Get->host_uuid)
This is the host UUID to look up. If not set, B<< and >> C<< node_name >> is also not set, the local system's host UUID is used.
=cut
sub which_node
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Cluster->start_cluster()" }});
my $node_is = "";
my $node_name = defined $parameter->{node_name} ? $parameter->{node_name} : "";
my $node_uuid = defined $parameter->{node_uuid} ? $parameter->{node_uuid} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
node_name => $node_name,
node_uuid => $node_uuid,
}});
if ((not $node_name) && (not $node_uuid))
{
$node_name = $anvil->Get->short_host_name();
$node_uuid = $anvil->Get->host_uuid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
node_name => $node_name,
node_uuid => $node_uuid,
}});
}
elsif (not $node_uuid)
{
# Get the node UUID from the host name.
$node_uuid = $anvil->Get->host_name_from_uuid({host_name => $node_name});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { node_uuid => $node_uuid }});
if (not $node_uuid)
{
return("!!error!!");
}
}
# Load Anvil! systems.
if ((not exists $anvil->data->{anvils}{anvil_name}) && (not $anvil->data->{anvils}{anvil_name}))
{
$anvil->Database->load_anvils({debug => $debug});
}
foreach my $anvil_name (sort {$a cmp $b} keys %{$anvil->data->{anvils}{anvil_name}})
{
my $node1_host_uuid = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_node1_host_uuid};
my $node2_host_uuid = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_node2_host_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
anvil_name => $anvil_name,
node1_host_uuid => $node1_host_uuid
node2_host_uuid => $node2_host_uuid
}});
if ($node_uuid eq $node1_host_uuid)
{
$node_id = "node1";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { node_id => $node_id }});
last;
}
elsif ($node_uuid eq $node2_host_uuid)
{
$node_id = "node2";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { node_id => $node_id }});
last;
}
}
return($node_is);
}
# =head3 # =head3
# #
# Private Functions; # Private Functions;

@ -143,7 +143,7 @@ sub allow_two_primaries
} }
# Do we need to scan devices? # Do we need to scan devices?
my $host = $anvil->_short_host_name; my $host = $anvil->Get->short_host_name;
if (not $anvil->data->{drbd}{config}{$host}{peer}) if (not $anvil->data->{drbd}{config}{$host}{peer})
{ {
# Get our device list. # Get our device list.
@ -276,7 +276,7 @@ sub get_devices
}}); }});
# Is this a local call or a remote call? # Is this a local call or a remote call?
my $host = $anvil->_short_host_name; my $host = $anvil->Get->short_host_name;
my $shell_call = $anvil->data->{path}{exe}{drbdadm}." dump-xml"; my $shell_call = $anvil->data->{path}{exe}{drbdadm}." dump-xml";
my $output = ""; my $output = "";
if ($anvil->Network->is_local({host => $target})) if ($anvil->Network->is_local({host => $target}))
@ -403,10 +403,10 @@ sub get_devices
my $this_host = $host_href->{name}; my $this_host = $host_href->{name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
this_host => $this_host, this_host => $this_host,
'$anvil->_host_name' => $anvil->_host_name, '$anvil->Get->host_name' => $anvil->Get->host_name,
'$anvil->_short_host_name' => $anvil->_short_host_name, '$anvil->Get->short_host_name' => $anvil->Get->short_host_name,
}}); }});
if (($this_host eq $anvil->_host_name) or ($this_host eq $anvil->_short_host_name)) if (($this_host eq $anvil->Get->host_name) or ($this_host eq $anvil->Get->short_host_name))
{ {
$anvil->data->{drbd}{config}{$host}{host} = $this_host; $anvil->data->{drbd}{config}{$host}{host} = $this_host;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "drbd::config::${host}::host" => $anvil->data->{drbd}{config}{$host}{host} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "drbd::config::${host}::host" => $anvil->data->{drbd}{config}{$host}{host} }});
@ -567,7 +567,7 @@ sub get_status
# Is this a local call or a remote call? # Is this a local call or a remote call?
my $shell_call = $anvil->data->{path}{exe}{drbdsetup}." status --json"; my $shell_call = $anvil->data->{path}{exe}{drbdsetup}." status --json";
my $output = ""; my $output = "";
my $host = $anvil->_short_host_name(); my $host = $anvil->Get->short_host_name();
if ($anvil->Network->is_local({host => $target})) if ($anvil->Network->is_local({host => $target}))
{ {
# Clear the hash where we'll store the data. # Clear the hash where we'll store the data.

@ -1568,8 +1568,8 @@ sub connect
# Set the first ID to be the one I read from later. Alternatively, if this host is # Set the first ID to be the one I read from later. Alternatively, if this host is
# local, use it. # local, use it.
if (($host eq $anvil->_host_name) or if (($host eq $anvil->Get->host_name) or
($host eq $anvil->_short_host_name) or ($host eq $anvil->Get->short_host_name) or
($host eq "localhost") or ($host eq "localhost") or
($host eq "127.0.0.1") or ($host eq "127.0.0.1") or
(not $anvil->data->{sys}{database}{read_uuid})) (not $anvil->data->{sys}{database}{read_uuid}))
@ -3080,7 +3080,7 @@ sub get_local_uuid
$anvil->Network->get_ips({debug => $debug}); $anvil->Network->get_ips({debug => $debug});
# Look for matches # Look for matches
my $host = $anvil->_short_host_name(); my $host = $anvil->Get->short_host_name();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
if (not $local_uuid) if (not $local_uuid)
{ {
@ -3218,7 +3218,7 @@ AND
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $local_host = $anvil->_short_host_name; my $local_host = $anvil->Get->short_host_name;
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results}; $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
@ -5850,7 +5850,7 @@ sub insert_or_update_hosts
my $line = defined $parameter->{line} ? $parameter->{line} : ""; my $line = defined $parameter->{line} ? $parameter->{line} : "";
my $host_ipmi = defined $parameter->{host_ipmi} ? $parameter->{host_ipmi} : ""; my $host_ipmi = defined $parameter->{host_ipmi} ? $parameter->{host_ipmi} : "";
my $host_key = defined $parameter->{host_key} ? $parameter->{host_key} : ""; my $host_key = defined $parameter->{host_key} ? $parameter->{host_key} : "";
my $host_name = defined $parameter->{host_name} ? $parameter->{host_name} : $anvil->_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;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
@ -7037,7 +7037,7 @@ WHERE
# Fill some data # Fill some data
if (not $mail_server_helo_domain) if (not $mail_server_helo_domain)
{ {
$mail_server_helo_domain = $anvil->_domain_name(); $mail_server_helo_domain = $anvil->Get->domain_name();
if (not $mail_server_helo_domain) if (not $mail_server_helo_domain)
{ {
# Fall back on 'localdomain' # Fall back on 'localdomain'
@ -11004,7 +11004,7 @@ sub locking
}}); }});
# These are used to ID this lock. # These are used to ID this lock.
my $source_name = $anvil->_host_name; my $source_name = $anvil->Get->host_name;
my $source_uuid = $anvil->data->{sys}{host_uuid}; my $source_uuid = $anvil->data->{sys}{host_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
source_name => $source_name, source_name => $source_name,
@ -11068,7 +11068,7 @@ sub locking
}}); }});
# Log that the lock has been released. # Log that the lock has been released.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0039", variables => { host => $anvil->_host_name }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0039", variables => { host => $anvil->Get->host_name }});
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { set => $set }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { set => $set }});
@ -11098,7 +11098,7 @@ sub locking
}}); }});
# Log that we've renewed the lock. # Log that we've renewed the lock.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0044", variables => { host => $anvil->_host_name }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0044", variables => { host => $anvil->Get->host_name }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { set => $set }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { set => $set }});
return($set); return($set);
@ -11187,7 +11187,7 @@ sub locking
}}); }});
# Log that we've got the lock. # Log that we've got the lock.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0045", variables => { host => $anvil->_host_name }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0045", variables => { host => $anvil->Get->host_name }});
} }
} }
@ -12671,7 +12671,7 @@ sub resync_databases
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0221", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0221", variables => {
to_write => $anvil->Convert->add_commas({number => $to_write_count}), to_write => $anvil->Convert->add_commas({number => $to_write_count}),
table => $table, table => $table,
host_name => $anvil->Get->host_name({host_uuid => $uuid}), host_name => $anvil->Get->host_name_from_uuid({host_uuid => $uuid}),
}}); }});
$anvil->Database->write({debug => $debug, uuid => $uuid, query => $merged, source => $THIS_FILE, line => __LINE__}); $anvil->Database->write({debug => $debug, uuid => $uuid, query => $merged, source => $THIS_FILE, line => __LINE__});
undef $merged; undef $merged;
@ -13421,7 +13421,7 @@ ORDER BY
# We've been asked to resync this DB. # We've been asked to resync this DB.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "log_0476", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "log_0476", variables => {
uuid => $uuid, uuid => $uuid,
host => $anvil->Get->host_name({host_uuid => $uuid}), host => $anvil->Get->host_name_from_uuid({host_uuid => $uuid}),
}}); }});
# Mark it as behind. # Mark it as behind.
@ -13459,7 +13459,7 @@ ORDER BY
seconds => $difference, seconds => $difference,
table => $table, table => $table,
uuid => $uuid, uuid => $uuid,
host => $anvil->Get->host_name({host_uuid => $uuid}), host => $anvil->Get->host_name_from_uuid({host_uuid => $uuid}),
}}); }});
# Mark it as behind. # Mark it as behind.
@ -13478,7 +13478,7 @@ ORDER BY
missing => $difference, missing => $difference,
table => $table, table => $table,
uuid => $uuid, uuid => $uuid,
host => $anvil->Get->host_name({host_uuid => $uuid}), host => $anvil->Get->host_name_from_uuid({host_uuid => $uuid}),
}}); }});
# Mark it as behind. # Mark it as behind.

@ -475,7 +475,7 @@ sub send_alerts
} }
# Build the emails now. # Build the emails now.
my $host_name = $anvil->_host_name; my $host_name = $anvil->Get->host_name;
foreach my $recipient_uuid (keys %{$anvil->data->{alerts}{queue}}) foreach my $recipient_uuid (keys %{$anvil->data->{alerts}{queue}})
{ {
my $recipient_name = $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_name}; my $recipient_name = $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_name};
@ -759,7 +759,7 @@ sub _configure_for_server
my $relayhost_seen = 0; my $relayhost_seen = 0;
my $relayhost_line = "relayhost = [".$mail_server_address."]:".$mail_server_port; my $relayhost_line = "relayhost = [".$mail_server_address."]:".$mail_server_port;
my $smtp_helo_name_seen = 0; my $smtp_helo_name_seen = 0;
my $smtp_helo_name_line = "smtp_helo_name = ".$anvil->_domain_name(); my $smtp_helo_name_line = "smtp_helo_name = ".$anvil->Get->domain_name();
my $smtp_use_tls_seen = 0; my $smtp_use_tls_seen = 0;
my $smtp_use_tls_line = "smtp_use_tls = yes"; my $smtp_use_tls_line = "smtp_use_tls = yes";
my $smtp_sasl_auth_enable_seen = 0; my $smtp_sasl_auth_enable_seen = 0;

@ -20,7 +20,10 @@ my $THIS_FILE = "Get.pm";
# bridges # bridges
# cgi # cgi
# date_and_time # date_and_time
# domain_name
# free_memory # free_memory
# host_name
# host_name_from_uuid
# host_type # host_type
# host_uuid # host_uuid
# md5sum # md5sum
@ -268,7 +271,7 @@ sub bridges
}}); }});
# Delete any previously known data # Delete any previously known data
my $host = $anvil->_short_host_name(); my $host = $anvil->Get->short_host_name();
if (exists $anvil->data->{$host}{network}{bridges}) if (exists $anvil->data->{$host}{network}{bridges})
{ {
delete $anvil->data->{$host}{network}{bridges}; delete $anvil->data->{$host}{network}{bridges};
@ -725,8 +728,59 @@ sub date_and_time
return($return_string); return($return_string);
} }
=head2 domain_name
This returns the domain name portion of the local system's host name. That is to say, the host name after the first C<< . >>. If there is no domain portion, nothing is returned.
This method takes no parameters.
=cut
sub domain_name
{
### NOTE: This method doesn't offer logging.
my $self = shift;
my $anvil = $self->parent;
my $domain_name = $anvil->Get->host_name;
$domain_name =~ s/^.*?\.//;
$domain_name = "" if not defined $domain_name;
return($domain_name);
}
=head2 host_name =head2 host_name
This returns the full host name for the local machine.
This method takes no parameters.
=cut
sub host_name
{
### NOTE: This method doesn't offer logging.
my $self = shift;
my $anvil = $self->parent;
my $host_name = "";
if ($ENV{HOSTNAME})
{
# We have an environment variable, so use it.
$host_name = $ENV{HOSTNAME};
}
else
{
# The environment variable isn't set. Call 'hostnamectl' on the command line.
($host_name, my $return_code) = $anvil->System->call({debug => 9999, shell_call => $anvil->data->{path}{exe}{hostnamectl}." --static"});
}
return($host_name);
}
=head2 host_name_from_uuid
This takes a host UUID and returns the host name (as recorded in the C<< hosts >> table). If the entry is not found, an empty string is returned. This takes a host UUID and returns the host name (as recorded in the C<< hosts >> table). If the entry is not found, an empty string is returned.
Parameters; Parameters;
@ -736,13 +790,13 @@ Parameters;
This is the C<< host_uuid >> to translate into a host name. This is the C<< host_uuid >> to translate into a host name.
=cut =cut
sub host_name sub host_name_from_uuid
{ {
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;
my $anvil = $self->parent; my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Get->host_name()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Get->host_name_from_uuid()" }});
my $host_name = ""; my $host_name = "";
my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : ""; my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : "";
@ -837,7 +891,7 @@ sub host_type
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Get->host_type()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Get->host_type()" }});
my $host_type = ""; my $host_type = "";
my $host_name = $anvil->_short_host_name; my $host_name = $anvil->Get->short_host_name;
$host_type = "unknown"; $host_type = "unknown";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_type => $host_type, host_type => $host_type,
@ -1147,6 +1201,27 @@ sub os_type
return($os_type, $os_arch); return($os_type, $os_arch);
} }
=head2 short_host_name
This returns the short host name for the machine this is running on. That is to say, the host name up to the first C<< . >>.
The method takes no parameters.
=cut
sub short_host_name
{
### NOTE: This method doesn't offer logging.
my $self = shift;
my $anvil = $self->parent;
my $short_host_name = $anvil->Get->host_name;
$short_host_name =~ s/\..*$//;
return($short_host_name);
}
=head2 switches =head2 switches
This reads in the command line switches used to invoke the parent program. This reads in the command line switches used to invoke the parent program.

@ -186,7 +186,7 @@ sub bridge_info
{ {
my $bridge = $hash_ref->{master}; my $bridge = $hash_ref->{master};
my $interface = $hash_ref->{ifname}; my $interface = $hash_ref->{ifname};
my $host = $target ? $target : $anvil->_short_host_name(); my $host = $target ? $target : $anvil->Get->short_host_name();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:bridge' => $bridge, 's1:bridge' => $bridge,
's2:interface' => $interface, 's2:interface' => $interface,
@ -1493,7 +1493,7 @@ sub get_ips
}}); }});
# This is used in the hash reference when storing the data. # This is used in the hash reference when storing the data.
my $host = $target ? $target : $anvil->_short_host_name(); my $host = $target ? $target : $anvil->Get->short_host_name();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }});
if (exists $anvil->data->{network}{$host}) if (exists $anvil->data->{network}{$host})
@ -1939,8 +1939,8 @@ sub is_local
} }
$anvil->data->{cache}{is_local}{$host} = 0; $anvil->data->{cache}{is_local}{$host} = 0;
if (($host eq $anvil->_host_name) or if (($host eq $anvil->Get->host_name) or
($host eq $anvil->_short_host_name) or ($host eq $anvil->Get->short_host_name) or
($host eq "localhost") or ($host eq "localhost") or
($host eq "127.0.0.1")) ($host eq "127.0.0.1"))
{ {
@ -1951,7 +1951,7 @@ sub is_local
else else
{ {
# Get the list of current IPs and see if they match. # Get the list of current IPs and see if they match.
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
if (not exists $anvil->data->{network}{$local_host}{interface}) if (not exists $anvil->data->{network}{$local_host}{interface})
{ {
$anvil->Network->get_ips({debug => 9999}); $anvil->Network->get_ips({debug => 9999});
@ -2349,7 +2349,7 @@ sub read_nmcli
if (not $host) if (not $host)
{ {
$host = $target ? $target : $anvil->_short_host_name(); $host = $target ? $target : $anvil->Get->short_host_name();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }});
} }

@ -313,7 +313,7 @@ sub call
}}); }});
# In case 'target' is our short host name, change it to ''. # In case 'target' is our short host name, change it to ''.
if ($target eq $anvil->_short_host_name()) if ($target eq $anvil->Get->short_host_name())
{ {
$target = ""; $target = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { target => $target }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { target => $target }});

@ -229,7 +229,7 @@ sub find
} }
my $host_type = $anvil->Get->host_type({debug => $debug}); my $host_type = $anvil->Get->host_type({debug => $debug});
my $host = $anvil->_host_name; my $host = $anvil->Get->host_name;
my $virsh_output = ""; my $virsh_output = "";
my $return_code = ""; my $return_code = "";
if ($anvil->Network->is_local({host => $target})) if ($anvil->Network->is_local({host => $target}))
@ -340,7 +340,7 @@ sub get_status
}}); }});
# This is used in the hash reference when storing the data. # This is used in the hash reference when storing the data.
my $host = $target ? $target : $anvil->_short_host_name(); my $host = $target ? $target : $anvil->Get->short_host_name();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }});
if (not $server) if (not $server)
@ -365,7 +365,7 @@ sub get_status
# Is this a local call or a remote call? # Is this a local call or a remote call?
my $shell_call = $anvil->data->{path}{exe}{virsh}." dumpxml ".$server; my $shell_call = $anvil->data->{path}{exe}{virsh}." dumpxml ".$server;
my $this_host = $anvil->_short_host_name; my $this_host = $anvil->Get->short_host_name;
if ($anvil->Network->is_local({host => $target})) if ($anvil->Network->is_local({host => $target}))
{ {
# Local. # Local.
@ -545,7 +545,7 @@ sub map_network
}); });
# This is used in the hash reference when storing the data. # This is used in the hash reference when storing the data.
my $host = $target ? $target : $anvil->_short_host_name(); my $host = $target ? $target : $anvil->Get->short_host_name();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }});
foreach my $mac (sort {$a cmp $b} keys %{$anvil->data->{server}{$host}{$server}{from_memory}{device}{interface}}) foreach my $mac (sort {$a cmp $b} keys %{$anvil->data->{server}{$host}{$server}{from_memory}{device}{interface}})
{ {
@ -628,7 +628,7 @@ sub migrate
my $server = defined $parameter->{server} ? $parameter->{server} : ""; my $server = defined $parameter->{server} ? $parameter->{server} : "";
my $source = defined $parameter->{source} ? $parameter->{source} : ""; my $source = defined $parameter->{source} ? $parameter->{source} : "";
my $target = defined $parameter->{target} ? $parameter->{target} : $anvil->_host_name; my $target = defined $parameter->{target} ? $parameter->{target} : $anvil->Get->host_name;
my $success = 0; my $success = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
server => $server, server => $server,
@ -981,8 +981,8 @@ sub _parse_definition
my $server = defined $parameter->{server} ? $parameter->{server} : ""; my $server = defined $parameter->{server} ? $parameter->{server} : "";
my $source = defined $parameter->{source} ? $parameter->{source} : ""; my $source = defined $parameter->{source} ? $parameter->{source} : "";
my $definition = defined $parameter->{definition} ? $parameter->{definition} : ""; my $definition = defined $parameter->{definition} ? $parameter->{definition} : "";
my $host = defined $parameter->{host} ? $parameter->{host} : $anvil->_short_host_name; my $host = defined $parameter->{host} ? $parameter->{host} : $anvil->Get->short_host_name;
my $target = $anvil->_short_host_name(); my $target = $anvil->Get->short_host_name();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
server => $server, server => $server,
source => $source, source => $source,

@ -523,7 +523,7 @@ sub get_local_repo
# What are my IPs? # What are my IPs?
$anvil->Network->get_ips(); $anvil->Network->get_ips();
my $base_url = ""; my $base_url = "";
my $host = $anvil->_short_host_name(); my $host = $anvil->Get->short_host_name();
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$host}{interface}}) foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$host}{interface}})
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { interface => $interface }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { interface => $interface }});
@ -547,8 +547,8 @@ sub get_local_repo
### - https://docs.fedoraproject.org/en-US/modularity/making-modules/defining-modules/ ### - https://docs.fedoraproject.org/en-US/modularity/making-modules/defining-modules/
### - https://docs.fedoraproject.org/en-US/modularity/hosting-modules/ ### - https://docs.fedoraproject.org/en-US/modularity/hosting-modules/
# Create the local repo file body # Create the local repo file body
my $repo = "[".$anvil->_short_host_name."-repo] my $repo = "[".$anvil->Get->short_host_name."-repo]
name=Repo on ".$anvil->_host_name." name=Repo on ".$anvil->Get->host_name."
".$base_url." ".$base_url."
enabled=1 enabled=1
gpgcheck=0 gpgcheck=0
@ -1130,7 +1130,7 @@ sub parse_all_status_json
# We're going to look for matches as we go, so look # We're going to look for matches as we go, so look
$anvil->Network->load_ips({ $anvil->Network->load_ips({
debug => $debug, debug => $debug,
host => $anvil->_short_host_name(), host => $anvil->Get->short_host_name(),
host_uuid => $anvil->data->{sys}{host_uuid}, host_uuid => $anvil->data->{sys}{host_uuid},
}); });
@ -1160,7 +1160,7 @@ sub parse_all_status_json
# Find what interface on this host we can use to talk to it (if we're not looking at ourselves). # Find what interface on this host we can use to talk to it (if we're not looking at ourselves).
my $matched_interface = ""; my $matched_interface = "";
my $matched_ip_address = ""; my $matched_ip_address = "";
if ($host_name ne $anvil->_host_name) if ($host_name ne $anvil->Get->host_name)
{ {
$anvil->Network->load_ips({ $anvil->Network->load_ips({
debug => $debug, debug => $debug,
@ -1169,7 +1169,7 @@ sub parse_all_status_json
}); });
my ($match) = $anvil->Network->find_matches({ my ($match) = $anvil->Network->find_matches({
debug => 3, debug => 3,
first => $anvil->_short_host_name(), first => $anvil->Get->short_host_name(),
second => $short_name, second => $short_name,
}); });
if ($match) if ($match)

@ -156,7 +156,7 @@ sub activate_lv
$anvil->System->check_storage({debug => $debug, scan => 2}); $anvil->System->check_storage({debug => $debug, scan => 2});
# Check if it worked. # Check if it worked.
my $host = $anvil->_short_host_name(); my $host = $anvil->Get->short_host_name();
$activated = $anvil->data->{lvm}{$host}{lv}{$path}{active}; $activated = $anvil->data->{lvm}{$host}{lv}{$path}{active};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { activated => $activated }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { activated => $activated }});
@ -1055,7 +1055,7 @@ sub check_storage
### DRBD devices being "wrong medium type" when Secondary. We check for and ignore these ### DRBD devices being "wrong medium type" when Secondary. We check for and ignore these
### warnings. ### warnings.
# Gather PV data. # Gather PV data.
my $host = $anvil->_short_host_name(); my $host = $anvil->Get->short_host_name();
my ($pvs_output, $pvs_return_code) = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{pvs}." --units b --noheadings --separator \\\#\\\!\\\# -o pv_name,vg_name,pv_fmt,pv_attr,pv_size,pv_free,pv_used,pv_uuid 2>/dev/null"}); my ($pvs_output, $pvs_return_code) = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{pvs}." --units b --noheadings --separator \\\#\\\!\\\# -o pv_name,vg_name,pv_fmt,pv_attr,pv_size,pv_free,pv_used,pv_uuid 2>/dev/null"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
pvs_output => $pvs_output, pvs_output => $pvs_output,
@ -1907,7 +1907,7 @@ sub generate_state_json
# We're going to look for matches as we go, so look # We're going to look for matches as we go, so look
$anvil->Network->load_ips({ $anvil->Network->load_ips({
debug => $debug, debug => $debug,
host => $anvil->_short_host_name(), host => $anvil->Get->short_host_name(),
host_uuid => $anvil->data->{sys}{host_uuid}, host_uuid => $anvil->data->{sys}{host_uuid},
}); });
@ -1940,12 +1940,12 @@ sub generate_state_json
# Find what interface on this host we can use to talk to it (if we're not looking at ourselves). # Find what interface on this host we can use to talk to it (if we're not looking at ourselves).
my $matched_interface = ""; my $matched_interface = "";
my $matched_ip_address = ""; my $matched_ip_address = "";
if ($host_name ne $anvil->_host_name) if ($host_name ne $anvil->Get->host_name)
{ {
# Don't need to call 'local_ips', it was called by load_interfaces above. # Don't need to call 'local_ips', it was called by load_interfaces above.
my ($match) = $anvil->Network->find_matches({ my ($match) = $anvil->Network->find_matches({
debug => $debug, debug => $debug,
first => $anvil->_short_host_name(), first => $anvil->Get->short_host_name(),
second => $short_host_name, second => $short_host_name,
}); });
@ -2383,7 +2383,7 @@ sub find_matching_ip
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }});
# Look through our IPs. First match wins. # Look through our IPs. First match wins.
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$local_host}{interface}}) foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$local_host}{interface}})
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { interface => $interface }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { interface => $interface }});

@ -900,7 +900,7 @@ WHERE
# If we don't have $helo_domain, use the host's domain # If we don't have $helo_domain, use the host's domain
if (not $helo_domain) if (not $helo_domain)
{ {
$helo_domain = $anvil->_domain_name(); $helo_domain = $anvil->Get->domain_name();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { helo_domain => $helo_domain }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { helo_domain => $helo_domain }});
} }
@ -2441,14 +2441,14 @@ sub handle_manifest
# Pre-load values # Pre-load values
if (not $anvil->data->{cgi}{prefix}{value}) if (not $anvil->data->{cgi}{prefix}{value})
{ {
$anvil->data->{cgi}{prefix}{value} = $anvil->_short_host_name() =~ /-/ ? $anvil->_short_host_name() : "xx"; $anvil->data->{cgi}{prefix}{value} = $anvil->Get->short_host_name() =~ /-/ ? $anvil->Get->short_host_name() : "xx";
$anvil->data->{cgi}{prefix}{value} =~ s/-.*$//; $anvil->data->{cgi}{prefix}{value} =~ s/-.*$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::prefix::value" => $anvil->data->{cgi}{prefix}{value} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::prefix::value" => $anvil->data->{cgi}{prefix}{value} }});
} }
if (not $anvil->data->{cgi}{domain}{value}) if (not $anvil->data->{cgi}{domain}{value})
{ {
$anvil->data->{cgi}{domain}{value} = $anvil->_host_name() =~ /\./ ? $anvil->_host_name() : "example.com"; $anvil->data->{cgi}{domain}{value} = $anvil->Get->host_name() =~ /\./ ? $anvil->Get->host_name() : "example.com";
$anvil->data->{cgi}{domain}{value} =~ s/^.*?\.//; $anvil->data->{cgi}{domain}{value} =~ s/^.*?\.//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::domain::value" => $anvil->data->{cgi}{domain}{value} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::domain::value" => $anvil->data->{cgi}{domain}{value} }});
} }
@ -5916,7 +5916,7 @@ sub process_prep_host_page
dr_checked => $dr_checked, dr_checked => $dr_checked,
}}); }});
my $host_name = $anvil->_host_name; my $host_name = $anvil->Get->host_name;
$host_name =~ s/striker\d\d/xxx/; $host_name =~ s/striker\d\d/xxx/;
my $default_host_name = $host_name; my $default_host_name = $host_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
@ -6194,7 +6194,7 @@ sub process_sync_page
# We'll want to show the user way to access the local machine. For that, we'll loop through our own IPs. # We'll want to show the user way to access the local machine. For that, we'll loop through our own IPs.
my $inbound_table = ""; my $inbound_table = "";
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$local_host}{interface}}) foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$local_host}{interface}})
{ {
next if (($interface !~ /^bcn/) && ($interface !~ /^ifn/)); next if (($interface !~ /^bcn/) && ($interface !~ /^ifn/));
@ -6314,7 +6314,7 @@ sub delete_sync_peer
my ($anvil) = @_; my ($anvil) = @_;
my $uuid = $anvil->data->{cgi}{'delete'}{value}; my $uuid = $anvil->data->{cgi}{'delete'}{value};
my $host_name = $anvil->Get->host_name({host_uuid => $uuid}); my $host_name = $anvil->Get->host_name_from_uuid({host_uuid => $uuid});
my $host = $anvil->data->{database}{$uuid}{host} ? $anvil->data->{database}{$uuid}{host} : ""; # This should fail my $host = $anvil->data->{database}{$uuid}{host} ? $anvil->data->{database}{$uuid}{host} : ""; # This should fail
my $name = $anvil->data->{database}{$uuid}{name} ? $anvil->data->{database}{$uuid}{name} : $anvil->data->{sys}{database}{name}; my $name = $anvil->data->{database}{$uuid}{name} ? $anvil->data->{database}{$uuid}{name} : $anvil->data->{sys}{database}{name};
my $user = $anvil->data->{database}{$uuid}{user} ? $anvil->data->{database}{$uuid}{user} : $anvil->data->{sys}{database}{user}; my $user = $anvil->data->{database}{$uuid}{user} ? $anvil->data->{database}{$uuid}{user} : $anvil->data->{sys}{database}{user};

@ -692,9 +692,9 @@ sub stop_drbd_resource
{ {
my ($anvil) = @_; my ($anvil) = @_;
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $server = $anvil->data->{environment}{OCF_RESKEY_name}; my $server = $anvil->data->{environment}{OCF_RESKEY_name};
my $host = $anvil->_short_host_name; my $host = $anvil->Get->short_host_name;
my $peer = $anvil->data->{drbd}{config}{$host}{peer}; my $peer = $anvil->data->{drbd}{config}{$host}{peer};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
server => $server, server => $server,
@ -737,9 +737,9 @@ sub start_drbd_resource
{ {
my ($anvil) = @_; my ($anvil) = @_;
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $server = $anvil->data->{environment}{OCF_RESKEY_name}; my $server = $anvil->data->{environment}{OCF_RESKEY_name};
my $host = $anvil->_short_host_name; my $host = $anvil->Get->short_host_name;
my $peer = $anvil->data->{drbd}{config}{$host}{peer}; my $peer = $anvil->data->{drbd}{config}{$host}{peer};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
server => $server, server => $server,
@ -875,7 +875,7 @@ sub find_server
my ($anvil) = @_; my ($anvil) = @_;
my $server = $anvil->data->{environment}{OCF_RESKEY_name}; my $server = $anvil->data->{environment}{OCF_RESKEY_name};
my $host = $anvil->_short_host_name; my $host = $anvil->Get->short_host_name;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0415", variables => { server => $server }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0415", variables => { server => $server }});
foreach my $ip_address (sort {$a cmp $b} keys %{$anvil->data->{drbd}{config}{$host}{ip_addresses}}) foreach my $ip_address (sort {$a cmp $b} keys %{$anvil->data->{drbd}{config}{$host}{ip_addresses}})
{ {
@ -908,7 +908,7 @@ sub find_server
host => $host, host => $host,
}}); }});
if ($host eq $anvil->_host_name) if ($host eq $anvil->Get->host_name)
{ {
# Already running, we're good, and we're done. # Already running, we're good, and we're done.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0416", variables => { server => $server }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0416", variables => { server => $server }});
@ -1173,7 +1173,7 @@ sub migrate_server
# missing. # missing.
# If we're given 'migrate_from', we're pulling the server towards us, so we can check both brdiges # If we're given 'migrate_from', we're pulling the server towards us, so we can check both brdiges
# and storage. # and storage.
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $server = $anvil->data->{environment}{OCF_RESKEY_name}; my $server = $anvil->data->{environment}{OCF_RESKEY_name};
my $source = $anvil->data->{environment}{OCF_RESKEY_CRM_meta_migrate_source}; my $source = $anvil->data->{environment}{OCF_RESKEY_CRM_meta_migrate_source};
my $target = $anvil->data->{environment}{OCF_RESKEY_CRM_meta_migrate_target}; my $target = $anvil->data->{environment}{OCF_RESKEY_CRM_meta_migrate_target};
@ -1269,7 +1269,7 @@ sub migrate_server
# Make sure all resource(s) are ready for the server. # Make sure all resource(s) are ready for the server.
my $all_up_to_date = 1; my $all_up_to_date = 1;
my $host = $anvil->_short_host_name; my $host = $anvil->Get->short_host_name;
my $peer_name = $anvil->data->{drbd}{config}{$host}{peer}; my $peer_name = $anvil->data->{drbd}{config}{$host}{peer};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
host => $host, host => $host,
@ -1394,7 +1394,7 @@ sub migrate_server
# This is called after a migration. If that is the case here, the target will be us. Just # This is called after a migration. If that is the case here, the target will be us. Just
# make sure it is running and, if so, return '0'. The 'meta_on_node' is the new host. # make sure it is running and, if so, return '0'. The 'meta_on_node' is the new host.
if (($target eq $anvil->_host_name) or ($target eq $anvil->_short_host_name) or ($target eq $meta_on_node)) if (($target eq $anvil->Get->host_name) or ($target eq $anvil->Get->short_host_name) or ($target eq $meta_on_node))
{ {
# If it's running, we're succesfully out. # If it's running, we're succesfully out.
if ((($host eq $target) or ($short_host eq $target)) && ($status eq "running")) if ((($host eq $target) or ($short_host eq $target)) && ($status eq "running"))
@ -1487,7 +1487,7 @@ sub validate_bridges
$anvil->Get->bridges({debug => 3}); $anvil->Get->bridges({debug => 3});
# Find the Optical drives and DRBD devices. # Find the Optical drives and DRBD devices.
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $server = $anvil->data->{environment}{OCF_RESKEY_name}; my $server = $anvil->data->{environment}{OCF_RESKEY_name};
foreach my $mac (sort {$a cmp $b} keys %{$anvil->data->{server}{$local_host}{$server}{from_disk}{device}{interface}}) foreach my $mac (sort {$a cmp $b} keys %{$anvil->data->{server}{$local_host}{$server}{from_disk}{device}{interface}})
{ {
@ -1534,7 +1534,7 @@ sub validate_storage
server => $server, server => $server,
target => $target, target => $target,
}}); }});
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $xml_source = "from_disk"; my $xml_source = "from_disk";
if ($anvil->data->{server}{$local_host}{$server}{from_memory}{host}) if ($anvil->data->{server}{$local_host}{$server}{from_memory}{host})
{ {
@ -1594,8 +1594,8 @@ sub validate_storage_drbd
# Now check storage. # Now check storage.
my $server = $anvil->data->{environment}{OCF_RESKEY_name}; my $server = $anvil->data->{environment}{OCF_RESKEY_name};
my $xml_source = "from_disk"; my $xml_source = "from_disk";
my $host = $anvil->_short_host_name; my $host = $anvil->Get->short_host_name;
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
# Did I find a resource for each disk? # Did I find a resource for each disk?
foreach my $device_path (sort {$a cmp $b} keys %{$anvil->data->{server}{$local_host}{$server}{device}}) foreach my $device_path (sort {$a cmp $b} keys %{$anvil->data->{server}{$local_host}{$server}{device}})
@ -1676,7 +1676,7 @@ sub validate_emulator
my ($anvil) = @_; my ($anvil) = @_;
# What emulator is this using? # What emulator is this using?
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $server = $anvil->data->{environment}{OCF_RESKEY_name}; my $server = $anvil->data->{environment}{OCF_RESKEY_name};
my $emulator = $anvil->data->{server}{$local_host}{$server}{from_disk}{info}{emulator}; my $emulator = $anvil->data->{server}{$local_host}{$server}{from_disk}{info}{emulator};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
@ -1708,7 +1708,7 @@ sub validate_name
{ {
my ($anvil) = @_; my ($anvil) = @_;
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $server = $anvil->data->{environment}{OCF_RESKEY_name}; my $server = $anvil->data->{environment}{OCF_RESKEY_name};
$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,
@ -1745,7 +1745,7 @@ sub validate_ram
my ($anvil) = @_; my ($anvil) = @_;
# How mcuh RAM does the server need and how much do we have free? # How mcuh RAM does the server need and how much do we have free?
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $server = $anvil->data->{environment}{OCF_RESKEY_name}; my $server = $anvil->data->{environment}{OCF_RESKEY_name};
my $server_ram_bytes = $anvil->data->{server}{$local_host}{$server}{from_disk}{memory}; my $server_ram_bytes = $anvil->data->{server}{$local_host}{$server}{from_disk}{memory};
my $available = $anvil->Get->free_memory({debug => 3}); my $available = $anvil->Get->free_memory({debug => 3});

@ -2,6 +2,9 @@
# #
# This scans the cluster by processing the CIB and storing information about nodes, cluster states, etc. # This scans the cluster by processing the CIB and storing information about nodes, cluster states, etc.
# #
# NOTE: The data stored here is not bound to a given host. As such, node 1 will run this agent and node 2
# won't, _except_ when node 1 is offline and only node 2 is up.
#
# Examples; # Examples;
# #
# Exit codes; # Exit codes;
@ -89,9 +92,33 @@ sub collect_data
my ($anvil) = @_; my ($anvil) = @_;
# Pick out core cluster details. # Pick out core cluster details.
# my $stonith_enabled = $anvil->data->{cib}{parsed}{configuration}{crm_config}{cluster_property_set}{nvpair}{ my $problem = $anvil->Cluster->parse_cib({debug => 2});
# my $maintenance_mode = $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { offline => $offline }});
# my $no_quorum_policy =
my $cluster_name = $anvil->data->{cib}{parsed}{data}{cluster}{name};
my $stonith_enabled = $anvil->data->{cib}{parsed}{data}{stonith}{enabled};
my $maintenance_mode = $anvil->data->{cib}{parsed}{data}{cluster}{'maintenance-mode'};
my $stonith_max_attempts = $anvil->data->{cib}{parsed}{data}{cluster}{'stonith-max-attempts'};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
cluster_name => $cluster_name,
stonith_enabled => $stonith_enabled,
maintenance_mode => $maintenance_mode,
stonith_max_attempts => $stonith_max_attempts,
}});
### TODO: If we're node 2, or not in the cluster, only update our information in the
### 'scan_cluster_nodes' table. Node 1 will update everything else if it's 'ready' (else node 2
### will, if it's ready)
my $ready = $anvil->data->{cib}{parsed}{data}{node}{$node_name}{node_state}{ready};
if ($stonith_max_attempts ne "INFINITY")
{
### TODO: Call pcs to update
}
# Pick up node data
return(0); return(0);

@ -1,11 +1,69 @@
-- This is the database schema for the 'scan-cluster Scan Agent'. -- This is the database schema for the 'scan-cluster Scan Agent'.
--
-- NOTE: This agent is not host-bound. It's update by node 1 if it's in the cluster, else by node 2 if it's
-- the only one online.
CREATE TABLE scan_cluster ( CREATE TABLE scan_cluster (
scan_cluster_uuid uuid primary key, scan_cluster_uuid uuid primary key,
scan_cluster_host_uuid uuid not null, scan_cluster_name text not null, -- The name of the cluster
scan_cluster_stonith_enabled boolean not null, -- Tracks when stonith (fencing) was enabled/disabled scan_cluster_stonith_enabled boolean not null, -- Tracks when stonith (fencing) was enabled/disabled
scan_cluster_maintenance_mode boolean not null, -- Tracks when maintenance mode is enabled/disabled. scan_cluster_maintenance_mode boolean not null, -- Tracks when maintenance mode is enabled/disabled.
scan_cluster_no_quorum_policy text not null, -- Tracks what is done when quorum is lost. modified_date timestamp with time zone not null,
FOREIGN KEY(scan_cluster_host_uuid) REFERENCES hosts(host_uuid)
);
ALTER TABLE scan_cluster OWNER TO admin;
CREATE TABLE history.scan_cluster (
history_id bigserial,
scan_cluster_uuid uuid,
scan_cluster_name text,
scan_cluster_stonith_enabled boolean,
scan_cluster_maintenance_mode boolean,
modified_date timestamp with time zone not null
);
ALTER TABLE history.scan_cluster OWNER TO admin;
CREATE FUNCTION history_scan_cluster() RETURNS trigger
AS $$
DECLARE
history_scan_cluster RECORD;
BEGIN
SELECT INTO history_scan_cluster * FROM scan_cluster WHERE scan_cluster_uuid=new.scan_cluster_uuid;
INSERT INTO history.scan_cluster
(scan_cluster_uuid,
scan_cluster_name,
scan_cluster_stonith_enabled,
scan_cluster_maintenance_mode,
modified_date)
VALUES
(history_scan_cluster.scan_cluster_uuid,
history_scan_cluster.scan_cluster_host_uuid,
history_scan_cluster.scan_cluster_name,
history_scan_cluster.scan_cluster_stonith_enabled,
history_scan_cluster.scan_cluster_maintenance_mode,
history_scan_cluster.modified_date);
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
ALTER FUNCTION history_scan_cluster() OWNER TO admin;
CREATE TRIGGER trigger_scan_cluster
AFTER INSERT OR UPDATE ON scan_cluster
FOR EACH ROW EXECUTE PROCEDURE history_scan_cluster();
CREATE TABLE scan_cluster_nodes (
scan_cluster_node_uuid uuid primary key,
scan_cluster_node_host_uuid uuid not null, -- This is the host UUID of the node.
scan_cluster_node_name text not null, -- This is the host name as reported by pacemaker. It _should_ match up to a host name in 'hosts'.
scan_cluster_node_pacemaker_id numeric not null, -- This is the internal pacemaker ID number of this node.
my $node_id = $anvil->data->{cib}{parsed}{data}{node}{$node_name}{id};
my $in_ccm = $anvil->data->{cib}{parsed}{cib}{node_state}{$node_id}{in_ccm} eq "true" ? 1 : 0; # 'true' or 'false' - Corosync member
my $crmd = $anvil->data->{cib}{parsed}{cib}{node_state}{$node_id}{crmd} eq "online" ? 1 : 0; # 'online' or 'offline' - In corosync process group
my $join = $anvil->data->{cib}{parsed}{cib}{node_state}{$node_id}{'join'} eq "member" ? 1 : 0; # 'member' or 'down' - Completed controller join process
modified_date timestamp with time zone not null, modified_date timestamp with time zone not null,
FOREIGN KEY(scan_cluster_host_uuid) REFERENCES hosts(host_uuid) FOREIGN KEY(scan_cluster_host_uuid) REFERENCES hosts(host_uuid)
@ -16,6 +74,9 @@ CREATE TABLE history.scan_cluster (
history_id bigserial, history_id bigserial,
scan_cluster_uuid uuid, scan_cluster_uuid uuid,
scan_cluster_host_uuid uuid, scan_cluster_host_uuid uuid,
scan_cluster_node_name text,
scan_cluster_stonith_enabled boolean,
scan_cluster_maintenance_mode boolean,
modified_date timestamp with time zone not null modified_date timestamp with time zone not null
); );
ALTER TABLE history.scan_cluster OWNER TO admin; ALTER TABLE history.scan_cluster OWNER TO admin;
@ -29,10 +90,16 @@ BEGIN
INSERT INTO history.scan_cluster INSERT INTO history.scan_cluster
(scan_cluster_uuid, (scan_cluster_uuid,
scan_cluster_host_uuid, scan_cluster_host_uuid,
scan_cluster_name,
scan_cluster_stonith_enabled,
scan_cluster_maintenance_mode,
modified_date) modified_date)
VALUES VALUES
(history_scan_cluster.scan_cluster_uuid, (history_scan_cluster.scan_cluster_uuid,
history_scan_cluster.scan_cluster_host_uuid, history_scan_cluster.scan_cluster_host_uuid,
history_scan_cluster.scan_cluster_name,
history_scan_cluster.scan_cluster_stonith_enabled,
history_scan_cluster.scan_cluster_maintenance_mode,
history_scan_cluster.modified_date); history_scan_cluster.modified_date);
RETURN NULL; RETURN NULL;
END; END;
@ -43,3 +110,4 @@ ALTER FUNCTION history_scan_cluster() OWNER TO admin;
CREATE TRIGGER trigger_scan_cluster CREATE TRIGGER trigger_scan_cluster
AFTER INSERT OR UPDATE ON scan_cluster AFTER INSERT OR UPDATE ON scan_cluster
FOR EACH ROW EXECUTE PROCEDURE history_scan_cluster(); FOR EACH ROW EXECUTE PROCEDURE history_scan_cluster();

@ -165,7 +165,7 @@ sub reconfigure_network
{ {
my ($anvil) = @_; my ($anvil) = @_;
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $reboot_needed = 0; my $reboot_needed = 0;
my $prefix = exists $anvil->data->{variables}{form}{config_step1}{prefix}{value} ? $anvil->data->{variables}{form}{config_step1}{prefix}{value} : ""; my $prefix = exists $anvil->data->{variables}{form}{config_step1}{prefix}{value} ? $anvil->data->{variables}{form}{config_step1}{prefix}{value} : "";
my $sequence = exists $anvil->data->{variables}{form}{config_step1}{sequence}{value} ? $anvil->data->{variables}{form}{config_step1}{sequence}{value} : ""; my $sequence = exists $anvil->data->{variables}{form}{config_step1}{sequence}{value} ? $anvil->data->{variables}{form}{config_step1}{sequence}{value} : "";

@ -1068,12 +1068,12 @@ sub check_local_network
my ($anvil) = @_; my ($anvil) = @_;
# What host name and IP(s) should I have? # What host name and IP(s) should I have?
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $machine = $anvil->data->{sys}{machine}; my $machine = $anvil->data->{sys}{machine};
my $manifest_uuid = $anvil->data->{sys}{manifest_uuid}; my $manifest_uuid = $anvil->data->{sys}{manifest_uuid};
my $domain = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{domain}; my $domain = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{domain};
my $old_host_name = $anvil->_host_name; my $old_host_name = $anvil->Get->host_name;
my $new_host_name = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{machine}{$machine}{name}; my $new_host_name = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{machine}{$machine}{name};
if ($domain) if ($domain)
{ {

@ -243,7 +243,7 @@ sub find_file
my $found = 0; my $found = 0;
# What are my IPs? # What are my IPs?
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
$anvil->Network->get_ips(); $anvil->Network->get_ips();
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$local_host}{interface}}) foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$local_host}{interface}})
{ {

@ -104,7 +104,7 @@ sub check_initial_setup
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "firewall::default_zone" => $anvil->data->{firewall}{default_zone} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "firewall::default_zone" => $anvil->data->{firewall}{default_zone} }});
my $internet_zone = ""; my $internet_zone = "";
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$local_host}{interface}}) foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$local_host}{interface}})
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { interface => $interface }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { interface => $interface }});

@ -127,7 +127,7 @@ sub update_network
# We'll read through '/sys/class/net' looking for network interfaces. # We'll read through '/sys/class/net' looking for network interfaces.
# * 'network::${local_host}::interface::<iface_name>::ip' - If an IP address is set # * 'network::${local_host}::interface::<iface_name>::ip' - If an IP address is set
# * 'network::${local_host}::interface::<iface_name>::subnet_mask' - If an IP is set # * 'network::${local_host}::interface::<iface_name>::subnet_mask' - If an IP is set
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my $directory = "/sys/class/net"; my $directory = "/sys/class/net";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { directory => $directory }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { directory => $directory }});

@ -147,7 +147,7 @@ sub add_databases
password => $anvil->data->{data}{password}, password => $anvil->data->{data}{password},
port => $anvil->data->{data}{ssh_port}, port => $anvil->data->{data}{ssh_port},
}); });
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
my ($match) = $anvil->Network->find_matches({ my ($match) = $anvil->Network->find_matches({
debug => 3, debug => 3,
first => $local_host, first => $local_host,
@ -347,7 +347,7 @@ sub add_repos
# NOTE: We can't use Storage->write_file() because the target may not have 'rsync' installed # NOTE: We can't use Storage->write_file() because the target may not have 'rsync' installed
# yet. # yet.
my $shell_call = " my $shell_call = "
".$anvil->data->{path}{exe}{cat}." > /etc/yum.repos.d/".$anvil->_short_host_name.".repo << EOF ".$anvil->data->{path}{exe}{cat}." > /etc/yum.repos.d/".$anvil->Get->short_host_name.".repo << EOF
$repo $repo
EOF EOF
"; ";

@ -456,7 +456,7 @@ sub setup_boot_environment
# Get my BCN IP and active OS. # Get my BCN IP and active OS.
$anvil->Network->get_ips(); $anvil->Network->get_ips();
my $bcn_interface = ""; my $bcn_interface = "";
my $local_host = $anvil->_short_host_name(); my $local_host = $anvil->Get->short_host_name();
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$local_host}{interface}}) foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$local_host}{interface}})
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { interface => $interface }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { interface => $interface }});
@ -485,9 +485,9 @@ sub setup_boot_environment
my $dns = $anvil->data->{network}{$local_host}{interface}{$bcn_interface}{dns} ? $anvil->data->{network}{$local_host}{interface}{$bcn_interface}{dns} : $anvil->data->{defaults}{network}{dns}; my $dns = $anvil->data->{network}{$local_host}{interface}{$bcn_interface}{dns} ? $anvil->data->{network}{$local_host}{interface}{$bcn_interface}{dns} : $anvil->data->{defaults}{network}{dns};
my $domain = "localdomain"; my $domain = "localdomain";
my $base_url = "http://".$bcn_ip."/".$anvil->data->{host_os}{os_type}."/".$anvil->data->{host_os}{os_arch}; my $base_url = "http://".$bcn_ip."/".$anvil->data->{host_os}{os_type}."/".$anvil->data->{host_os}{os_arch};
if ($anvil->_host_name =~ /\./) if ($anvil->Get->host_name =~ /\./)
{ {
$domain = $anvil->_host_name; $domain = $anvil->Get->host_name;
$domain =~ s/^.*?\.//; $domain =~ s/^.*?\.//;
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
@ -502,7 +502,7 @@ sub setup_boot_environment
### NOTE: The DNS range is a bit tricky, so for now, we'll assume that the BCN is always a /16 ### NOTE: The DNS range is a bit tricky, so for now, we'll assume that the BCN is always a /16
### network. Someday this might change, and if so, we'll need to make this a lot smarter. ### network. Someday this might change, and if so, we'll need to make this a lot smarter.
my $striker_number = ($anvil->_short_host_name =~ /striker(\d+)/)[0]; my $striker_number = ($anvil->Get->short_host_name =~ /striker(\d+)/)[0];
$striker_number = 1 if not $striker_number; $striker_number = 1 if not $striker_number;
$striker_number =~ s/^0//; $striker_number =~ s/^0//;
my $third_octet = (10 * $striker_number) + 4; my $third_octet = (10 * $striker_number) + 4;
@ -617,9 +617,9 @@ sub setup_boot_environment
### TODO: Add repos for all known strikers ### TODO: Add repos for all known strikers
# Build the repository file body. # Build the repository file body.
my $repo_file = "/etc/yum.repos.d/".$anvil->_short_host_name.".repo"; my $repo_file = "/etc/yum.repos.d/".$anvil->Get->short_host_name.".repo";
my $repo_body = "[".$anvil->_short_host_name."-repo]\n"; my $repo_body = "[".$anvil->Get->short_host_name."-repo]\n";
$repo_body .= "name=".$anvil->_host_name." #!string!message_0153!#\n"; $repo_body .= "name=".$anvil->Get->host_name." #!string!message_0153!#\n";
# Add the IPs. # Add the IPs.
$anvil->Network->get_ips({}); $anvil->Network->get_ips({});
my $first_line = 1; my $first_line = 1;

@ -548,7 +548,7 @@ sub process_entry
my $peer_connected = 0; my $peer_connected = 0;
until($peer_connected) until($peer_connected)
{ {
my $say_host = $anvil->Get->host_name({host_uuid => $host_uuid}); my $say_host = $anvil->Get->host_name_from_uuid({host_uuid => $host_uuid});
$say_host = $host_uuid if not $say_host; $say_host = $host_uuid if not $say_host;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
say_host => $say_host, say_host => $say_host,

Loading…
Cancel
Save