From 0fb191c00f9eb3305bb819960d6c1054195c4f22 Mon Sep 17 00:00:00 2001 From: Digimer Date: Tue, 2 Mar 2021 01:18:18 -0500 Subject: [PATCH] * Made more progress on tools/striker-auto-initialize-all, now to the point where it loads the variables needed to initialize Striker dashboard. * Cleaned up / added some logging in various locations. Signed-off-by: Digimer --- Anvil/Tools/Get.pm | 2 +- Anvil/Tools/Network.pm | 9 + Anvil/Tools/Remote.pm | 7 +- cgi-bin/striker | 22 +- notes | 4 + share/words.xml | 8 + tools/striker-auto-initialize-all | 389 ++++++++++++++++++++-- tools/striker-auto-initialize-all.example | 47 ++- 8 files changed, 439 insertions(+), 49 deletions(-) diff --git a/Anvil/Tools/Get.pm b/Anvil/Tools/Get.pm index 1eaf322d..af29567c 100644 --- a/Anvil/Tools/Get.pm +++ b/Anvil/Tools/Get.pm @@ -1063,7 +1063,7 @@ sub cgi # This is a password and we're not logging sensitive data, obfuscate it. $censored_value = $anvil->Words->string({key => "log_0186"}); } - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "cgi::${variable}::$say_value" => $censored_value, }}); } diff --git a/Anvil/Tools/Network.pm b/Anvil/Tools/Network.pm index ad30e990..203f39fa 100644 --- a/Anvil/Tools/Network.pm +++ b/Anvil/Tools/Network.pm @@ -1637,6 +1637,15 @@ sub get_ips $anvil->data->{network}{$host}{interface}{$in_iface}{default_gateway} = 0 if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{default_gateway}; $anvil->data->{network}{$host}{interface}{$in_iface}{gateway} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{gateway}; $anvil->data->{network}{$host}{interface}{$in_iface}{dns} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{dns}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "network::${host}::interface::${in_iface}::ip" => $anvil->data->{network}{$host}{interface}{$in_iface}{ip}, + "network::${host}::interface::${in_iface}::subnet_mask" => $anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask}, + "network::${host}::interface::${in_iface}::mac_address" => $anvil->data->{network}{$host}{interface}{$in_iface}{mac_address}, + "network::${host}::interface::${in_iface}::mtu" => $anvil->data->{network}{$host}{interface}{$in_iface}{mtu}, + "network::${host}::interface::${in_iface}::default_gateway" => $anvil->data->{network}{$host}{interface}{$in_iface}{default_gateway}, + "network::${host}::interface::${in_iface}::gateway" => $anvil->data->{network}{$host}{interface}{$in_iface}{gateway}, + "network::${host}::interface::${in_iface}::dns" => $anvil->data->{network}{$host}{interface}{$in_iface}{dns}, + }}); } next if not $in_iface; if ($in_iface eq "lo") diff --git a/Anvil/Tools/Remote.pm b/Anvil/Tools/Remote.pm index f3d84fce..bdebd2cd 100644 --- a/Anvil/Tools/Remote.pm +++ b/Anvil/Tools/Remote.pm @@ -162,7 +162,7 @@ sub add_target_to_known_hosts { # We don't know about this machine yet, so scan it. my $added = $anvil->Remote->_call_ssh_keyscan({ - debug => $debug, + debug => 2, target => $target, port => $port, user => $user, @@ -171,10 +171,11 @@ sub add_target_to_known_hosts if (not $added) { # Failed to add. :( + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0009", variables => { target => $target, port => $port, - user => $user, + user => getpwuid($user) ? getpwuid($user) : $user, }}); return(1); } @@ -1022,7 +1023,7 @@ sub _call_ssh_keyscan $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "log_0159", variables => { target => $target, port => $port, - user => $user, + user => getpwuid($user) ? getpwuid($user) : $user, }}); # Redirect STDERR to STDOUT and grep off the comments. diff --git a/cgi-bin/striker b/cgi-bin/striker index fbdb2259..905dbf06 100755 --- a/cgi-bin/striker +++ b/cgi-bin/striker @@ -7839,21 +7839,21 @@ sub sanity_check_step2 }}); foreach my $count (1..$network_count) { - my $this_network = $network.$count; - my $this_ip_key = $this_network."_ip"; + my $this_network = $network.$count; + my $this_ip_key = $this_network."_ip"; my $this_subnet_mask_key = $this_network."_subnet_mask"; - my $this_iface1_key = $this_network."_link1_mac_to_set"; - my $this_iface2_key = $this_network."_link2_mac_to_set"; + my $this_iface1_key = $this_network."_link1_mac_to_set"; + my $this_iface2_key = $this_network."_link2_mac_to_set"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { - count => $count, - this_ip_key => $this_ip_key, + count => $count, + this_ip_key => $this_ip_key, this_subnet_mask_key => $this_subnet_mask_key, - this_iface1_key => $this_iface1_key, - this_iface2_key => $this_iface2_key, - "cgi::${this_ip_key}::value" => $anvil->data->{cgi}{$this_ip_key}{value}, + this_iface1_key => $this_iface1_key, + this_iface2_key => $this_iface2_key, + "cgi::${this_ip_key}::value" => $anvil->data->{cgi}{$this_ip_key}{value}, "cgi::${this_subnet_mask_key}::value" => $anvil->data->{cgi}{$this_subnet_mask_key}{value}, - "cgi::${this_iface1_key}::value" => $anvil->data->{cgi}{$this_iface1_key}{value}, - "cgi::${this_iface2_key}::value" => $anvil->data->{cgi}{$this_iface2_key}{value}, + "cgi::${this_iface1_key}::value" => $anvil->data->{cgi}{$this_iface1_key}{value}, + "cgi::${this_iface2_key}::value" => $anvil->data->{cgi}{$this_iface2_key}{value}, }}); # This will be used to tell the user which interface has a problem, if one exists. diff --git a/notes b/notes index 59071379..c1c35931 100644 --- a/notes +++ b/notes @@ -331,6 +331,10 @@ drbdsetup show all --show-defaults drbdsetup net-options srv01-c7_0 2 --_name=m3-a02n01.alteeve.com --csums-alg=md5 --data-integrity-alg=md5 --after-sb-0pri=discard-zero-changes --after-sb-1pri=discard-secondary --after-sb-2pri=disconnect --protocol=C --fencing=resource-and-stonith --allow-two-primaries=yes drbdsetup net-options srv01-c7_0 2 --_name=m3-a02n01.alteeve.com --csums-alg=md5 --data-integrity-alg=md5 --after-sb-0pri=discard-zero-changes --after-sb-1pri=discard-secondary --after-sb-2pri=disconnect --protocol=C --fencing=resource-and-stonith --allow-two-primaries=yes + +# Adding a second volume to a running resource; +- I wonder if you'd have the same results if you could get vol1 into an UpToDate/UpToDate state using the drbdsetup equivalent of drbdadm new-current-uuid --clear-bitmap + # Migrate: virsh -c qemu+ssh://root@m3-a02n02.alteeve.com/system list diff --git a/share/words.xml b/share/words.xml index c88ae052..f185d9e3 100644 --- a/share/words.xml +++ b/share/words.xml @@ -332,6 +332,13 @@ Output (if any): - shell_call: [#!variable!shell_call!#] ]]> Usage: [#!variable!program!# --config /path/to/config]. + The file: [#!variable!file!#] doesn't appear to be valid. + Failed to find a matching entry in the file: [#!variable!file!#]. Please make sure the MAC addresses in the config are accurate for these systems. + Missing variable: [#!variable!variable!#] from config file: [#!data!switches::config!#]. + The length of the prefix: [#!variable!prefix!#] is: [#!variable!length!#]. The prefix needs to be not more than 5. + The DNS IP: [#!variable!ip!#] is invalid. + The gateway IP: [#!variable!ip!#] is invalid. + The variable: [#!variable!variable!#] is invalid: [#!variable!value!#]. @@ -1676,6 +1683,7 @@ Are you sure that you want to delete the server: [#!variable!server_name!#]? [Ty Preparing to migrate a server (or all servers). - #!variable!server_name!# (Current state: [#!variable!server_state!#]) - * #!variable!server_name!# (Deleted, name can be reused) + We're Striker: [#!variable!striker!#], and we're now configured, so we're done. Striker 1 will finish configuration. Saved the mail server information successfully! diff --git a/tools/striker-auto-initialize-all b/tools/striker-auto-initialize-all index 967064eb..66787af8 100755 --- a/tools/striker-auto-initialize-all +++ b/tools/striker-auto-initialize-all @@ -23,30 +23,6 @@ if (($running_directory =~ /^\./) && ($ENV{PWD})) =cut Striker initialization; - -# Figure out if we're striker '1' or '2' by matching found MAC addresses against configured MAC addresses. -# Striker 1 will, after configuring itself, reboot and wait for access to Striker 2. Then it will bond the two and begin configuring nodes (and DR, if defined) - data source | variable_name | variable_value | variable_default | variable_description | variable_section | variable_source_uuid | variable_source_table | modified_date -------------------------------------------+--------------------------------------------------+-------------------------+------------------+----------------------+------------------+--------------------------------------+-----------------------+------------------------------- -base::organization_name | form::config_step1::organization::value | Alteeve | | striker_0004 | config_step1 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:26:22.938934-05 -base::prefix | form::config_step1::prefix::value | di | | striker_0006 | config_step1 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:26:22.938934-05 -base::domain | form::config_step1::domain::value | digimer.ca | | striker_0008 | config_step1 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:26:22.938934-05 -keys %{striker}{1}{network}{ifn} | form::config_step1::ifn_count::value | 1 | | striker_0012 | config_step1 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:26:22.938934-05 -# Match MAC for Striker sequence | form::config_step1::sequence::value | 2 | | striker_0010 | config_step1 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:27:39.491016-05 --striker0. | form::config_step2::host_name::value | di-striker02.digimer.ca | | striker_0017 | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:29:59.317812-05 -# Hard code to 'admin' | form::config_step2::striker_user::value | admin | | striker_0032 | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:29:59.317812-05 -base::password::desired | form::config_step2::striker_password::value | super secret password | | striker_0034 | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:29:59.317812-05 -base::dns | form::config_step2::dns::value | 8.8.8.8, 8.8.4.4 | | striker_0038 | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:29:59.317812-05 -base::gateway | form::config_step2::gateway::value | 192.168.122.1 | | striker_0036 | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:30:16.688974-05 -base::interface | form::config_step2::gateway_interface::value | ifn1 | | | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:30:16.688974-05 -striker::1::network::bcn::1::ip | form::config_step2::bcn1_ip::value | 10.201.4.2 | | striker_0024 | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:29:59.317812-05 -striker::1::network::bcn::1::subnet_mask | form::config_step2::bcn1_subnet_mask::value | 255.255.0.0 | | striker_0025 | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:29:59.317812-05 -striker::1::network::bcn::1::link::1::mac | form::config_step2::bcn1_link1_mac_to_set::value | 52:54:00:8b:d6:82 | | striker_0029 | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:29:59.317812-05 -striker::1::network::ifn::1::subnet_mask | form::config_step2::ifn1_subnet_mask::value | 255.255.255.0 | | striker_0025 | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:29:59.317812-05 -striker::1::network::ifn::1::link::1::mac | form::config_step2::ifn1_link1_mac_to_set::value | 52:54:00:c0:f2:7c | | striker_0029 | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:29:59.317812-05 -striker::1::network::ifn::1::ip | form::config_step2::ifn1_ip::value | 192.168.122.12 | | striker_0024 | config_step2 | a64c477b-b0a1-4985-9968-f4b46d75fb0c | hosts | 2021-02-16 20:30:16.688974-05 - - anvil=# SELECT * FROM jobs WHERE job_uuid = '158e8384-eac7-4289-8f70-bc43eaf8b017'; job_uuid | job_host_uuid | job_command | job_data | job_picked_up_by | job_picked_up_at | job_updated | job_name | job_progress | job_title | job_description | job_status | modified_date --------------------------------------+--------------------------------------+--------------------------------+--------------------+------------------+------------------+-------------+--------------------+--------------+-----------+-----------------+------------+------------------------------- @@ -114,8 +90,369 @@ if ((not $anvil->data->{switches}{config}) or (not -f $anvil->data->{switches}{c # Load the config. $anvil->Storage->read_config({file => $anvil->data->{switches}{config}}); -print Dumper $anvil->data->{base}; -print Dumper $anvil->data->{striker}; +# Check that 'prefix' is now set as a rough test that the file we read was useful. +if ((not exists $anvil->data->{base}{prefix}) or ($anvil->data->{base}{prefix} eq "")) +{ + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0241", variables => { file => $anvil->data->{switches}{config} }}); + $anvil->nice_exit({exit_code => 1}); +} + +# Find myself +find_myself($anvil); +if (not $anvil->data->{striker}{i_am}) +{ + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0242", variables => { file => $anvil->data->{switches}{config} }}); + $anvil->nice_exit({exit_code => 1}); +} + +# If I am not configured, configure myself now. +#my $configured = $anvil->System->check_if_configured; +my $configured = 0; +$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { configured => $configured }}); +if ($configured) +{ + # If I am not Striker 1, I am done. + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "striker::i_am" => $anvil->data->{striker}{i_am} }}); + if ($anvil->data->{striker}{i_am} ne "1") + { + # We're done. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "message_0221", variables => { striker => $anvil->data->{striker}{i_am} }}); + $anvil->nice_exit({exit_code => 0}); + } +} +else +{ + # Do the initial setup of ourselves. + striker_stage1($anvil); +} + +#print Dumper $anvil->data->{base}; +#print Dumper $anvil->data->{striker}; $anvil->nice_exit({exit_code => 0}); + + + +############################################################################################################# +# Functions # +############################################################################################################# + +# This preps and requests the initial configuration job. +sub striker_stage1 +{ + my ($anvil) = @_; + + ### TODO: Validate all steps up front before starting anything. + if ((not defined $anvil->data->{base}{organization_name}) or (not $anvil->data->{base}{organization_name})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0243", variables => { variable => 'base::organization_name' }}); + $anvil->nice_exit({exit_code => 1}); + } + if ((not defined $anvil->data->{base}{prefix}) or (not $anvil->data->{base}{prefix})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0243", variables => { variable => 'base::prefix' }}); + $anvil->nice_exit({exit_code => 1}); + } + elsif (length($anvil->data->{base}{prefix}) > 5) + { + # Prefix is too long + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0244", variables => { + prefix => $anvil->data->{base}{prefix}, + 'length' => length($anvil->data->{base}{prefix}), + }}); + $anvil->nice_exit({exit_code => 1}); + } + if ((not defined $anvil->data->{base}{domain}) or (not $anvil->data->{base}{domain})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0243", variables => { variable => 'base::domain' }}); + $anvil->nice_exit({exit_code => 1}); + } + elsif (not $anvil->Validate->domain_name({name => $anvil->data->{base}{domain}})) + { + # Domain is not valid + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0117", variables => { name => $anvil->data->{base}{domain} }}); + $anvil->nice_exit({exit_code => 1}); + } + if ((not defined $anvil->data->{base}{password}{desired}) or (not $anvil->data->{base}{password}{desired})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0243", variables => { variable => 'base::password::desired' }}); + $anvil->nice_exit({exit_code => 1}); + } + if ((not defined $anvil->data->{base}{dns}) or (not $anvil->data->{base}{dns})) + { + $anvil->data->{base}{dns} = "8.8.8.8,8.8.4.4"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "base::dns" => $anvil->data->{base}{dns} }}); + } + else + { + # Make sure any/all DNS are valid. + foreach my $ip (split/,/, $anvil->data->{base}{dns}) + { + if (not $anvil->Validate->ipv4({ip => $ip})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0245", variables => { ip => $ip }}); + $anvil->nice_exit({exit_code => 1}); + } + } + } + if ((defined $anvil->data->{base}{gateway}) && ($anvil->data->{base}{gateway})) + { + if (not $anvil->Validate->ipv4({ip => $anvil->data->{base}{gateway}})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0246", variables => { ip => $anvil->data->{base}{gateway} }}); + $anvil->nice_exit({exit_code => 1}); + } + } + + my $striker_number = $anvil->data->{striker}{i_am}; + my $organization_name = $anvil->data->{base}{organization_name}; + my $prefix = $anvil->data->{base}{prefix}; + my $domain = $anvil->data->{base}{domain}; + my $ifn_count = keys %{$anvil->data->{striker}{$striker_number}{network}{ifn}}; + my $host_name = $prefix."-striker0".$striker_number.".".$domain; + my $new_password = $anvil->data->{base}{password}{desired}; + my $dns = $anvil->data->{base}{dns}; + my $gateway = $anvil->data->{base}{gateway}; + my $gateway_network = defined $anvil->data->{base}{gateway_network} ? $anvil->data->{base}{gateway_network} : "ifn1"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + striker_number => $striker_number, + organization_name => $organization_name, + prefix => $prefix, + domain => $domain, + ifn_count => $ifn_count, + host_name => $host_name, + new_password => $anvil->Log->is_secure($new_password), + dns => $dns, + gateway => $gateway, + gateway_network => $gateway_network, + }}); + + # Load the variables. + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::organization::value'}{variable_value} = $organization_name; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::organization::value'}{variable_description} = "striker_0004"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::organization::value'}{variable_section} = "config_step1"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::prefix::value'}{variable_value} = $prefix; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::prefix::value'}{variable_description} = "striker_0006"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::prefix::value'}{variable_section} = "config_step1"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::domain::value'}{variable_value} = $domain; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::domain::value'}{variable_description} = "striker_0008"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::domain::value'}{variable_section} = "config_step1"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::ifn_count::value'}{variable_value} = $ifn_count; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::ifn_count::value'}{variable_description} = "striker_0012"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::ifn_count::value'}{variable_section} = "config_step1"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::sequence::value'}{variable_value} = $striker_number; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::sequence::value'}{variable_description} = "striker_0010"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step1::sequence::value'}{variable_section} = "config_step1"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::host_name::value'}{variable_value} = $host_name; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::host_name::value'}{variable_description} = "striker_0017"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::host_name::value'}{variable_section} = "config_step2"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::striker_user::value'}{variable_value} = "admin"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::striker_user::value'}{variable_description} = "striker_0032"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::striker_user::value'}{variable_section} = "config_step2"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::striker_password::value'}{variable_value} = $new_password; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::striker_password::value'}{variable_description} = "striker_0034"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::striker_password::value'}{variable_section} = "config_step2"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::dns::value'}{variable_value} = $dns; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::dns::value'}{variable_description} = "striker_0038"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::dns::value'}{variable_section} = "config_step2"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::gateway::value'}{variable_value} = $gateway; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::gateway::value'}{variable_description} = "striker_0036"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::gateway::value'}{variable_section} = "config_step2"; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::gateway_interface::value'}{variable_value} = $gateway_network; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::gateway_interface::value'}{variable_description} = ""; + $anvil->data->{striker}{stage1}{variables}{'form::config_step2::gateway_interface::value'}{variable_section} = "config_step2"; + foreach my $network (sort {$a cmp $b} keys %{$anvil->data->{striker}{$striker_number}{network}}) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network => $network }}); + foreach my $network_number (sort {$a cmp $b} keys %{$anvil->data->{striker}{$striker_number}{network}{$network}}) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_number => $network_number }}); + if ((not defined $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{ip}) or (not $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{ip})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0243", variables => { + variable => "striker::${striker_number}::network::${network}::${network_number}::ip", + }}); + $anvil->nice_exit({exit_code => 1}); + } + elsif (not $anvil->Validate->ipv4({ip => $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{ip}})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0247", variables => { + variable => "striker::${striker_number}::network::${network}::${network_number}::ip", + value => $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{ip}, + }}); + $anvil->nice_exit({exit_code => 1}); + } + if ((not defined $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{subnet_mask}) or (not $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{subnet_mask})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0243", variables => { + variable => "striker::${striker_number}::network::${network}::${network_number}::subnet_mask", + }}); + $anvil->nice_exit({exit_code => 1}); + } + elsif (not $anvil->Validate->ipv4({ip => $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{subnet_mask}})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0247", variables => { + variable => "striker::${striker_number}::network::${network}::${network_number}::subnet_mask", + value => $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{subnet_mask}, + }}); + $anvil->nice_exit({exit_code => 1}); + } + if ((not defined $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{'link'}{1}{mac}) or (not $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{'link'}{1}{mac})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0243", variables => { + variable => "striker::${striker_number}::network::${network}::${network_number}::link::1::mac", + }}); + $anvil->nice_exit({exit_code => 1}); + } + + my $ip_key = "form::config_step2::".$network.$network_number."_ip::value"; + my $ip = $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{ip}; + my $subnet_mask_key = "form::config_step2::".$network.$network_number."_subnet_mask::value"; + my $subnet_mask = $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{subnet_mask}; + my $link1_mac_key = "form::config_step2::".$network.$network_number."_link1_mac_to_set::value"; + my $link1_mac = $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{'link'}{1}{mac}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:ip_key' => $ip_key, + 's2:ip' => $ip, + 's3:subnet_mask_key' => $subnet_mask_key, + 's4:subnet_mask' => $subnet_mask, + 's4:link1_mac_key' => $link1_mac_key, + 's5:link1_mac' => $link1_mac, + }}); + + $anvil->data->{striker}{stage1}{variables}{$ip_key}{variable_value} = $ip; + $anvil->data->{striker}{stage1}{variables}{$ip_key}{variable_description} = "striker_0024"; + $anvil->data->{striker}{stage1}{variables}{$ip_key}{variable_section} = "config_step2"; + $anvil->data->{striker}{stage1}{variables}{$subnet_mask_key}{variable_value} = $subnet_mask; + $anvil->data->{striker}{stage1}{variables}{$subnet_mask_key}{variable_description} = "striker_0025"; + $anvil->data->{striker}{stage1}{variables}{$subnet_mask_key}{variable_section} = "config_step2"; + $anvil->data->{striker}{stage1}{variables}{$link1_mac_key}{variable_value} = $link1_mac; + $anvil->data->{striker}{stage1}{variables}{$link1_mac_key}{variable_description} = "striker_0029"; + $anvil->data->{striker}{stage1}{variables}{$link1_mac_key}{variable_section} = "config_step2"; + + if (exists $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{'link'}{2}) + { + if ((not defined $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{'link'}{2}{mac}) or (not $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{'link'}{2}{mac})) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0243", variables => { + variable => "striker::${striker_number}::network::${network}::${network_number}::link::2::mac", + }}); + $anvil->nice_exit({exit_code => 1}); + } + my $link2_mac_key = "form::config_step2::".$network.$network_number."_link2_mac_to_set::value"; + my $link2_mac = $anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{'link'}{2}{mac}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:link2_mac_key' => $link2_mac_key, + 's2:link2_mac' => $link2_mac, + }}); + $anvil->data->{striker}{stage1}{variables}{$link2_mac_key}{variable_value} = $link2_mac; + $anvil->data->{striker}{stage1}{variables}{$link2_mac_key}{variable_description} = "striker_0029"; + $anvil->data->{striker}{stage1}{variables}{$link2_mac_key}{variable_section} = "config_step2"; + } + } + } + + # Now, for each variable, record it to the database. + foreach my $variable (sort {$a cmp $b} keys %{$anvil->data->{striker}{stage1}{variables}}) + { + my $value = $anvil->data->{striker}{stage1}{variables}{$variable}{variable_value}; + my $description = $anvil->data->{striker}{stage1}{variables}{$variable}{variable_description}; + my $section = $anvil->data->{striker}{stage1}{variables}{$variable}{variable_section}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:variable' => $variable, + 's2:value' => $value, + 's3:description' => $description, + 's4:section' => $section, + }}); + + my ($variable_uuid) = $anvil->Database->insert_or_update_variables({ + variable_name => $variable, + variable_value => $value, + variable_default => "", + variable_description => $description, + variable_section => $section, + variable_source_uuid => $anvil->Get->host_uuid, + variable_source_table => "hosts", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { variable_uuid => $variable_uuid }}); + + } + + return(0); +} + +# This looks to see if we can map a 'striker::X::' to this machine. +sub find_myself +{ + my ($anvil) = @_; + + # Find my MAC addresses. + my $short_host_name = $anvil->Get->short_host_name(); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { short_host_name => $short_host_name }}); + + $anvil->Network->get_ips({debug => 3}); + +# print Dumper $anvil->data->{network}{$short_host_name}{interface}; +# foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$short_host_name}{interface}}) +# { +# print "Interface: [".$interface."]\n"; +# } +# die; + + $anvil->data->{striker}{i_am} = 0; + foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$short_host_name}{interface}}) + { + my $ip_address = $anvil->data->{network}{$short_host_name}{interface}{$interface}{ip}; + my $subnet_mask = $anvil->data->{network}{$short_host_name}{interface}{$interface}{subnet_mask}; + my $mac_address = $anvil->data->{network}{$short_host_name}{interface}{$interface}{mac_address}; + my $mtu = $anvil->data->{network}{$short_host_name}{interface}{$interface}{mtu}; + my $default_gateway = $anvil->data->{network}{$short_host_name}{interface}{$interface}{default_gateway}; + my $gateway = $anvil->data->{network}{$short_host_name}{interface}{$interface}{gateway}; + my $dns = $anvil->data->{network}{$short_host_name}{interface}{$interface}{dns}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + interface => $interface, + ip_address => $ip_address, + subnet_mask => $subnet_mask, + mac_address => $mac_address, + mtu => $mtu, + default_gateway => $default_gateway, + gateway => $gateway, + dns => $dns, + }}); + + foreach my $striker_number (sort {$a cmp $b} keys %{$anvil->data->{striker}}) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { striker_number => $striker_number }}); + foreach my $network (sort {$a cmp $b} keys %{$anvil->data->{striker}{$striker_number}{network}}) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network => $network }}); + foreach my $network_number (sort {$a cmp $b} keys %{$anvil->data->{striker}{$striker_number}{network}{$network}}) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_number => $network_number }}); + foreach my $link_number (sort {$a cmp $b} keys %{$anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{'link'}}) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { link_number => $link_number }}); + + my $this_mac_address = lc($anvil->data->{striker}{$striker_number}{network}{$network}{$network_number}{'link'}{$link_number}{mac}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + mac_address => $mac_address, + this_mac_address => $this_mac_address, + }}); + if ((not $anvil->data->{striker}{i_am}) && ($this_mac_address eq $mac_address)) + { + # This is us. + $anvil->data->{striker}{i_am} = $striker_number; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "striker::i_am" => $anvil->data->{striker}{i_am} }}); + return($anvil->data->{striker}{i_am}); + } + } + } + } + } + } + + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { i_am_striker => $anvil->data->{striker}{i_am} }}); + return($anvil->data->{striker}{i_am}); +} + diff --git a/tools/striker-auto-initialize-all.example b/tools/striker-auto-initialize-all.example index 7e92e2dd..1eee2994 100644 --- a/tools/striker-auto-initialize-all.example +++ b/tools/striker-auto-initialize-all.example @@ -1,20 +1,51 @@ # This is an example script to feed to 'striker-auto-initialize-all'. # -base::password::current = Initial1 -base::password::desired = super secret password +############################################################################################################# +# Common values # +############################################################################################################# +# This is the listed owner, department or organization who this Anvil! serves. base::organization_name = Alteeve's Niche! + +# The prefix for the Anvil! system. The can be up to five characters long. base::prefix = an + +# This is the domain to use for the Anvil! and member machine host names. base::domain = alteeve.com + +# These are the DNS server to use when configuring networks, comma separated. base::dns = 8.8.8.8,8.8.4.4 + +# This is the default gateway for the IFN base::gateway = 192.168.122.1 -base::interface = ifn1 +# This is the IFN network on which the gateway will be configured. +base::gateway_network = ifn1 + +# This is the startup password for newly built nodes and DR hosts we'll be integrating. +base::password::current = Initial1 + +# This is the password to set for all systems. +base::password::desired = super secret password + + +############################################################################################################# +# Striker configurations # +############################################################################################################# # Startup IP is used for peers to find us -striker::1::network::startup_ip = 192.168.122.145 +striker::1::startup_ip = 192.168.122.145 striker::1::network::ifn::1::ip = 192.168.122.11 striker::1::network::ifn::1::subnet_mask = 255.255.255.0 -striker::1::network::ifn::1::link::1::mac = aa:bb:cc:dd:ee:ff -striker::1::network::bcn::1::ip = 192.168.122.11 -striker::1::network::bcn::1::subnet_mask = 255.255.255.0 -striker::1::network::bcn::1::link::1::mac = aa:bb:cc:dd:ff:00 +striker::1::network::ifn::1::link::1::mac = 52:54:00:ac:50:e4 +striker::1::network::bcn::1::ip = 10.201.4.1 +striker::1::network::bcn::1::subnet_mask = 255.255.0.0 +striker::1::network::bcn::1::link::1::mac = 52:54:00:68:be:2e + +striker::2::startup_ip = 192.168.122.146 +striker::2::network::ifn::1::ip = 192.168.122.12 +striker::2::network::ifn::1::subnet_mask = 255.255.255.0 +striker::2::network::ifn::1::link::1::mac = 52:54:00:c0:f2:7c +striker::2::network::bcn::1::ip = 192.168.122.12 +striker::2::network::bcn::1::subnet_mask = 255.255.255.0 +striker::2::network::bcn::1::link::1::mac = 52:54:00:8b:d6:82 +