* Updated Jobs->get_job_details() to use --job-uuid switch or, failing that, look for an incomplete on this host with the same command as the calling program.

* Got anvil-join-anvil to the point that it reworks the network configs, updates MTUs and configured NTP.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 5 years ago
parent 7a247aca4e
commit 530fb31478
  1. 2
      Anvil/Tools.pm
  2. 48
      Anvil/Tools/Job.pm
  3. 23
      Anvil/Tools/Network.pm
  4. 25
      share/words.xml
  5. 2
      tools/anvil-configure-host
  6. 811
      tools/anvil-join-anvil
  7. 16
      tools/anvil-manage-firewall
  8. 8
      tools/anvil-update-states

@ -1071,6 +1071,7 @@ sub _set_paths
}, },
data => { data => {
'.htpasswd' => "/etc/httpd/.htpasswd", '.htpasswd' => "/etc/httpd/.htpasswd",
'chrony.conf' => "/etc/chrony.conf",
group => "/etc/group", group => "/etc/group",
issue => "/etc/issue", issue => "/etc/issue",
httpd_conf => "/etc/httpd/conf/httpd.conf", httpd_conf => "/etc/httpd/conf/httpd.conf",
@ -1130,6 +1131,7 @@ sub _set_paths
cat => "/usr/bin/cat", cat => "/usr/bin/cat",
'chmod' => "/usr/bin/chmod", 'chmod' => "/usr/bin/chmod",
'chown' => "/usr/bin/chown", 'chown' => "/usr/bin/chown",
chronyc => "/usr/bin/chronyc",
cibadmin => "/usr/sbin/cibadmin", cibadmin => "/usr/sbin/cibadmin",
cp => "/usr/bin/cp", cp => "/usr/bin/cp",
createdb => "/usr/bin/createdb", createdb => "/usr/bin/createdb",

@ -124,7 +124,7 @@ sub clear
=head2 get_job_details =head2 get_job_details
This takes a C<< job_uuid >> and returns the job's details. If the job is found, C<< 0 >> is returned. If it isn't found, C<< 1 >> is returned. If it is found, but C<< check >> was set and the process is still alice, C<< 2 >> is returned. This takes a C<< job_uuid >> and returns the job's details. If the job is found, C<< 0 >> is returned. If it isn't found, C<< 1 >> is returned. If it is found, but C<< check >> was set and the process is still alive, C<< 2 >> is returned.
When successful, the job details will be stored in; When successful, the job details will be stored in;
@ -147,9 +147,9 @@ Parameters;
This checks to see if the job was picked up by a program that is still running. If set to C<< 1 >> and that process is running, this method will return C<< 2 >>. If set to C<< 0 >>, the job data will be loaded (if found) and C<< 0 >> will be returned. This checks to see if the job was picked up by a program that is still running. If set to C<< 1 >> and that process is running, this method will return C<< 2 >>. If set to C<< 0 >>, the job data will be loaded (if found) and C<< 0 >> will be returned.
=head3 job_uuid (required) =head3 job_uuid (optional)
This is the job UUID to pull up. This is the job UUID to pull up. If not passed, first a check is made to see if C<< --job-uuid >> was passed. If not, a check is made in the database for any pending jobs assigned to this host and whose C<< job_command >> matches the calling program.
=cut =cut
sub get_job_details sub get_job_details
@ -169,9 +169,45 @@ sub get_job_details
# Were we passed a job uuid? # Were we passed a job uuid?
if ((not $job_uuid) && (not $anvil->data->{switches}{'job-uuid'})) if ((not $job_uuid) && (not $anvil->data->{switches}{'job-uuid'}))
{ {
$job_uuid = $anvil->data->{switches}{'job-uuid'}; # Try to find a job in the database.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, secure => 0, key => "error_0032", variables => { switch => '--job-uuid' } }); my $command = $0."%";
return(1); my $query = "
SELECT
job_uuid
FROM
jobs
WHERE
job_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
AND
job_progress != 100
AND
job_command LIKE ".$anvil->Database->quote($command)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if ($count)
{
$job_uuid = $results->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { job_uuid => $job_uuid }});
if (($job_uuid) && (not $anvil->data->{switches}{'job-uuid'}))
{
$anvil->data->{switches}{'job-uuid'} = $job_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 'switches::job-uuid' => $anvil->data->{switches}{'job-uuid'} }});
}
}
if (not $job_uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, secure => 0, key => "error_0032", variables => { switch => '--job-uuid' } });
return(1);
}
} }
if (not $anvil->Validate->is_uuid({uuid => $anvil->data->{switches}{'job-uuid'}})) if (not $anvil->Validate->is_uuid({uuid => $anvil->data->{switches}{'job-uuid'}}))

@ -1433,7 +1433,8 @@ This method checks the local system for interfaces and stores them in:
* C<< network::<target>::interface::<iface_name>::ip >> - If an IP address is set * C<< network::<target>::interface::<iface_name>::ip >> - If an IP address is set
* C<< network::<target>::interface::<iface_name>::subnet_mask >> - If an IP is set * C<< network::<target>::interface::<iface_name>::subnet_mask >> - If an IP is set
* C<< network::<target>::interface::<iface_name>::mac >> - Always set. * C<< network::<target>::interface::<iface_name>::mac_address >> - Always set.
* C<< network::<target>::interface::<iface_name>::mtu >> - Always set.
* C<< network::<target>::interface::<iface_name>::default_gateway >> = C<< 0 >> if not the default gateway, C<< 1 >> if so. * C<< network::<target>::interface::<iface_name>::default_gateway >> = C<< 0 >> if not the default gateway, C<< 1 >> if so.
* C<< network::<target>::interface::<iface_name>::gateway >> = If the default gateway, this is the gateway IP address. * C<< network::<target>::interface::<iface_name>::gateway >> = If the default gateway, this is the gateway IP address.
* C<< network::<target>::interface::<iface_name>::dns >> = If the default gateway, this is the comma-separated list of active DNS servers. * C<< network::<target>::interface::<iface_name>::dns >> = If the default gateway, this is the comma-separated list of active DNS servers.
@ -1535,6 +1536,7 @@ sub get_ips
$anvil->data->{network}{$host}{interface}{$in_iface}{ip} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{ip}; $anvil->data->{network}{$host}{interface}{$in_iface}{ip} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{ip};
$anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask}; $anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask};
$anvil->data->{network}{$host}{interface}{$in_iface}{mac_address} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{mac_address}; $anvil->data->{network}{$host}{interface}{$in_iface}{mac_address} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{mac_address};
$anvil->data->{network}{$host}{interface}{$in_iface}{mtu} = 0 if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{mtu};
$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}{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}{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->data->{network}{$host}{interface}{$in_iface}{dns} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{dns};
@ -1567,24 +1569,13 @@ sub get_ips
"s2:network::${host}::interface::${in_iface}::subnet_mask" => $anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask}, "s2:network::${host}::interface::${in_iface}::subnet_mask" => $anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask},
}}); }});
} }
if ($line =~ /ether ([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}) /i) if ($line =~ /mtu (\d+) /i)
{ {
my $mac_address = $1; my $mtu = $1;
$anvil->data->{network}{$host}{interface}{$in_iface}{mac_address} = $mac_address; $anvil->data->{network}{$host}{interface}{$in_iface}{mtu} = $mtu;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"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},
}}); }});
# We only record the mac in 'network::mac' if this isn't a bond.
my $test_file = "/proc/net/bonding/".$in_iface;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { test_file => $test_file }});
if (not -e $test_file)
{
$anvil->data->{network}{mac_address}{$mac_address}{iface} = $in_iface;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"network::mac_address::${mac_address}::iface" => $anvil->data->{network}{mac_address}{$mac_address}{iface},
}});
}
} }
} }

@ -66,7 +66,7 @@ Author: Madison Kelly <mkelly@alteeve.ca>
<key name="error_0029"><![CDATA[Failed to find the template: [<span class="code">#!variable!template!#</span>] in the template file: [<span class="code">#!variable!file!#</span>].]]></key> <key name="error_0029"><![CDATA[Failed to find the template: [<span class="code">#!variable!template!#</span>] in the template file: [<span class="code">#!variable!file!#</span>].]]></key>
<key name="error_0030"><![CDATA[Failed to process the template: [<span class="code">#!variable!template!#</span>] in the template file: [<span class="code">#!variable!file!#</span>]. Details of the problem should be in: [<span class="code">#!data!path::log::main!#</span>].]]></key> <key name="error_0030"><![CDATA[Failed to process the template: [<span class="code">#!variable!template!#</span>] in the template file: [<span class="code">#!variable!file!#</span>]. Details of the problem should be in: [<span class="code">#!data!path::log::main!#</span>].]]></key>
<key name="error_0031">The 'host-uuid': [#!variable!host_uuid!#] is not valid.</key> <key name="error_0031">The 'host-uuid': [#!variable!host_uuid!#] is not valid.</key>
<key name="error_0032">The '#!variable!switch!#' switch is missing.</key> <key name="error_0032">The '#!variable!switch!#' switch is missing and no pending job was found.</key>
<key name="error_0033">The job UUID was passed via '--job-uuid' but the passed in value: [#!variable!uuid!#] is not a valid UUID.</key> <key name="error_0033">The job UUID was passed via '--job-uuid' but the passed in value: [#!variable!uuid!#] is not a valid UUID.</key>
<key name="error_0034">The job UUID was passed via '--job-uuid': [#!variable!uuid!#] doesn't match a job in the database.</key> <key name="error_0034">The job UUID was passed via '--job-uuid': [#!variable!uuid!#] doesn't match a job in the database.</key>
<key name="error_0035"> <key name="error_0035">
@ -129,7 +129,7 @@ Failed to generate an RSA public key for the user: [#!variable!user!#]. The outp
<key name="error_0077">Unable to connect to the database, unable to read the details of the key to remove.</key> <key name="error_0077">Unable to connect to the database, unable to read the details of the key to remove.</key>
<key name="error_0078">Did not find any offending keys on this host, exiting.</key> <key name="error_0078">Did not find any offending keys on this host, exiting.</key>
<key name="error_0079">Job data not found for job_uuid: [#!variable!job_uuid!#].</key> <key name="error_0079">Job data not found for job_uuid: [#!variable!job_uuid!#].</key>
<key name="error_0080">No job UUID was passwed .</key> <key name="error_0080">No job UUID was passed .</key>
<key name="error_0081">The job_uuid: [#!variable!job_uuid!#] appears valid, but there was no job_data.</key> <key name="error_0081">The job_uuid: [#!variable!job_uuid!#] appears valid, but there was no job_data.</key>
<key name="error_0082">The state UUID: [#!variable!state_uuid!#] does not appear to be a valid UUID.</key> <key name="error_0082">The state UUID: [#!variable!state_uuid!#] does not appear to be a valid UUID.</key>
<key name="error_0083">No (good) state UUIDs found, unable to run this job.</key> <key name="error_0083">No (good) state UUIDs found, unable to run this job.</key>
@ -187,6 +187,7 @@ The error was:
<key name="error_0126">The IP address: [#!variable!ip!#] does not appear to be in the network: [#!variable!network!#].</key> <key name="error_0126">The IP address: [#!variable!ip!#] does not appear to be in the network: [#!variable!network!#].</key>
<key name="error_0127">I was asked to delete and entry from: [#!variable!table!#] but neither the name or UUID was passed.</key> <key name="error_0127">I was asked to delete and entry from: [#!variable!table!#] but neither the name or UUID was passed.</key>
<key name="error_0128">The host UUID: [#!variable!uuid!#] was set as the value for: [#!variable!column!#], but that host doesn't appear to exist.</key> <key name="error_0128">The host UUID: [#!variable!uuid!#] was set as the value for: [#!variable!column!#], but that host doesn't appear to exist.</key>
<key name="error_0129">Unable to connect to any database, unable to read the job details.</key>
<!-- Table headers --> <!-- Table headers -->
<key name="header_0001">Current Network Interfaces and States</key> <key name="header_0001">Current Network Interfaces and States</key>
@ -288,7 +289,7 @@ Failure! The return code: [#!variable!return_code!#] was received ('0' was expec
<key name="job_0052">[ Error ] - There was a problem reading the known hosts file: [#!variable!file!#]. Skipping it.</key> <key name="job_0052">[ Error ] - There was a problem reading the known hosts file: [#!variable!file!#]. Skipping it.</key>
<key name="job_0053">Found an entry for the target at line: [#!variable!line!#], removing it.</key> <key name="job_0053">Found an entry for the target at line: [#!variable!line!#], removing it.</key>
<key name="job_0054">[ Error ] - The line number: [#!variable!line!#] in: [#!variable!file!#] does not appear to be for the target: [#!variable!target!#]. Has the file already been updated? Skipping it.</key> <key name="job_0054">[ Error ] - The line number: [#!variable!line!#] in: [#!variable!file!#] does not appear to be for the target: [#!variable!target!#]. Has the file already been updated? Skipping it.</key>
<key name="job_0055">Rewriing: [#!variable!file!#].</key> <key name="job_0055">Rewriting: [#!variable!file!#].</key>
<key name="job_0056">Manage Keys</key> <key name="job_0056">Manage Keys</key>
<key name="job_0057">The selected bad key(s) will be removed from the specified files.</key> <key name="job_0057">The selected bad key(s) will be removed from the specified files.</key>
<key name="job_0058">The state UUID: [#!variable!state_uuid!#] is for the machine with the host UUID: [#!variable!host_uuid!#], which is not us. This is probably a progrem error, skipping this.</key> <key name="job_0058">The state UUID: [#!variable!state_uuid!#] is for the machine with the host UUID: [#!variable!host_uuid!#], which is not us. This is probably a progrem error, skipping this.</key>
@ -307,6 +308,24 @@ Failure! The return code: [#!variable!return_code!#] was received ('0' was expec
<key name="job_0071">The network configuration will be updated based on the variables stored in the database. When complete, the system will reboot.</key> <key name="job_0071">The network configuration will be updated based on the variables stored in the database. When complete, the system will reboot.</key>
<key name="job_0072">Join this machine to an #!string!brand_0006!#.</key> <key name="job_0072">Join this machine to an #!string!brand_0006!#.</key>
<key name="job_0073">This machine will join an #!string!brand_0006!# as a node or DR host. The role and #!string!brand_0006!# will be determined by the associated Install Manifest UUID.</key> <key name="job_0073">This machine will join an #!string!brand_0006!# as a node or DR host. The role and #!string!brand_0006!# will be determined by the associated Install Manifest UUID.</key>
<key name="job_0074">'Join #!string!brand_0002!#' job: [#!variable!job-uuid!#] picked up.</key>
<key name="job_0075">This will become: [#!variable!machine!#] using data from the install manifest UUID: [#!variable!manifest_uuid!#].</key>
<key name="job_0076">[ Error ] - Failed to load and parse the install manifest. Details will be found in the logs.</key>
<key name="job_0077">The host name is already: [#!variable!host_name!#], no change needed.</key>
<key name="job_0078">Updating the network configuration for: [#!variable!interface!#].</key>
<key name="job_0079">Disconnected from all database(s). Will reconnect after the network configuration changes have taken effect.</key>
<key name="job_0080">About to update the network, as necessary.</key>
<key name="job_0081">Checking: [#!variable!name!#].</key>
<key name="job_0082">No changes needed.</key>
<key name="job_0083">Backing up and writting out the new version of: [#!variable!file!#].</key>
<key name="job_0084">Reconnected to: [#!data!sys::database::connections!#] database(s).</key>
<key name="job_0085">The default 'virbr0' libvirtd bridge exists. Removing it.</key>
<key name="job_0086">Checking if the MTU needs to be updated on any interfaces.</key>
<key name="job_0087">The MTU on the interface: [#!variable!interface!#] is already: [#!variable!mtu!#] bytes, no update needed.</key>
<key name="job_0088">The MTU on the interface: [#!variable!interface!#] is currently: [#!variable!old_mtu!#] bytes, changing it to: [#!variable!mtu!#] bytes now.</key>
<key name="job_0089">Adding NTP (network time protocol) servers, if needed.</key>
<key name="job_0090">Adding the NTP server: [#!variable!server!#].</key>
<key name="job_0091">Restarting the daemon: [#!variable!daemon!#].</key>
<!-- Log entries --> <!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key> <key name="log_0001">Starting: [#!variable!program!#].</key>

@ -11,6 +11,8 @@
# 5 = Failed to write the temp file with the new password needed to call anvil-change-password. # 5 = Failed to write the temp file with the new password needed to call anvil-change-password.
# 6 = The job-uuid was not found. # 6 = The job-uuid was not found.
# #
# TODO: Add MTU support
#
use strict; use strict;
use warnings; use warnings;

@ -4,6 +4,10 @@
# #
# Exit codes; # Exit codes;
# 0 = Normal exit. # 0 = Normal exit.
# 1 = Failed to connect to any database.
# 2 = Failed to load/parse the manifest.
# 3 = Failed to change the host name.
# 4 = Failed to reconnect to any database after the network was reconfigured
# #
# TODO: # TODO:
# #
@ -37,11 +41,14 @@ if (not $anvil->data->{sys}{database}{connections})
{ {
# No databases, update the job, sleep for a bit and then exit. The daemon will pick it up and try # No databases, update the job, sleep for a bit and then exit. The daemon will pick it up and try
# again after we exit. # again after we exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0077"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0129"});
sleep 10; sleep 10;
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
# Get the job details
load_job($anvil);
# Load in the manifest # Load in the manifest
load_manifest($anvil); load_manifest($anvil);
@ -60,7 +67,767 @@ sub check_local_network
{ {
my ($anvil) = @_; my ($anvil) = @_;
# What host name and IP(s) should I have?
my $machine = $anvil->data->{sys}{machine};
my $manifest_uuid = $anvil->data->{sys}{manifest_uuid};
my $anvil_name = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{name};
my $domain = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{domain};
my $old_host_name = $anvil->_host_name;
my $new_host_name = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{machine}{$machine}{name};
if ($domain)
{
$new_host_name = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{machine}{$machine}{name}.".".$domain;
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:anvil_name' => $anvil_name,
's2:domain' => $domain,
's3:old_host_name' => $old_host_name,
's4:new_host_name' => $new_host_name,
}});
# If the hostname isn't the same, change it.
if ($old_host_name ne $new_host_name)
{
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0061,!!host_name!".$new_host_name."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0061", variables => { host_name => $new_host_name }});
my ($now_host_name) = $anvil->System->host_name({
debug => 2,
set => $new_host_name,
});
if ($now_host_name eq $new_host_name)
{
# Success!
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0045");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0045"});
}
else
{
# Failed
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "job_0063", variables => {
host_name => $new_host_name,
current_host_name => $now_host_name,
}});
update_progress($anvil, 0, "job_0063,!!host_name!".$new_host_name."!!,!!current_host_name!".$now_host_name."!!");
sleep 10;
$anvil->nice_exit({code => 3});
}
}
else
{
# No need to change
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0077,!!host_name!".$new_host_name."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0077", variables => { host_name => $new_host_name }});
}
# Read the local network manager data.
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0080");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0080"});
$anvil->Network->read_nmcli({debug => 3});
# Now check IP addresses.
$anvil->Network->get_ips({debug => 3});
# This will be set when the first IFN with a gateway is set.
my $default_gateway_interface = "";
foreach my $in_iface (sort {$a cmp $b} keys %{$anvil->data->{network}{'local'}{interface}})
{
if ($anvil->data->{network}{'local'}{interface}{$in_iface}{default_gateway})
{
$default_gateway_interface = $in_iface;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { default_gateway_interface => $default_gateway_interface }});
last;
}
}
my $dns = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{networks}{dns};
my $mtu = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{networks}{mtu};
my $ntp = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{networks}{ntp};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
dns => $dns,
mtu => $mtu,
ntp => $ntp,
}});
# The DNS are comma-separated lists, that may or may not have spaces and may or may not be in
# alphabetical order. To properly compare, we'll rebuild the CSV string of the current and desired
# DNS settings.
my $cleaned_dns = "";
my @dns_array = split/,/, $dns;
foreach my $this_dns (sort {$a cmp $b} @dns_array)
{
$this_dns = $anvil->Words->clean_spaces({ string => $this_dns });
$cleaned_dns .= $this_dns.",";
}
$cleaned_dns =~ s/,$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { cleaned_dns => $cleaned_dns }});
# If any network interface is changed, we'll write out the config file then, when done, disconnect
# from the database, restart networking and then reconnect before moving on.
my $restart_interfaces = [];
foreach my $network (sort {$a cmp $b} keys %{$anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{machine}{$machine}{network}})
{
my $ip = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{machine}{$machine}{network}{$network}{ip};
my $subnet = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{networks}{name}{$network}{subnet};
my $cidr = $anvil->Convert->cidr({subnet_mask => $subnet});
my $gateway = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{parsed}{networks}{name}{$network}{gateway};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:network' => $network,
's2:ip' => $ip,
's3:subnet' => $subnet,
's4:cidr' => $cidr,
's5:gateway' => $gateway,
}});
foreach my $in_iface (sort {$a cmp $b} keys %{$anvil->data->{network}{'local'}{interface}})
{
# Only one interface will start with the network name and have an IP address.
next if $in_iface !~ /^${network}_/;
next if not $anvil->data->{network}{'local'}{interface}{$in_iface}{ip};
my $current_ip = $anvil->data->{network}{'local'}{interface}{$in_iface}{ip};
my $current_subnet = $anvil->data->{network}{'local'}{interface}{$in_iface}{subnet_mask};
my $current_gateway = $anvil->data->{network}{'local'}{interface}{$in_iface}{gateway};
my $current_dns = $anvil->data->{network}{'local'}{interface}{$in_iface}{dns};
my $current_mtu = $anvil->data->{network}{'local'}{interface}{$in_iface}{mtu};
my $mac_address = $anvil->data->{network}{'local'}{interface}{$in_iface}{mac_address};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:in_iface' => $in_iface,
's2:current_ip' => $current_ip,
's4:current_subnet' => $current_subnet,
's5:current_gateway' => $current_gateway,
's6:current_dns' => $current_dns,
's7:current_mtu' => $current_mtu,
}});
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0081,!!name!".$in_iface."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0081", variables => { name => $in_iface }});
if ((not $default_gateway_interface) && ($in_iface =~ /^ifn/) && ($gateway))
{
# No existing default gateway, but this is the first IFN we've seen with a
# gateway defined, so we'll use this one.
$default_gateway_interface = $in_iface;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { default_gateway_interface => $default_gateway_interface }});
}
my $cleaned_current_dns = "";
my @current_dns_array = split/,/, $current_dns;
foreach my $this_current_dns (sort {$a cmp $b} @current_dns_array)
{
$this_current_dns = $anvil->Words->clean_spaces({ string => $this_current_dns });
$cleaned_current_dns .= $this_current_dns.",";
}
$cleaned_current_dns =~ s/,$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { cleaned_current_dns => $cleaned_current_dns }});
my $change = 0;
if (($current_ip ne $ip) or ($current_subnet ne $subnet))
{
# IP / subnet changed.
print "IP: .... [".$current_ip."] -> [".$ip."]\n";
print "Subnet: [".$current_subnet."] -> [".$subnet."]\n";
$change = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { change => $change }});
}
# gateway?
if ($current_gateway ne $gateway)
{
print "Gateway: [".$current_gateway."] -> [".$gateway."]\n";
$change = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { change => $change }});
}
# Check DNS only if gateway is set.
if ($gateway)
{
if ($cleaned_dns ne $cleaned_current_dns)
{
print "DNS: ... [".$cleaned_current_dns."] -> [".$cleaned_dns."]\n";
$change = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { change => $change }});
}
elsif (($in_iface eq $default_gateway_interface) && (not $anvil->data->{network}{'local'}{interface}{$in_iface}{default_gateway}))
{
# This isn't the default gateway yet, but we'll make it so.
print "Will set as default gateway\n";
$change = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { change => $change }});
}
}
if (not $change)
{
# No change
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0082");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0082"});
}
else
{
# Update the config.
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0078,!!interface!".$in_iface."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0078", variables => { interface => $in_iface }});
my $interface_uuid = $anvil->data->{nmcli}{'local'}{device_to_uuid}{$in_iface};
my $filename = $anvil->data->{nmcli}{'local'}{uuid}{$interface_uuid}{filename};
my $interface_name = $anvil->data->{nmcli}{'local'}{uuid}{$interface_uuid}{name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:in_iface' => $in_iface,
's2:interface_name' => $interface_name,
's3:filename' => $filename,
's4:interface_uuid' => $interface_uuid,
}});
# Record the name to restart
push @{$restart_interfaces}, $interface_name;
# Read in the file. We'll update the date stamp and change the variables as
# needed and write it back out.
my $ip_seen = 0;
my $subnet_seen = 0;
my $gateway_seen = 0;
my $dns_seen = 0;
my $mtu_seen = 0;
my $boot_proto_seen = 0;
my $defroute_seen = 0;
my $say_default = $default_gateway_interface eq $in_iface ? "YES" : "NO";
my $new_config = "";
my $old_config = $anvil->Storage->read_file({file => $filename});
foreach my $line (split/\n/, $old_config)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
if ($line =~ /^BOOTPROTO="(.*?)"/)
{
my $boot_protocol = $1;
$boot_proto_seen = 1;
$new_config .= "BOOTPROTO=\"none\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:boot_proto_seen' => $boot_proto_seen,
's2:boot_protocol' => $boot_protocol,
's3:new_config' => $new_config,
}});
if ($boot_protocol eq "dhcp")
{
# Inject the network config.
if (not $ip_seen)
{
$ip_seen = 1;
$new_config .= "IPADDR=\"".$ip."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:ip_seen' => $boot_proto_seen,
's2:new_config' => $new_config,
}});
}
if (not $subnet_seen)
{
if ($cidr)
{
$new_config .= "PREFIX=\"".$cidr."\"\n";
}
else
{
$new_config .= "NETMASK=\"".$subnet."\"\n";
}
$subnet_seen = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:subnet_seen' => $subnet_seen,
's2:new_config' => $new_config,
}});
}
if (($gateway) && (not $gateway_seen))
{
$gateway_seen = 1;
$new_config .= "GATEWAY=\"".$gateway."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:gateway_seen' => $gateway_seen,
's2:new_config' => $new_config,
}});
}
if (not $defroute_seen)
{
$defroute_seen = 1;
$new_config .= "DEFROUTE=\"".$say_default."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:defroute_seen' => $defroute_seen,
's2:new_config' => $new_config,
}});
}
if (($default_gateway_interface eq $in_iface) && ($cleaned_dns))
{
if (not $dns_seen)
{
my $i = 1;
foreach my $this_dns (split/,/, $cleaned_dns)
{
$new_config .= "DNS".$i."=\"".$this_dns."\"\n";
$i++;
}
$dns_seen = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:dns_seen' => $dns_seen,
's2:new_config' => $new_config,
}});
}
}
}
}
elsif ($line =~ /^IPADDR=".*?"/)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ip_seen => $ip_seen }});
if (not $ip_seen)
{
$ip_seen = 1;
$new_config .= "IPADDR=\"".$ip."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:ip_seen' => $boot_proto_seen,
's2:new_config' => $new_config,
}});
}
}
elsif (($line =~ /^PREFIX=".*?"/) or ($line =~ /^NETMASK=".*?"/))
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { subnet_seen => $subnet_seen }});
if (not $subnet_seen)
{
$subnet_seen = 1;
if ($cidr)
{
$new_config .= "PREFIX=\"".$cidr."\"\n";
}
else
{
$new_config .= "NETMASK=\"".$subnet."\"\n";
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:subnet_seen' => $subnet_seen,
's2:new_config' => $new_config,
}});
}
}
elsif ($line =~ /^GATEWAY=".*"/)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { gateway_seen => $gateway_seen }});
if (not $gateway_seen)
{
$gateway_seen = 1;
$new_config .= "GATEWAY=\"".$gateway."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:gateway_seen' => $gateway_seen,
's2:new_config' => $new_config,
}});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { gateway_seen => $gateway_seen }});
}
elsif ($line =~ /^DNS=".*"/)
{
# The first time we see a DNS entry, we inject the DNS we've
# got and then ignore the rest.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { dns_seen => $dns_seen }});
if (not $dns_seen)
{
# If there's no DNS, this will do nothing.
my $i = 1;
foreach my $this_dns (split/,/, $cleaned_dns)
{
$new_config .= "DNS".$i."=\"".$this_dns."\"\n";
$i++;
}
$dns_seen = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:dns_seen' => $dns_seen,
's2:new_config' => $new_config,
}});
}
}
elsif ($line =~ /^MTU=".*"/)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mtu_seen => $mtu_seen }});
if (not $mtu_seen)
{
$mtu_seen = 1;
$new_config .= "MTU=\"".$mtu."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:mtu_seen' => $mtu_seen,
's2:new_config' => $new_config,
}});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mtu_seen => $mtu_seen }});
}
elsif ($line =~ /^DEFROUTE=".*"/)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { defroute_seen => $defroute_seen }});
if (not $defroute_seen)
{
$defroute_seen = 1;
$new_config .= "DEFROUTE=\"".$say_default."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:defroute_seen' => $defroute_seen,
's2:new_config' => $new_config,
}});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { defroute_seen => $defroute_seen }});
}
else
{
$new_config .= $line."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { defroute_seen => $defroute_seen }});
}
}
# Add any values I've not yet seen.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
ip_seen => $ip_seen,
subnet_seen => $subnet_seen,
gateway_seen => $gateway_seen,
dns_seen => $dns_seen,
mtu_seen => $mtu_seen,
defroute_seen => $defroute_seen,
}});
if (not $ip_seen)
{
$new_config .= "IPADDR=\"".$ip."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_config => $new_config }});
}
if (not $subnet_seen)
{
if ($cidr)
{
$new_config .= "PREFIX=\"".$cidr."\"\n";
}
else
{
$new_config .= "NETMASK=\"".$subnet."\"\n";
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_config => $new_config }});
}
if (not $gateway_seen)
{
$new_config .= "GATEWAY=\"".$gateway."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_config => $new_config }});
}
if (not $dns_seen)
{
# If there's no DNS, this will do nothing.
my $i = 1;
foreach my $this_dns (split/,/, $cleaned_dns)
{
$new_config .= "DNS".$i."=\"".$this_dns."\"\n";
$i++;
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_config => $new_config }});
}
if (not $mtu_seen)
{
$new_config .= "MTU=\"".$mtu."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_config => $new_config }});
}
if (not $defroute_seen)
{
$new_config .= "DEFROUTE=\"".$say_default."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_config => $new_config }});
}
# Write out the new file.
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0083,!!file!".$filename."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0083", variables => { file => $filename }});
$anvil->Storage->write_file({
debug => 2,
file => $filename,
body => $new_config,
user => "root",
group => "root",
mode => "0644",
overwrite => 1,
});
}
last;
}
}
# If there are any entries in '$restart_interfaces', restart
my $restart_interface_count = @{$restart_interfaces};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { restart_interface_count => $restart_interface_count }});
if ($restart_interface_count)
{
# Disconnect from the database, as we're about to tear down our connection.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, secure => 0, key => "job_0079"});
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0079");
$anvil->Database->disconnect();
# Tell nmcli to re-read the config files.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0463"});
my ($output, $return_code) = $anvil->System->call({debug => 3, shell_call => $anvil->data->{path}{exe}{nmcli}." connection reload"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => {
output => $output,
return_code => $return_code,
}});
foreach my $interface_name (sort {$a cmp $b} @{$restart_interfaces})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0462", variables => { interface => $interface_name }});
$anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{nmcli}." connection down ".$interface_name});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0464", variables => { interface => $interface_name }});
$anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{nmcli}." connection up ".$interface_name});
}
# Wait for a DB connection. We'll wait up to 130 seconds (updelay is 120 seconds, plus a small buffer).
my $wait_until = time + 130;
until ($anvil->data->{sys}{database}{connections})
{
$anvil->refresh();
$anvil->Database->connect();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print' => 1, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
if (time > $wait_until)
{
# Failed to reconnect, exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0107"});
$anvil->nice_exit({code => 4});
}
# No databases, sleep and then try again.
sleep 2;
}
}
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, secure => 0, key => "job_0084"});
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0084");
}
# Remove virbr0 if it exists.
if (exists $anvil->data->{network}{'local'}{interface}{virbr0})
{
# Remove the NAT'ed bridge
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, secure => 0, key => "job_0085"});
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0085");
$anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{virsh}." net-destroy default"});
$anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{virsh}." net-undefine default "});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, secure => 0, key => "job_0034"});
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0034");
}
# Update network view
$anvil->Network->read_nmcli({debug => 2});
$anvil->Network->get_ips({debug => 3});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, secure => 0, key => "job_0086"});
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0086");
# Update MTUs (running interface and config) if needed.
foreach my $in_iface (sort {$a cmp $b} keys %{$anvil->data->{network}{'local'}{interface}})
{
# Only one interface will start with the network name and have an IP address.
my $current_mtu = $anvil->data->{network}{'local'}{interface}{$in_iface}{mtu};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:in_iface' => $in_iface,
's2:current_mtu' => $current_mtu,
}});
if ($current_mtu eq $mtu)
{
# It's fine
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0087,!!interface!".$in_iface."!!,!!mtu!".$mtu."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0087", variables => {
interface => $in_iface,
mtu => $mtu,
}});
}
else
{
# Change the MTU both on the running interface and in the config file.
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0088,!!interface!".$in_iface."!!,!!old_mtu!".$current_mtu."!!,!!mtu!".$mtu."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0088", variables => {
interface => $in_iface,
old_mtu => $current_mtu,
mtu => $mtu,
}});
# Change the live MTU.
$anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{ip}." link set ".$in_iface." mtu ".$mtu});
# Now update the config file.
my $interface_uuid = $anvil->data->{nmcli}{'local'}{device_to_uuid}{$in_iface};
my $filename = $anvil->data->{nmcli}{'local'}{uuid}{$interface_uuid}{filename};
my $interface_name = $anvil->data->{nmcli}{'local'}{uuid}{$interface_uuid}{name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:interface_name' => $interface_name,
's2:filename' => $filename,
's3:interface_uuid' => $interface_uuid,
}});
my $mtu_seen = 0;
my $new_config = "";
my $old_config = $anvil->Storage->read_file({file => $filename});
foreach my $line (split/\n/, $old_config)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
if ($line =~ /^MTU=".*?"/)
{
$mtu_seen = 1;
$new_config .= "MTU=\"".$mtu."\"\n";
}
else
{
$new_config .= $line."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_config => $new_config }});
}
}
if (not $mtu_seen)
{
# Inject the MTU variable
$new_config .= "MTU=\"".$mtu."\"\n";
}
# Write out the new file.
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0083,!!file!".$filename."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0083", variables => { file => $filename }});
$anvil->Storage->write_file({
debug => 2,
file => $filename,
body => $new_config,
user => "root",
group => "root",
mode => "0644",
overwrite => 1,
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, secure => 0, key => "job_0034"});
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0034");
}
}
# Update NTP if set and needed.
if ($ntp)
{
# Break up the NTP servers into a list, we'll set to '1' the ones we find.
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0089");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0089"});
my $new_ntp = {};
foreach my $ntp_server (split/,/, $ntp)
{
$ntp_server = $anvil->Words->clean_spaces({ string => $ntp_server });
$new_ntp->{$ntp_server} = 0;
}
# Call chrony to see what servers are setup already.
my $change = 0;
my $new_config = "";
my $old_config = $anvil->Storage->read_file({file => $anvil->data->{path}{data}{'chrony.conf'}});
foreach my $line (split/\n/, $old_config)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { line => $line }});
$new_config .= $line."\n";
if ($line =~ /^Server (.*)$/)
{
# This is a source.
my $source = $1;
$new_ntp->{$source} = 1;
}
}
# Are any sources not enabled?
foreach my $source (sort {$a cmp $b} keys %{$new_ntp})
{
if (not $new_ntp->{$source})
{
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0090,!!server!".$source."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0090", variables => { server => $source }});
$change = 1;
$new_config .= "Server ".$source."\n";
}
}
if ($change)
{
# Write out the updated file.
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0055,!!file!".$anvil->data->{path}{data}{'chrony.conf'}."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0055", variables => { file => $anvil->data->{path}{data}{'chrony.conf'} }});
$anvil->Storage->write_file({
debug => 2,
file => $anvil->data->{path}{data}{'chrony.conf'},
body => $new_config,
user => "root",
group => "root",
mode => "0644",
overwrite => 1,
});
# Restart the daemon.
my $daemon = "chronyd";
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0091,!!daemon!".$daemon."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0091", variables => { daemon => $daemon }});
$anvil->System->restart_daemon({
debug => 2,
daemon => $daemon,
})
}
}
# Setup IPMI, if needed.
=cut
909; xxx::upses::el8-ups01::uuid: [7ebecdda-782d-4624-841d-98d912ed3d50]
909; xxx::upses::el8-ups02::uuid: [7ffb4dc2-8b96-4ca7-80bb-49e309fb2f5f]
918; xxx::fences::an-nas02::uuid: [4117a862-f58f-4676-991a-9ca257a3c612]
949; xxx::networks::name::bcn1::gateway: [], xxx::networks::name::bcn1::network: [10.201.0.0], xxx::networks::name::bcn1::subnet: [255.255.0.0]
949; xxx::networks::name::sn1::gateway: [], xxx::networks::name::sn1::network: [10.101.0.0], xxx::networks::name::sn1::subnet: [255.255.0.0]
949; xxx::networks::name::ifn1::gateway: [10.255.255.254], xxx::networks::name::ifn1::network: [10.255.0.0], xxx::networks::name::ifn1::subnet: [255.255.0.0]
961; xxx::networks::count::bcn: [1], xxx::networks::count::ifn: [1], xxx::networks::count::sn: [1]
971; xxx::machine::node1::ipmi_ip: [], xxx::machine::node1::type: [!!undef!!]
980; xxx::machine::node1::fence::an-nas02::port: [el8-a01n01]
980; xxx::machine::node1::fence::el8-pdu01::port: []
980; xxx::machine::node1::fence::el8-pdu02::port: []
980; xxx::machine::node1::fence::pulsar::port: []
989; xxx::machine::node1::ups::el8-ups01::used: [0]
989; xxx::machine::node1::ups::el8-ups02::used: [0]
998; xxx::machine::node1::network::bcn1::ip: [10.201.10.1]
998; xxx::machine::node1::network::ifn1::ip: [10.255.10.1]
998; xxx::machine::node1::network::sn1::ip: [10.101.10.1]
=cut
return(0);
}
# Load the job details.
sub load_job
{
my ($anvil) = @_;
# See if we can find the job details. This method checks for the 'job-uuid' switch if it was used.
$anvil->data->{switches}{'job-uuid'} = "" if not exists $anvil->data->{switches}{'job-uuid'};
$anvil->data->{jobs}{job_uuid} = "" if not exists $anvil->data->{jobs}{job_uuid};
$anvil->Job->get_job_details({debug => 2});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"jobs::job_uuid" => $anvil->data->{jobs}{job_uuid},
}});
$anvil->data->{job}{progress} = 0;
update_progress($anvil, $anvil->data->{job}{progress}, "clear");
update_progress($anvil, ($anvil->data->{job}{progress} += 1), "job_0074,!!job-uuid!".$anvil->data->{switches}{'job-uuid'}."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0074", variables => { 'job-uuid' => $anvil->data->{switches}{'job-uuid'} }});
my ($machine, $manifest_uuid) = ($anvil->data->{jobs}{job_data} =~ /as_machine=(.*?),manifest_uuid=(.*)$/);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
machine => $machine,
manifest_uuid => $manifest_uuid,
}});
$anvil->data->{sys}{machine} = $machine;
$anvil->data->{sys}{manifest_uuid} = $manifest_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"sys::machine" => $anvil->data->{sys}{machine},
"sys::manifest_uuid" => $anvil->data->{sys}{manifest_uuid},
}});
update_progress($anvil, ($anvil->data->{job}{progress} += 1), "job_0075,!!machine!".$anvil->data->{sys}{machine}."!!,!!manifest_uuid!".$anvil->data->{sys}{manifest_uuid}."!!");
return(0); return(0);
} }
@ -70,7 +837,49 @@ sub load_manifest
{ {
my ($anvil) = @_; my ($anvil) = @_;
$anvil->Database->get_hosts();
my $problem = $anvil->Striker->load_manifest({
debug => 2,
manifest_uuid => $anvil->data->{sys}{manifest_uuid},
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
manifest_uuid => $anvil->data->{sys}{manifest_uuid},
problem => $problem,
}});
if ($problem)
{
# Report a problem and send the user back to the manifests page.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "warning_0046"});
update_progress($anvil, 0, "job_0076");
sleep 10;
$anvil->nice_exit({exit_code => 2});
}
return(0);
}
# If this is being called as a job, this will allow the progress to be updated.
sub update_progress
{
my ($anvil, $progress, $message) = @_;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
's1:progress' => $progress,
's2:message' => $message,
}});
$progress = 95 if $progress > 100;
if (not $anvil->data->{switches}{'job-uuid'})
{
return(0);
}
$anvil->Job->update_progress({
debug => 3,
progress => $progress,
message => $message,
job_uuid => $anvil->data->{switches}{'job-uuid'},
});
return(0); return(0);
} }

@ -3,7 +3,6 @@
# This keeps an eye on the network configuration and ensures the firewall is configured appropriately. What # This keeps an eye on the network configuration and ensures the firewall is configured appropriately. What
# exactly that means depends on why kind of machine the local host is. # exactly that means depends on why kind of machine the local host is.
# #
#
# Exit codes; # Exit codes;
# 0 = Normal exit. # 0 = Normal exit.
# 1 = Failed to unlink an unneeded file. # 1 = Failed to unlink an unneeded file.
@ -12,6 +11,7 @@
# TODO: # TODO:
# - TEMP: During development, firewalling is disabled. # - TEMP: During development, firewalling is disabled.
# - Add support for enabling/disabling MASQ'ing the BCN # - Add support for enabling/disabling MASQ'ing the BCN
# - Add support for listening for NTP queries based on /etc/chrony.conf's Server entries (map them to networks / zones).
# #
# # Allow routing/masq'ing through the IFN1 (provide net access to the BCN) # # Allow routing/masq'ing through the IFN1 (provide net access to the BCN)
# firewall-cmd --zone=IFN1 --add-masquerade # firewall-cmd --zone=IFN1 --add-masquerade
@ -71,20 +71,6 @@ $anvil->nice_exit({exit_code => 0});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "message_0134"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "message_0134"});
check_initial_setup($anvil); check_initial_setup($anvil);
### TODO:
=cut
firewall-cmd --get-active-zones | grep -q virbr0
if [ $? -eq 0 ];
then
echo "Removing libvirt firewall zone..."
firewall-cmd --zone=libvirt --remove-interface=virbr0 --permanent
firewall-cmd --zone=libvirt --remove-interface=virbr0
echo "Done."
else
echo "There is no libvirt firewall zone to remove."
fi
=cut
# Restart, if needed. # Restart, if needed.
if ($anvil->data->{firewall}{reload}) if ($anvil->data->{firewall}{reload})
{ {

@ -531,7 +531,7 @@ sub update_network
if (($bridge_uuid) && ($ip_address)) if (($bridge_uuid) && ($ip_address))
{ {
my $ip_address_uuid = $anvil->Database->insert_or_update_ip_addresses({ my $ip_address_uuid = $anvil->Database->insert_or_update_ip_addresses({
debug => 2, debug => 3,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
ip_address_on_type => $type, ip_address_on_type => $type,
@ -562,7 +562,7 @@ sub update_network
if ($anvil->data->{sys}{database}{connections}) if ($anvil->data->{sys}{database}{connections})
{ {
my $bond_uuid = $anvil->Database->insert_or_update_bonds({ my $bond_uuid = $anvil->Database->insert_or_update_bonds({
debug => 2, debug => 3,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
bond_name => $interface, bond_name => $interface,
@ -587,7 +587,7 @@ sub update_network
if (($bond_uuid) && ($ip_address)) if (($bond_uuid) && ($ip_address))
{ {
my $ip_address_uuid = $anvil->Database->insert_or_update_ip_addresses({ my $ip_address_uuid = $anvil->Database->insert_or_update_ip_addresses({
debug => 2, debug => 3,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
ip_address_on_type => $type, ip_address_on_type => $type,
@ -649,7 +649,7 @@ sub update_network
if (($network_interface_uuid) && ($ip_address)) if (($network_interface_uuid) && ($ip_address))
{ {
my $ip_address_uuid = $anvil->Database->insert_or_update_ip_addresses({ my $ip_address_uuid = $anvil->Database->insert_or_update_ip_addresses({
debug => 2, debug => 3,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
ip_address_on_type => $type, ip_address_on_type => $type,

Loading…
Cancel
Save