* Fixed tools/striker-initialize-host so that it set the hostname on the target, not locally.

* Updated System->host_name to work locally and on remote targets.
* Renamed all 'hostname' instances to 'host_name' to standardize on a spelling throughout the program.
* Removed use of and dependency on 'hostname'.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 5 years ago
parent b57546e663
commit 3a86bed694
  1. 25
      Anvil/Tools.pm
  2. 18
      Anvil/Tools/Convert.pm
  3. 22
      Anvil/Tools/DRBD.pm
  4. 14
      Anvil/Tools/Database.pm
  5. 2
      Anvil/Tools/Network.pm
  6. 6
      Anvil/Tools/Remote.pm
  7. 10
      Anvil/Tools/Server.pm
  8. 4
      Anvil/Tools/Striker.pm
  9. 183
      Anvil/Tools/System.pm
  10. 40
      cgi-bin/striker
  11. 4
      html/skins/alteeve/config.html
  12. 2
      html/skins/alteeve/pxe.txt
  13. 14
      ocf/alteeve/server
  14. 4
      share/words.xml
  15. 28
      tools/anvil-configure-host
  16. 8
      tools/anvil-daemon
  17. 15
      tools/striker-initialize-host
  18. 11
      tools/striker-manage-install-target

@ -26,11 +26,11 @@ my $THIS_FILE = "Tools.pm";
# refresh
# _add_hash_reference
# _anvil_version
# _hostname
# _host_name
# _make_hash_reference
# _set_defaults
# _set_paths
# _short_hostname
# _short_host_name
use utf8;
binmode(STDERR, ':encoding(utf-8)');
@ -701,29 +701,29 @@ sub _anvil_version
return($anvil->{HOST}{ANVIL_VERSION});
}
=head2 _hostname
=head2 _host_name
This returns the (full) host name for the machine this is running on.
=cut
sub _hostname
sub _host_name
{
my $self = shift;
my $anvil = $self;
my $hostname = "";
my $host_name = "";
if ($ENV{HOSTNAME})
{
# We have an environment variable, so use it.
$hostname = $ENV{HOSTNAME};
$host_name = $ENV{HOSTNAME};
}
else
{
# The environment variable isn't set. Call 'hostname' on the command line.
($hostname, my $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{hostname}});
# The environment variable isn't set. Call 'hostnamectl' on the command line.
($host_name, my $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{hostnamectl}." --static"});
}
return($hostname);
return($host_name);
}
=head2 _get_hash_reference
@ -1092,7 +1092,6 @@ sub _set_paths
gethostip => "/usr/bin/gethostip",
'grep' => "/usr/bin/grep",
head => "/usr/bin/head",
hostname => "/usr/bin/hostname",
hostnamectl => "/usr/bin/hostnamectl",
htpasswd => "/usr/bin/htpasswd",
ifdown => "/sbin/ifdown",
@ -1201,17 +1200,17 @@ sub _set_paths
return(0);
}
=head3 _short_hostname
=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_hostname
sub _short_host_name
{
my $self = shift;
my $anvil = $self;
my $short_host_name = $anvil->_hostname;
my $short_host_name = $anvil->_host_name;
$short_host_name =~ s/\..*$//;
return($short_host_name);

@ -15,7 +15,7 @@ my $THIS_FILE = "Convert.pm";
# add_commas
# bytes_to_human_readable
# cidr
# hostname_to_ip
# host_name_to_ip
# human_readable_to_bytes
# round
# time
@ -605,38 +605,38 @@ sub cidr
return($output);
}
=head2 hostname_to_ip
=head2 host_name_to_ip
This method takes a host name and tries to convert it to an IP address. If it fails, it will return C<< 0 >>.
Parameters;
=head3 hostname
=head3 host_name
This is the host name (or domain name) to try and convert to an IP address.
=cut
sub hostname_to_ip
sub host_name_to_ip
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $hostname = defined $parameter->{hostname} ? $parameter->{hostname} : "";
my $host_name = defined $parameter->{host_name} ? $parameter->{host_name} : "";
my $ip = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { hostname => $hostname }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_name => $host_name }});
if (not $hostname)
if (not $host_name)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Convert->hostname_to_ip()", parameter => "hostnmae" }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Convert->host_name_to_ip()", parameter => "host_name" }});
return($ip);
}
### TODO: Check local cached information later.
# Try to resolve it using 'gethostip'.
my $output = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{gethostip}." -d $hostname"});
my $output = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{gethostip}." -d $host_name"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output }});
foreach my $line (split/\n/, $output)
{

@ -105,7 +105,7 @@ This is the IP or host name of the machine to read the version of. If this is no
=head3 target_node_id (optional, but see condition below)
This is the DRBD target node's (connection) ID that we're enabling dual-primary with. If this is not passed, but C<< drbd::status::<local_short_hostname>::resource::<resource>::connection::<peer_name>::peer-node-id >> is set, it will be used. Otherwise this argument is required.
This is the DRBD target node's (connection) ID that we're enabling dual-primary with. If this is not passed, but C<< drbd::status::<local_short_host_name>::resource::<resource>::connection::<peer_name>::peer-node-id >> is set, it will be used. Otherwise this argument is required.
=cut
sub allow_two_primaries
@ -138,7 +138,7 @@ sub allow_two_primaries
}
# Do we need to scan devices?
my $host = $anvil->_short_hostname;
my $host = $anvil->_short_host_name;
if (not $anvil->data->{drbd}{config}{$host}{peer})
{
# Get our device list.
@ -270,7 +270,7 @@ sub get_devices
}});
# Is this a local call or a remote call?
my $host = $anvil->_short_hostname;
my $host = $anvil->_short_host_name;
my $shell_call = $anvil->data->{path}{exe}{drbdadm}." dump-xml";
my $output = "";
if ($anvil->Network->is_remote($target))
@ -396,10 +396,10 @@ sub get_devices
my $this_host = $host_href->{name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
this_host => $this_host,
'$anvil->_hostname' => $anvil->_hostname,
'$anvil->_short_hostname' => $anvil->_short_hostname,
'$anvil->_host_name' => $anvil->_host_name,
'$anvil->_short_host_name' => $anvil->_short_host_name,
}});
if (($this_host eq $anvil->_hostname) or ($this_host eq $anvil->_short_hostname))
if (($this_host eq $anvil->_host_name) or ($this_host eq $anvil->_short_host_name))
{
$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} }});
@ -494,11 +494,11 @@ sub get_devices
This parses the DRBD status on the local or remote system. The data collected is stored in the following hashes;
- drbd::status::<hostname>::resource::<resource_name>::{ap-in-flight,congested,connection-state,peer-node-id,rs-in-flight}
- drbd::status::<hostname>::resource::<resource_name>::connection::<peer_hostname>::volume::<volume>::{has-online-verify-details,has-sync-details,out-of-sync,peer-client,peer-disk-state,pending,percent-in-sync,received,replication-state,resync-suspended,sent,unacked}
- drbd::status::<host_name>::resource::<resource_name>::{ap-in-flight,congested,connection-state,peer-node-id,rs-in-flight}
- drbd::status::<host_name>::resource::<resource_name>::connection::<peer_host_name>::volume::<volume>::{has-online-verify-details,has-sync-details,out-of-sync,peer-client,peer-disk-state,pending,percent-in-sync,received,replication-state,resync-suspended,sent,unacked}
- # If the volume is resyncing, these additional values will be set:
- drbd::status::<hostname>::resource::<resource_name>::connection::<peer_hostname>::volume::<volume>::{db-dt MiB-s,db0-dt0 MiB-s,db1-dt1 MiB-s,estimated-seconds-to-finish,percent-resync-done,rs-db0-sectors,rs-db1-sectors,rs-dt-start-ms,rs-dt0-ms,rs-dt1-ms,rs-failed,rs-paused-ms,rs-same-csum,rs-total,want}
- drbd::status::<hostname>::resource::<resource>::devices::volume::<volume>::{al-writes,bm-writes,client,disk-state,lower-pending,minor,quorum,read,size,upper-pending,written}
- drbd::status::<host_name>::resource::<resource_name>::connection::<peer_host_name>::volume::<volume>::{db-dt MiB-s,db0-dt0 MiB-s,db1-dt1 MiB-s,estimated-seconds-to-finish,percent-resync-done,rs-db0-sectors,rs-db1-sectors,rs-dt-start-ms,rs-dt0-ms,rs-dt1-ms,rs-failed,rs-paused-ms,rs-same-csum,rs-total,want}
- drbd::status::<host_name>::resource::<resource>::devices::volume::<volume>::{al-writes,bm-writes,client,disk-state,lower-pending,minor,quorum,read,size,upper-pending,written}
If any data for the host was stored in a previous call, it will be deleted before the new data is collected and stored.
@ -543,7 +543,7 @@ sub get_status
# Is this a local call or a remote call?
my $shell_call = $anvil->data->{path}{exe}{drbdsetup}." status --json";
my $output = "";
my $host = $anvil->_short_hostname();
my $host = $anvil->_short_host_name();
if ($anvil->Network->is_remote($target))
{
# Clear the hash where we'll store the data.

@ -1021,8 +1021,8 @@ sub connect
# Set the first ID to be the one I read from later. Alternatively, if this host is
# local, use it.
if (($host eq $anvil->_hostname) or
($host eq $anvil->_short_hostname) or
if (($host eq $anvil->_host_name) or
($host eq $anvil->_short_host_name) or
($host eq "localhost") or
($host eq "127.0.0.1") or
(not $anvil->data->{sys}{database}{read_uuid}))
@ -3085,7 +3085,7 @@ sub insert_or_update_hosts
my $file = defined $parameter->{file} ? $parameter->{file} : "";
my $line = defined $parameter->{line} ? $parameter->{line} : "";
my $host_key = defined $parameter->{host_key} ? $parameter->{host_key} : "";
my $host_name = defined $parameter->{host_name} ? $parameter->{host_name} : $anvil->_hostname;
my $host_name = defined $parameter->{host_name} ? $parameter->{host_name} : $anvil->_host_name;
my $host_type = defined $parameter->{host_type} ? $parameter->{host_type} : $anvil->System->get_host_type;
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 => {
@ -5457,7 +5457,7 @@ sub locking
}});
# These are used to ID this lock.
my $source_name = $anvil->_hostname;
my $source_name = $anvil->_host_name;
my $source_uuid = $anvil->data->{sys}{host_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
source_name => $source_name,
@ -5521,7 +5521,7 @@ sub locking
}});
# Log that the lock has been released.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0039", variables => { host => $anvil->_hostname }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0039", variables => { host => $anvil->_host_name }});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { set => $set }});
@ -5551,7 +5551,7 @@ sub locking
}});
# Log that we've renewed the lock.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0044", variables => { host => $anvil->_hostname }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0044", variables => { host => $anvil->_host_name }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { set => $set }});
return($set);
@ -5640,7 +5640,7 @@ sub locking
}});
# Log that we've got the lock.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0045", variables => { host => $anvil->_hostname }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0045", variables => { host => $anvil->_host_name }});
}
}

@ -654,7 +654,7 @@ sub is_remote
my $anvil = $self->parent;
my $remote = 0;
if (($target) && ($target ne "local") && ($target ne $anvil->_hostname) && ($target ne $anvil->_short_hostname))
if (($target) && ($target ne "local") && ($target ne $anvil->_host_name) && ($target ne $anvil->_short_host_name))
{
# It's a remote system
$remote = 1;

@ -187,12 +187,12 @@ This does a remote call over SSH. The connection is held open and the file handl
Example;
# Call 'hostname' on a node.
# Call 'hostnamectl' on a node.
my ($output, $error, $return_code) = $anvil->Remote->call({
target => "an-a01n01.alteeve.com",
password => "super secret password",
remote_user => "admin",
shell_call => "/usr/bin/hostname",
shell_call => "/usr/bin/hostnamectl",
});
# Make a call with sensitive data that you want logged only if $anvil->Log->secure is set and close the
@ -390,7 +390,7 @@ sub call
# If the target is a host name, convert it to an IP.
if (not $anvil->Validate->is_ipv4({ip => $target}))
{
my $new_target = $anvil->Convert->hostname_to_ip({hostname => $target});
my $new_target = $anvil->Convert->host_name_to_ip({host_name => $target});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_target => $new_target }});
if ($new_target)
{

@ -174,7 +174,7 @@ This will look on the local or a remote machine for the list of servers that are
The list is stored as;
server::location::<server>::status = <status>
server::location::<server>::host = <hostname>
server::location::<server>::host = <host_name>
Parameters;
@ -226,7 +226,7 @@ sub find
}
my $host_type = $anvil->System->get_host_type({debug => $debug});
my $host = $anvil->_hostname;
my $host = $anvil->_host_name;
my $virsh_output = "";
my $return_code = "";
if ($anvil->Network->is_remote($target))
@ -356,7 +356,7 @@ sub get_status
# Is this a local call or a remote call?
my $shell_call = $anvil->data->{path}{exe}{virsh}." dumpxml ".$server;
my $host = $anvil->_short_hostname;
my $host = $anvil->_short_host_name;
if ($anvil->Network->is_remote($target))
{
# Remote call.
@ -676,7 +676,7 @@ sub migrate
my $server = defined $parameter->{server} ? $parameter->{server} : "";
my $source = defined $parameter->{source} ? $parameter->{source} : "";
my $target = defined $parameter->{target} ? $parameter->{target} : $anvil->_hostname;
my $target = defined $parameter->{target} ? $parameter->{target} : $anvil->_host_name;
my $success = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
server => $server,
@ -763,7 +763,7 @@ sub _parse_definition
my $server = defined $parameter->{server} ? $parameter->{server} : "";
my $source = defined $parameter->{source} ? $parameter->{source} : "";
my $definition = defined $parameter->{definition} ? $parameter->{definition} : "";
my $host = defined $parameter->{host} ? $parameter->{host} : $anvil->_short_hostname;
my $host = defined $parameter->{host} ? $parameter->{host} : $anvil->_short_host_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
server => $server,
source => $source,

@ -155,8 +155,8 @@ sub get_local_repo
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { base_url => $base_url }});
# Create the local repo file body
my $repo = "[".$anvil->_short_hostname."-repo]
name=Repo on ".$anvil->_hostname."
my $repo = "[".$anvil->_short_host_name."-repo]
name=Repo on ".$anvil->_host_name."
".$base_url."
enabled=1
gpgcheck=0

@ -29,7 +29,7 @@ my $THIS_FILE = "System.pm";
# find_matching_ip
# get_uptime
# get_os_type
# hostname
# host_name
# is_local
# maintenance_mode
# manage_firewall
@ -65,7 +65,7 @@ Provides all methods related to storage on a system.
# Access to methods using '$anvil->System->X'.
#
# Example using 'system_call()';
my ($hostname, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{hostname}});
my ($host_name, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{hostnamectl}." --static"});
=head1 METHODS
@ -164,7 +164,7 @@ sub activate_lv
This method makes a system call and returns the output (with the last new-line removed) and the return code. If there is a problem, 'C<< #!error!# >>' is returned and the error will be logged.
my ($output, $return_code) = $anvil->System->call({shell_call => "hostname"});
my ($output, $return_code) = $anvil->System->call({shell_call => "host_name"});
Parameters;
@ -949,7 +949,7 @@ sub get_host_type
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->get_host_type()" }});
my $host_type = "";
my $host_name = $anvil->_short_hostname;
my $host_name = $anvil->_short_host_name;
$host_type = "unknown";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_type => $host_type,
@ -1053,7 +1053,7 @@ sub find_matching_ip
if (not $anvil->Validate->is_ipv4({ip => $host}))
{
# This will be '0' if it failed, and pre-validated if it returns an IP.
$host = $anvil->Convert->hostname_to_ip({hostname => $host});
$host = $anvil->Convert->host_name_to_ip({host_name => $host});
if (not $host)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "log_0211", variables => { host => $parameter->{host} }});
@ -1192,56 +1192,102 @@ sub get_os_type
return($os_type, $os_arch);
}
=head2 hostname
=head2 host_name
Get or set the local host name. The current (or new) "static" (traditional) host name and the "pretty" (descriptive) host names are returned.
# Get the current host name.
my ($traditional_hostname, $descriptive_hostname) = $anvil->System->hostname();
my ($traditional_host_name, $descriptive_host_name) = $anvil->System->host_name();
# Set the traditional host name.
my ($traditional_hostname, $descriptive_hostname) = $anvil->System->hostname({set => "an-striker01.alteeve.com");
my ($traditional_host_name, $descriptive_host_name) = $anvil->System->host_name({set => "an-striker01.alteeve.com");
# Set the traditional and descriptive host names.
my ($traditional_hostname, $descriptive_hostname) = $anvil->System->hostname({set => "an-striker01.alteeve.com", pretty => "Alteeve - Striker 01");
my ($traditional_host_name, $descriptive_host_name) = $anvil->System->host_name({set => "an-striker01.alteeve.com", pretty => "Alteeve - Striker 01");
The current host name (or the new host name if C<< set >> was used) is returned as a string.
Parameters;
=head3 set (optional)
=head3 password (optional)
If set, this will become the new host name.
This is the password to use when connecting to a remote machine. If not set, but C<< target >> is, an attempt to connect without a password will be made.
=head3 port (optional)
This is the TCP port to use when connecting to a remote machine. If not set, but C<< target >> is, C<< 22 >> will be used.
=head3 pretty (optional)
If set, this will be set as the "pretty" host name.
=head3 remote_user (optional, default root)
If C<< target >> is set, this will be the user we connect to the remote machine as.
=head3 set (optional)
If set, this will become the new host name.
=head3 target (optional)
This is the IP or host name of the machine to read the version of. If this is not set, the local system's version is checked.
=cut
sub hostname
sub host_name
{
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 => "System->hostname()" }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->host_name()" }});
my $pretty = $parameter->{pretty} ? $parameter->{pretty} : "";
my $set = $parameter->{set} ? $parameter->{set} : "";
my $pretty = defined $parameter->{pretty} ? $parameter->{pretty} : "";
my $set = defined $parameter->{set} ? $parameter->{set} : "";
my $password = defined $parameter->{password} ? $parameter->{password} : "";
my $port = defined $parameter->{port} ? $parameter->{port} : "";
my $remote_user = defined $parameter->{remote_user} ? $parameter->{remote_user} : "root";
my $target = defined $parameter->{target} ? $parameter->{target} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
pretty => $pretty,
set => $set,
target => $target,
port => $port,
remote_user => $remote_user,
password => $anvil->Log->is_secure($password),
}});
# Set
# Set?
if ($set)
{
# TODO: Sanity check the host name
my $shell_call = $anvil->data->{path}{exe}{hostnamectl}." set-hostname $set";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code }});
my $output = "";
my $return_code = "";
if ($anvil->Network->is_remote($target))
{
($output, my $error, $return_code) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
target => $target,
port => $port,
password => $password,
remote_user => $remote_user,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
error => $error,
output => $output,
}});
}
else
{
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
}
# Pretty
@ -1252,19 +1298,100 @@ sub hostname
my $shell_call = $anvil->data->{path}{exe}{hostnamectl}." set-hostname --pretty \"$pretty\"";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code }});
my $output = "";
my $return_code = "";
if ($anvil->Network->is_remote($target))
{
($output, my $error, $return_code) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
target => $target,
port => $port,
password => $password,
remote_user => $remote_user,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
error => $error,
output => $output,
}});
}
else
{
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output,
return_code => $return_code,
}});
}
}
# Get the static (traditional) host name
my ($hostname, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{hostnamectl}." --static"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { hostname => $hostname, return_code => $return_code }});
my $shell_call = $anvil->data->{path}{exe}{hostnamectl}." --static";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
my $host_name = "";
my $descriptive = "";
my $output = "";
my $return_code = "";
if ($anvil->Network->is_remote($target))
{
($host_name, my $error, $return_code) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
target => $target,
port => $port,
password => $password,
remote_user => $remote_user,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_name => $host_name,
output => $output,
}});
}
else
{
($host_name, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_name => $host_name,
return_code => $return_code,
}});
}
# Get the pretty (descriptive) host name
(my $descriptive, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{hostnamectl}." --pretty"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { descriptive => $descriptive, return_code => $return_code }});
$shell_call = $anvil->data->{path}{exe}{hostnamectl}." --pretty";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
return($hostname, $descriptive);
$output = "";
$return_code = "";
if ($anvil->Network->is_remote($target))
{
($descriptive, my $error, $return_code) = $anvil->Remote->call({
debug => $debug,
shell_call => $shell_call,
target => $target,
port => $port,
password => $password,
remote_user => $remote_user,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
descriptive => $descriptive,
output => $output,
}});
}
else
{
($descriptive, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
descriptive => $descriptive,
return_code => $return_code,
}});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
host_name => $host_name,
return_code => $return_code,
}});
return($host_name, $descriptive);
}
=head2 is_local
@ -1290,8 +1417,8 @@ sub is_local
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host => $host }});
my $is_local = 0;
if (($host eq $anvil->_hostname) or
($host eq $anvil->_short_hostname) or
if (($host eq $anvil->_host_name) or
($host eq $anvil->_short_host_name) or
($host eq "localhost") or
($host eq "127.0.0.1"))
{

@ -949,7 +949,7 @@ sub process_prep_host_page
dr_checked => $dr_checked,
}});
my $host_name = $anvil->_hostname;
my $host_name = $anvil->_host_name;
$host_name =~ s/striker\d\d/xxx/;
my $default_host_name = $host_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
@ -1948,7 +1948,7 @@ ORDER BY
step1_welcome_message_id => "",
organization => $anvil->data->{cgi}{organization}{value},
prefix => $anvil->data->{cgi}{prefix}{value},
hostname => $anvil->data->{cgi}{hostname}{value},
host_name => $anvil->data->{cgi}{host_name}{value},
striker_user => $anvil->data->{cgi}{striker_user}{value},
striker_password => $anvil->data->{cgi}{striker_password}{value},
networks => $networks,
@ -2269,16 +2269,16 @@ ORDER BY
# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { say_dg_iface => $say_dg_iface }});
# Hostname
my $say_default_hostname = $anvil->data->{cgi}{prefix}{value}."-striker0".$anvil->data->{cgi}{sequence}{value}.".".$anvil->data->{cgi}{domain}{value};
my $hostname_class = $anvil->data->{cgi}{hostname}{alert} ? "input_alert" : "input_clear";
my $say_hostname = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
name => "hostname",
id => "hostname",
my $say_default_host_name = $anvil->data->{cgi}{prefix}{value}."-striker0".$anvil->data->{cgi}{sequence}{value}.".".$anvil->data->{cgi}{domain}{value};
my $host_name_class = $anvil->data->{cgi}{host_name}{alert} ? "input_alert" : "input_clear";
my $say_host_name = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
name => "host_name",
id => "host_name",
field => "#!string!striker_0016!#",
description => "#!string!striker_0017!#",
value => defined $anvil->data->{cgi}{hostname}{value} ? $anvil->data->{cgi}{hostname}{value} : $say_default_hostname,
value => defined $anvil->data->{cgi}{host_name}{value} ? $anvil->data->{cgi}{host_name}{value} : $say_default_host_name,
default_value => "",
class => $hostname_class,
class => $host_name_class,
extra => "",
}});
@ -2327,7 +2327,7 @@ ORDER BY
striker_password_form => $say_striker_password,
gateway_form => $say_gateway,
dns_form => $say_dns,
hostname_form => $say_hostname,
host_name_form => $say_host_name,
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step2_body => $step2_body }});
@ -2343,10 +2343,10 @@ sub sanity_check_step2
my $sane = 1;
# Do we have a host name, striker user and password?
if (not $anvil->Validate->form_field({name => "hostname", type => "domain_name"}))
if (not $anvil->Validate->form_field({name => "host_name", type => "domain_name"}))
{
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0012"}) }});
$anvil->data->{cgi}{hostname}{alert} = 1;
$anvil->data->{cgi}{host_name}{alert} = 1;
$sane = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
}
@ -2354,8 +2354,8 @@ sub sanity_check_step2
{
# Record the answer.
$anvil->Database->insert_or_update_variables({
variable_name => "form::config_step2::hostname::value",
variable_value => $anvil->data->{cgi}{hostname}{value},
variable_name => "form::config_step2::host_name::value",
variable_value => $anvil->data->{cgi}{host_name}{value},
variable_default => "",
variable_description => "striker_0017",
variable_section => "config_step2",
@ -2919,13 +2919,13 @@ sub config_step1
}});
# If we don't have an organization name, prefix, domain name or sequence number, try to parse it from
# the current static and pretty hostnames.
my ($traditional_hostname, $descriptive_hostname) = $anvil->System->hostname();
# the current static and pretty host_names.
my ($traditional_host_name, $descriptive_host_name) = $anvil->System->host_name();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
traditional_hostname => $traditional_hostname,
descriptive_hostname => $descriptive_hostname,
traditional_host_name => $traditional_host_name,
descriptive_host_name => $descriptive_host_name,
}});
if ($descriptive_hostname =~ /^(.*?) - Striker (\d+)/)
if ($descriptive_host_name =~ /^(.*?) - Striker (\d+)/)
{
my $organization = $1;
my $sequence = $2;
@ -2951,7 +2951,7 @@ sub config_step1
}});
}
}
if ($traditional_hostname =~ /^(.*?)-striker\d+\.(.*)$/)
if ($traditional_host_name =~ /^(.*?)-striker\d+\.(.*)$/)
{
my $prefix = $1;
my $domain = $2;

@ -126,7 +126,7 @@
<table>
<tr>
<td>
#!variable!hostname_form!#
#!variable!host_name_form!#
</td>
</tr>
<tr>
@ -287,7 +287,7 @@
#!string!striker_0016!#:
</td>
<td class="column_row_value_fixed">
#!variable!hostname!#
#!variable!host_name!#
</td>
</tr>
<!-- User -->

@ -59,7 +59,7 @@ timezone #!variable!timezone!#
lang en_CA.UTF-8
# Network information
network --hostname=#!variable!hostname!#
network --hostname=#!variable!host_name!#
# Root and admin passwords are '#!variable!password!#'
rootpw --plaintext #!variable!password!#
user --name=admin --password "#!variable!password!#" --plaintext --gecos "admin" --groups wheel

@ -352,7 +352,7 @@ sub stop_drbd_resource
my ($anvil) = @_;
my $server = $anvil->data->{environment}{OCF_RESKEY_name};
my $host = $anvil->_short_hostname;
my $host = $anvil->_short_host_name;
my $peer = $anvil->data->{drbd}{config}{$host}{peer};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
server => $server,
@ -394,7 +394,7 @@ sub start_drbd_resource
my ($anvil) = @_;
my $server = $anvil->data->{environment}{OCF_RESKEY_name};
my $host = $anvil->_short_hostname;
my $host = $anvil->_short_host_name;
my $peer = $anvil->data->{drbd}{config}{$host}{peer};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
server => $server,
@ -527,7 +527,7 @@ sub find_server
my ($anvil) = @_;
my $server = $anvil->data->{environment}{OCF_RESKEY_name};
my $host = $anvil->_short_hostname;
my $host = $anvil->_short_host_name;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "log_0415", variables => { server => $server }});
foreach my $ip_address (sort {$a cmp $b} keys %{$anvil->data->{drbd}{config}{$host}{ip_addresses}})
{
@ -560,7 +560,7 @@ sub find_server
host => $host,
}});
if ($host eq $anvil->_hostname)
if ($host eq $anvil->_host_name)
{
# Already running, we're good, and we're done.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "log_0416", variables => { server => $server }});
@ -741,7 +741,7 @@ sub migrate_server
# Make sure all resource(s) are ready for the server.
my $all_up_to_date = 1;
my $host = $anvil->_short_hostname;
my $host = $anvil->_short_host_name;
my $peer_name = $anvil->data->{drbd}{config}{$host}{peer};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
host => $host,
@ -865,7 +865,7 @@ sub migrate_server
# 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.
if (($target eq $anvil->_hostname) or ($target eq $anvil->_short_hostname) or ($target eq $meta_on_node))
if (($target eq $anvil->_host_name) or ($target eq $anvil->_short_host_name) or ($target eq $meta_on_node))
{
# If it's running, we're succesfully out.
if ((($host eq $target) or ($short_host eq $target)) && ($status eq "running"))
@ -1050,7 +1050,7 @@ sub validate_storage_drbd
# Now check storage.
my $server = $anvil->data->{environment}{OCF_RESKEY_name};
my $source = "from_disk";
my $host = $anvil->_short_hostname;
my $host = $anvil->_short_host_name;
# Did I find a resource for each disk?
foreach my $device_path (sort {$a cmp $b} keys %{$anvil->data->{server}{$server}{device}})

@ -40,8 +40,8 @@ Author: Madison Kelly <mkelly@alteeve.ca>
<key name="message_0013">#!free!#</key>
<key name="message_0014">One or more files on disk have changed. Exiting to reload.</key>
<key name="message_0015">The reconfigure of the network has begun.</key>
<key name="message_0016">The hostname: [#!variable!hostname!#] has been set.</key>
<key name="message_0017">Failed to set the hostname: [#!variable!hostname!#]! The hostname is currently [#!variable!bad_hostname!#]. This is probably a program error.</key>
<key name="message_0016">The host name: [#!variable!host_name!#] has been set.</key>
<key name="message_0017">Failed to set the host name: [#!variable!host_name!#]! The host name is currently [#!variable!bad_host_name!#]. This is probably a program error.</key>
<key name="message_0018">What would you like the new password to be?</key>
<key name="message_0019">Please enter the password again to confirm.</key>
<key name="message_0020">About to update the local passwords (shell users, database and web interface).</key>

@ -196,8 +196,8 @@ sub reconfigure_network
my $bcn_count = 1; # TODO: This should be coming from the form, even though it's only '1' for now.
my $sn_count = 0; # TODO: This should be coming from the form, even though it's always '0' for Strikers.
my $ifn_count = $anvil->data->{variables}{form}{config_step1}{ifn_count}{value};
my $new_hostname = defined $anvil->data->{variables}{form}{config_step2}{hostname}{value} ? $anvil->data->{variables}{form}{config_step2}{hostname}{value} : $prefix."-striker".sprintf("%02d", $sequence).".".$domain;
my $pretty_hostname = $organization." - Striker ".sprintf("%02d", $sequence);
my $new_host_name = defined $anvil->data->{variables}{form}{config_step2}{host_name}{value} ? $anvil->data->{variables}{form}{config_step2}{host_name}{value} : $prefix."-striker".sprintf("%02d", $sequence).".".$domain;
my $pretty_host_name = $organization." - Striker ".sprintf("%02d", $sequence);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, list => {
prefix => $prefix,
sequence => $sequence,
@ -205,37 +205,37 @@ sub reconfigure_network
organization => $organization,
bcn_count => $bcn_count,
ifn_count => $ifn_count,
new_hostname => $new_hostname,
pretty_hostname => $pretty_hostname,
new_host_name => $new_host_name,
pretty_host_name => $pretty_host_name,
}});
# Set the hostname
my ($hostname, $descriptive_hostname) = $anvil->System->hostname({set => $new_hostname, pretty => $pretty_hostname, debug => 3});
# Set the host_name
my ($host_name, $descriptive_host_name) = $anvil->System->host_name({set => $new_host_name, pretty => $pretty_host_name, debug => 3});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
hostname => $hostname,
descriptive_hostname => $descriptive_hostname,
host_name => $host_name,
descriptive_host_name => $descriptive_host_name,
}});
if ($hostname eq $new_hostname)
if ($host_name eq $new_host_name)
{
# Success
$anvil->Job->update_progress({
progress => 10,
message => "message_0016,!!hostname!$new_hostname!!",
message => "message_0016,!!host_name!$new_host_name!!",
job_uuid => $anvil->data->{job}{uuid},
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0016", variables => { hostname => $new_hostname }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0016", variables => { host_name => $new_host_name }});
}
else
{
# Failed
$anvil->Job->update_progress({
progress => 0,
message => "message_0017,!!hostname!$new_hostname!!,!!bad_hostname!$hostname!!",
message => "message_0017,!!host_name!$new_host_name!!,!!bad_host_name!$host_name!!",
job_uuid => $anvil->data->{job}{uuid},
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "message_0017", variables => {
hostname => $new_hostname,
bad_hostname => $hostname,
host_name => $new_host_name,
bad_host_name => $host_name,
}});
$anvil->nice_exit({code => 4});
}

@ -519,7 +519,7 @@ sub check_ssh_keys
's2:host_key_public_key' => $host_key_public_key,
}});
# The key in the file might have a different trailing suffix (user@hostname)
# The key in the file might have a different trailing suffix (user@host_name)
# and doesn't really matter. So we search by the key type and public key to
# see if it exists already.
my $found = 0;
@ -687,10 +687,10 @@ WHERE
# If the host name is the long host name, create another entry with the short name.
if ($host_name =~ /^(.*?)\./)
{
my $short_hostname = $1;
$anvil->data->{peers}{ssh_keys}{$host_uuid}{host}{$short_hostname} = $host_key;
my $short_host_name = $1;
$anvil->data->{peers}{ssh_keys}{$host_uuid}{host}{$short_host_name} = $host_key;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"peers::ssh_keys::${host_uuid}::host::${short_hostname}" => $anvil->data->{peers}{ssh_keys}{$host_uuid}{host}{$short_hostname},
"peers::ssh_keys::${host_uuid}::host::${short_host_name}" => $anvil->data->{peers}{ssh_keys}{$host_uuid}{host}{$short_host_name},
}});
}

@ -72,7 +72,7 @@ sub set_host_name
### TODO: Left off here;
### - Validate host name
### - Update progress values
### - Set hostnamectl
### - Set host_namectl
if ((not defined $anvil->data->{data}{host_name}) or (not $anvil->data->{data}{host_name}))
{
return(0);
@ -83,7 +83,7 @@ sub set_host_name
if (not $anvil->Validate->is_domain_name({name => $anvil->data->{data}{host_name}}))
{
# Bad hostname.
# Bad host_name.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print' => 1, key => "job_0062", variables => { host_name => $anvil->data->{data}{host_name} }});
$anvil->data->{job}{progress} += 5;
update_progress($anvil, $anvil->data->{job}{progress}, "job_0062,!!host_name!".$anvil->data->{data}{host_name}."!!");
@ -91,7 +91,14 @@ sub set_host_name
}
# Try to set the host name now.
my ($host_name, $descriptive_host_name) = $anvil->System->hostname({debug => 2, set => $anvil->data->{data}{host_name}});
my ($host_name, $descriptive_host_name) = $anvil->System->host_name({
debug => 2,
set => $anvil->data->{data}{host_name},
password => $anvil->data->{data}{password},
port => $anvil->data->{data}{ssh_port},
target => $anvil->data->{data}{host_ip_address},
remote_user => "root",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
host_name => $host_name,
descriptive_host_name => $descriptive_host_name,
@ -219,7 +226,7 @@ sub add_repos
# NOTE: We can't use Storage->write_file() because the target may not have 'rsync' installed
# yet.
my $shell_call = "
".$anvil->data->{path}{exe}{cat}." > /etc/yum.repos.d/".$anvil->_short_hostname.".repo << EOF
".$anvil->data->{path}{exe}{cat}." > /etc/yum.repos.d/".$anvil->_short_host_name.".repo << EOF
$repo
EOF
";

@ -199,7 +199,7 @@ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list
}});
# If this isn't a Striker dashboard, exit.
if ($anvil->_short_hostname !~ /striker/)
if ($anvil->_short_host_name !~ /striker/)
{
print $anvil->Words->string({key => "error_0044"})."\n";
update_progress($anvil, 100, "error_0044");
@ -463,9 +463,9 @@ sub setup_boot_environment
my $dns = $anvil->data->{network}{'local'}{interface}{$bcn_interface}{dns} ? $anvil->data->{network}{'local'}{interface}{$bcn_interface}{dns} : $anvil->data->{defaults}{network}{dns};
my $domain = "localdomain";
my $base_url = "http://".$bcn_ip."/".$anvil->data->{host_os}{os_type}."/".$anvil->data->{host_os}{os_arch};
if ($anvil->_hostname =~ /\./)
if ($anvil->_host_name =~ /\./)
{
$domain = $anvil->_hostname;
$domain = $anvil->_host_name;
$domain =~ s/^.*?\.//;
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
@ -480,7 +480,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
### network. Someday this might change, and if so, we'll need to make this a lot smarter.
my $striker_number = ($anvil->_short_hostname =~ /striker(\d+)/)[0];
my $striker_number = ($anvil->_short_host_name =~ /striker(\d+)/)[0];
$striker_number = 1 if not $striker_number;
$striker_number =~ s/^0//;
my $third_octet = (10 * $striker_number) + 4;
@ -582,7 +582,7 @@ sub setup_boot_environment
my $kickstart_body = $anvil->Template->get({file => "pxe.txt", show_name => 0, name => "kickstart", variables => {
type => $type,
say_type => $say_type,
hostname => "new-".$type.".".$domain,
host_name => "new-".$type.".".$domain,
os => $anvil->data->{host_os}{os_type},
url => $base_url."/os/",
keyboard => $anvil->data->{kickstart}{keyboard} ? $anvil->data->{kickstart}{keyboard} : $anvil->data->{defaults}{kickstart}{keyboard},
@ -1418,7 +1418,6 @@ sub load_packages
"harfbuzz.x86_64",
"hdparm.x86_64",
"hicolor-icon-theme.noarch",
"hostname.x86_64",
"htop.x86_64",
"httpd-filesystem.noarch",
"httpd-tools.x86_64",

Loading…
Cancel
Save