From d3d28d8ec51ab754f5fef1e101667299d5e1e669 Mon Sep 17 00:00:00 2001 From: Digimer Date: Wed, 26 Sep 2018 18:55:52 -0400 Subject: [PATCH] * Updated striker's first config page to pre-fill with values (Org name, prefix, sequence and domain name) if they can be devined from the existing system config. * Updated System->hostname() to return the "pretty" host name as well as the traditional host name. Signed-off-by: Digimer --- Anvil/Tools/System.pm | 26 ++++++++---- cgi-bin/striker | 74 +++++++++++++++++++++++++++++++++-- notes | 3 ++ tools/anvil-configure-striker | 2 +- 4 files changed, 94 insertions(+), 11 deletions(-) diff --git a/Anvil/Tools/System.pm b/Anvil/Tools/System.pm index 053a23d5..4cc9dd56 100755 --- a/Anvil/Tools/System.pm +++ b/Anvil/Tools/System.pm @@ -884,7 +884,18 @@ sub get_ips =head2 hostname -Get our set the local hostname. The current host name (or the new hostname if C<< set >> was used) is returned as a string. +Get or set the local hostname. 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(); + + # Set the traditional host name. + my ($traditional_hostname, $descriptive_hostname) = $anvil->System->hostname({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"); + +The current host name (or the new hostname if C<< set >> was used) is returned as a string. Parameters; @@ -935,14 +946,15 @@ sub hostname $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output }}); } - # Get - 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 $hostname = $anvil->System->call({shell_call => $shell_call}); + # Get the static (traditional) hostname + my $hostname = $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($hostname); + # Get the pretty (descriptive) hostname + my $descriptive = $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($hostname, $descriptive); } =head2 is_local diff --git a/cgi-bin/striker b/cgi-bin/striker index 2fdc243c..1aca7f43 100755 --- a/cgi-bin/striker +++ b/cgi-bin/striker @@ -2118,7 +2118,7 @@ sub config_step1 variable_source_uuid => $anvil->Get->host_uuid, variable_source_table => "hosts", }); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { organization => $organization, prefix => $prefix, domain => $domain, @@ -2129,15 +2129,83 @@ sub config_step1 $anvil->data->{cgi}{organization}{value} = $organization ne "" ? $organization : ""; $anvil->data->{cgi}{prefix}{value} = $prefix ne "" ? $prefix : ""; $anvil->data->{cgi}{domain}{value} = $domain ne "" ? $domain : ""; - $anvil->data->{cgi}{sequence}{value} = $sequence ne "" ? $sequence : 1; + $anvil->data->{cgi}{sequence}{value} = $sequence ne "" ? $sequence : ""; $anvil->data->{cgi}{ifn_count}{value} = $ifn_count ne "" ? $ifn_count : 1; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'cgi::organization::value' => $anvil->data->{cgi}{organization}{value}, 'cgi::prefix::value' => $anvil->data->{cgi}{prefix}{value}, 'cgi::domain::value' => $anvil->data->{cgi}{domain}{value}, 'cgi::sequence::value' => $anvil->data->{cgi}{sequence}{value}, 'cgi::ifn_count::value' => $anvil->data->{cgi}{ifn_count}{value}, }}); + + # 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(); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + traditional_hostname => $traditional_hostname, + descriptive_hostname => $descriptive_hostname, + }}); + if ($descriptive_hostname =~ /^(.*?) - Striker (\d+)/) + { + my $organization = $1; + my $sequence = $2; + $sequence =~ s/^0+//; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + organization => $organization, + sequence => $sequence, + }}); + + if (($organization) && ($anvil->data->{cgi}{organization}{value} eq "")) + { + $anvil->data->{cgi}{organization}{value} = $organization; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 'cgi::organization::value' => $anvil->data->{cgi}{organization}{value}, + }}); + } + + if (($sequence =~ /^\d+$/) && ($anvil->data->{cgi}{sequence}{value} eq "")) + { + $anvil->data->{cgi}{sequence}{value} = $sequence; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 'cgi::sequence::value' => $anvil->data->{cgi}{sequence}{value}, + }}); + } + } + if ($traditional_hostname =~ /^(.*?)-striker\d+\.(.*)$/) + { + my $prefix = $1; + my $domain = $2; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + prefix => $prefix, + domain => $domain, + }}); + + if (($prefix) && ($anvil->data->{cgi}{prefix}{value} eq "")) + { + $anvil->data->{cgi}{prefix}{value} = $prefix; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 'cgi::prefix::value' => $anvil->data->{cgi}{prefix}{value}, + }}); + } + + if (($domain) && ($anvil->data->{cgi}{domain}{value} eq "")) + { + $anvil->data->{cgi}{domain}{value} = $domain; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 'cgi::domain::value' => $anvil->data->{cgi}{domain}{value}, + }}); + } + } + + # If I still don't have a sequence number, set '1'. + if ($anvil->data->{cgi}{sequence}{value} eq "") + { + $anvil->data->{cgi}{sequence}{value} = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 'cgi::sequence::value' => $anvil->data->{cgi}{sequence}{value}, + }}); + } } my $organization_class = $anvil->data->{cgi}{organization}{alert} ? "input_alert" : "input_clear"; diff --git a/notes b/notes index 685b3588..9e79ec83 100644 --- a/notes +++ b/notes @@ -6,6 +6,9 @@ DB stuff; Dump; su - postgres -c "pg_dump anvil" > /anvil.out +Drop; +su - postgres -c "dropdb anvil" && su - postgres -c "createdb --owner admin anvil" && su - postgres -c "psql anvil" + Reload the DB; su - postgres -c "dropdb anvil" && su - postgres -c "createdb --owner admin anvil" && su - postgres -c "psql anvil < /anvil.out" su - postgres -c "psql anvil" diff --git a/tools/anvil-configure-striker b/tools/anvil-configure-striker index 94f1eac6..e894f90d 100755 --- a/tools/anvil-configure-striker +++ b/tools/anvil-configure-striker @@ -192,7 +192,7 @@ sub reconfigure_network }}); # Set the hostname - my $hostname = $anvil->System->hostname({set => $new_hostname, pretty => $pretty_hostname, debug => 3}); + my ($hostname, $descriptive_hostname) = = $anvil->System->hostname({set => $new_hostname, pretty => $pretty_hostname, debug => 3}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { hostname => $hostname }}); if ($hostname eq $new_hostname) {