@ -149,11 +149,13 @@ sub update_passwords
my ($anvil) = @_;
# Have we been asked to set a password?
$anvil->data->{variables}{form}{config_step2}{striker_password}{value} = "" if not defined $anvil->data->{variables}{form}{config_step2}{striker_password}{value};
if ($anvil->data->{variables}{form}{config_step2}{striker_password}{value})
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => {
"config::striker_password" => $anvil->data->{config}{striker_password},
}});
if ($anvil->data->{config}{striker_password})
{
# Set the passwords
my $password = $anvil->data->{variables}{form}{ config_step2 }{striker_password}{value };
my $password = $anvil->data->{config}{striker_password};
my $temp_file = "/tmp/anvil-".$anvil->Get->uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { password => $password }});
@ -235,17 +237,17 @@ sub reconfigure_network
{
my ($anvil) = @_;
my $local_host = $anvil->Get->short_host_name();
my $reboot_needed = 0;
my $prefix = exists $anvil->data->{variables}{form}{config_step1}{prefix}{value} ? $anvil->data->{variables}{form}{config_step1}{prefix}{value} : "";
my $sequence = exists $anvil->data->{variables}{form}{config_step1}{sequence}{value} ? $anvil->data->{variables}{form}{config_step1}{sequence}{value} : "";
my $domain = exists $anvil->data->{variables}{form}{config_step1}{domain}{value} ? $anvil->data->{variables}{form}{config_step1}{domain}{value} : "";
my $organization = exists $anvil->data->{variables}{form}{config_step1}{organization}{value} ? $anvil->data->{variables}{form}{config_step1}{organization}{value} : "";
my $bcn_count = exists $anvil->data->{variables}{form}{config_step1}{bcn_count}{value} ? $anvil->data->{variables}{form}{config_step1}{bcn_count}{value} : 1;
my $sn_count = exists $anvil->data->{variables}{form}{config_step1}{sn_count}{value} ? $anvil->data->{variables}{form}{config_step1}{sn_count}{value} : 0;
my $mn_count = exists $anvil->data->{variables}{form}{config_step1}{mn_count}{value} ? $anvil->data->{variables}{form}{config_step1}{mn_count}{value} : 0;
my $ifn_count = exists $anvil->data->{variables}{form}{config_step1}{ifn_count}{value} ? $anvil->data->{variables}{form}{config_step1}{ifn_count}{value} : 1;
my $new_host_name = exists $anvil->data->{variables}{form}{config_step2}{host_name}{value} ? $anvil->data->{variables}{form}{config_step2}{host_name}{value} : "";
my $local_host = $anvil->Get->short_host_name();
my $prefix = $anvil->data->{config}{prefix};
my $sequence = $anvil->data->{config}{sequence};
my $domain = $anvil->data->{config}{domain};
my $new_host_name = $anvil->data->{config}{host_name};
my $organization = $anvil->data->{config}{organization};
my $bcn_count = $anvil->data->{config}{bcn_count};
my $ifn_count = $anvil->data->{config}{ifn_count};
my $sn_count = $anvil->data->{config}{sn_count};
my $mn_count = $anvil->data->{config}{mn_count};
my $type = $anvil->Get->host_type();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
prefix => $prefix,
@ -260,18 +262,6 @@ sub reconfigure_network
type => $type,
}});
# Clear the network mapping flag.
$anvil->Database->insert_or_update_variables({
debug => 2,
variable_name => "config::map_network",
variable_value => 0,
variable_default => "",
variable_description => "striker_0202",
variable_section => "config",
variable_source_uuid => $anvil->Get->host_uuid,
variable_source_table => "hosts",
});
# If we're configuring a dashboard and no host name was given, generate it.
if (($type eq "striker") && (not $new_host_name))
{
@ -349,7 +339,7 @@ sub reconfigure_network
}
# Now configure the network.
my $dns = defined $anvil->data->{variables}{form}{ config_step2 }{dns}{value} ? [split/,/, $anvil->data->{variables}{form}{ config_step2 }{dns}{value }] : [];
my $dns = $anvil->data->{config}{dns} ? [split/,/, $anvil->data->{config}{dns}] : [];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { dns => $dns }});
for (my $i = 0; $i < @{$dns}; $i++)
{
@ -357,8 +347,8 @@ sub reconfigure_network
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "dns->[$i]" => $dns->[$i] }});
}
my $gateway = defined $anvil->data->{variables}{form}{ config_step2 }{gateway}{value} ? $anvil->data->{variables}{form}{config_step2}{gateway}{value} : "" ;
my $gateway_interface = defined $anvil->data->{variables}{form}{ config_step2 }{gateway_interface}{value} ? $anvil->data->{variables}{form}{config_step2}{gateway_interface}{value} : "" ;
my $gateway = $anvil->data->{config}{gateway};
my $gateway_interface = $anvil->data->{config}{gateway_interface};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
gateway => $gateway,
gateway_interface => $gateway_interface,
@ -384,7 +374,8 @@ sub reconfigure_network
{
my $ip_key = $network_type.$network_count."_ip";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ip_key => $ip_key }});
if ((exists $anvil->data->{variables}{form}{config_step2}{$ip_key}{value}) && ($anvil->data->{variables}{form}{config_step2}{$ip_key}{value} eq "dhcp"))
if ((exists $anvil->data->{config}{$ip_key}) && ($anvil->data->{config}{$ip_key} eq "dhcp"))
{
$gateway_interface = $network_type.$network_count;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { gateway_interface => $gateway_interface }});
@ -490,11 +481,390 @@ ORDER BY
# This will be set to '1' if we make a change.
my $changes = 0;
my $new_interfaces = [];
my $network_type = $anvil->System->check_network_type();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_type => $network_type }});
if ($network_type eq "ifcfg")
{
foreach my $network_type ("bcn", "sn", "mn", "ifn")
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_type => $network_type }});
=cut
# This is the old type of network config
configure_ifcfg_network($anvil, $network_type);
}
}
else
{
# Configure the network using Network Manager
reconfigure_bridges($anvil);
reconfigure_bonds($anvil);
reconfigure_interfaces($anvil);
reconfigure_ip_addresses($anvil);
}
# If we should reset, do so now.
if ($anvil->data->{sys}{reboot})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0687", variables => { reason => "#!string!log_0631!#" }});
do_reboot($anvil);
}
if ($changes)
{
# In an attempt to make network changes more reliable, we'll just reboot. This shouldn't
# actually be hit anymore as any change should have triggered the reboot above.
$anvil->data->{sys}{reboot} = 1;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0687", variables => { reason => "#!string!log_0631!#" }});
do_reboot($anvil);
# Re-read the config
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0463"});
my $shell_call = $anvil->data->{path}{exe}{nmcli}." connection reload";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({debug => 3, shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
# Give a couple seconds for the reload
sleep 2;
# Now check the bonds
my $repaired = $anvil->Network->check_network({heal => "all"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { repaired => $repaired }});
if ($repaired)
{
# It can take a bit for the bonds to allow traffic, so sleep for a bit.
sleep 30;
}
}
# Wait for a DB connection. We'll wait up to 130 seconds, as sometimes it takes a while for the network
# to start routing traffic.
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, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
if (time > $wait_until)
{
# Failed to reconnect, reboot. Hopefully the network comes up cleanly
# next time..
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0107"});
do_reboot($anvil);
}
# No databases, sleep and then try again.
sleep 10;
}
}
# We're half-way there.
$anvil->Job->update_progress({
progress => 50,
job_uuid => $anvil->data->{job}{uuid},
});
# If any virtio bridges exist, remove it/them.
my $start = 0;
my ($bridges, $return_code) = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." net-list"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bridges => $bridges, return_code => $return_code }});
if ($return_code)
{
### NOTE: We're doing a bunch of deletes, so to be safe we statically define the directory
### here.
# Libvirtd isn't running, check the directory directly.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0478"});
my $directory = "/etc/libvirt/qemu/networks/autostart";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { directory => $directory }});
if (-d $directory)
{
# Delete all files.
local(*DIRECTORY);
opendir(DIRECTORY, $directory);
while(my $file = readdir(DIRECTORY))
{
next if $file eq ".";
next if $file eq "..";
my $full_path = $directory."/".$file;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
file => $file,
full_path => $full_path,
}});
if (-l $full_path)
{
# It's a symlink, remove it.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0479", variables => { 'symlink' => $full_path }});
unlink $full_path;
if (-l $full_path)
{
# It didn't work...
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 0, priority => "err", key => "error_0132", variables => { 'symlink' => $full_path }});;
}
}
}
closedir(DIRECTORY);
}
}
else
{
foreach my $line (split/\n/, $bridges)
{
$line = $anvil->Words->clean_spaces({string => $line});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
if ($line =~ /^----------/)
{
$start = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { start => $start }});
next;
}
next if not $start;
my $bridge = ($line =~ /(.*?)\s/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bridge => $bridge }});
$anvil->data->{virsh}{bridge}{$bridge} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "virsh::bridge::$bridge" => $anvil->data->{virsh}{bridge}{$bridge} }});
}
foreach my $bridge (sort {$a cmp $b} keys %{$anvil->data->{virsh}{bridge}})
{
# Destroy (stop) it.
my ($destroy, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." net-destroy ".$bridge});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { destroy => $destroy, return_code => $return_code }});
# Disable it from auto-start.
(my $disable, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." net-autostart ".$bridge." --disable"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { disable => $disable, return_code => $return_code }});
# Undefine (delete)
(my $undefine, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." net-undefine ".$bridge});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { undefine => $undefine, return_code => $return_code }});
}
}
$anvil->Job->update_progress({
progress => 75,
job_uuid => $anvil->data->{job}{uuid},
});
return(0);
}
sub reconfigure_interfaces
{
my ($anvil) = @_;
foreach my $network_type ("bcn", "sn", "mn", "ifn")
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_type => $network_type }});
# This is the old type of network config
configure_ifcfg_network($anvil, $network_type);
}
foreach my $wanted_interface (sort {$a cmp $b} keys %{$anvil->data->{network_manager}{reconfigure}})
{
my $uuid = $anvil->data->{network_manager}{reconfigure}{$wanted_interface}{from_uuid};
my $old_device = $anvil->data->{interface}{uuid}{$uuid}{device};
my $name = $anvil->data->{interface}{uuid}{$uuid}{'connection.id'};
my $mac_address = $anvil->data->{interface}{uuid}{$uuid}{mac_address};
my $type = $anvil->data->{interface}{uuid}{$uuid}{type};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:wanted_interface' => $wanted_interface,
's2:uuid' => $uuid,
's3:old_device' => $old_device,
's4:name' => $name,
's5:mac_address' => $mac_address,
's6:type' => $type,
}});
print "Renaming old device/name: [".$old_device."/".$name."] with MAC: [".$mac_address."] to: [".$wanted_interface."] using UUID: [".$uuid."]\n";
# Read persistent-net and see if it needs to be updated.
my $new_persistent_net = "";
my $old_persistent_net = "";
if (-e $anvil->data->{path}{configs}{'persistent-net'})
{
$old_persistent_net = $anvil->Storage->read_file({debug => 2, file => $anvil->data->{path}{configs}{'persistent-net'}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { old_persistent_net => $old_persistent_net }});
}
foreach my $line (split/\n/, $old_persistent_net)
{
# If this MAC or device name exists already, delete the line.
if (($line =~ /"$mac_address"/) or ($line =~ /"$wanted_interface"/))
{
next;
}
$new_persistent_net .= $line."\n";
}
$new_persistent_net .= "SUBSYSTEM==\"net\",ACTION==\"add\",ATTR{address}==\"".$mac_address."\",ATTR{type}==\"".$type."\",NAME=\"".$wanted_interface."\"\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_persistent_net => $new_persistent_net }});
my $difference = diff \$old_persistent_net, \$new_persistent_net, { STYLE => 'Unified' };
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { difference => $difference }});
# Write the new file.
if ($difference)
{
print "- Updating the udev file: [".$anvil->data->{path}{configs}{'persistent-net'}."]\n";
my $problem = $anvil->Storage->write_file({
file => $anvil->data->{path}{configs}{'persistent-net'},
body => $new_persistent_net,
overwrite => 1,
user => "admin",
group => "admin",
mode => "0644",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
if ($problem)
{
print "[ Error ] - Failed to write the new: [".$anvil->data->{path}{configs}{'persistent-net'}."] file, aborting!\n";
$anvil->nice_exit({exit_code => 1});
}
}
# Update the connection.interface-name
my $connection_interface_name = $anvil->data->{interface}{uuid}{$uuid}{'connection.interface-name'} ? $anvil->data->{interface}{uuid}{$uuid}{'connection.interface-name'} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { connection_interface_name => $connection_interface_name }});
if ($connection_interface_name)
{
print "- Removing the old 'connection.interface-name': [".$connection_interface_name."]\n";
my $shell_call = $anvil->data->{path}{exe}{nmcli}." connection modify ".$uuid." connection.interface-name \"\"";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
$shell_call = $anvil->data->{path}{exe}{nmcli}." --get-values connection.interface-name connection show ".$uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
if ($output)
{
# This should have been blank
print "[ Error ] - Failed to delete the 'connection.interface-name', got: [".$output."] and it should bhave been blank, aborting!\n";
$anvil->nice_exit({exit_code => 1});
}
}
# We'll log what it was, and change it anyway
my $match_interface_name = $anvil->data->{interface}{uuid}{$uuid}{'match.interface-name'} ? $anvil->data->{interface}{uuid}{$uuid}{'match.interface-name'} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { match_interface_name => $match_interface_name }});
if (1)
{
print "- Matching the new interface name: [".$wanted_interface."] to the bios device name: [".$old_device."]\n";
my $shell_call = $anvil->data->{path}{exe}{nmcli}." connection modify ".$uuid." match.interface-name \"".$wanted_interface." ".$old_device."\"";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
# Read it back
$shell_call = $anvil->data->{path}{exe}{nmcli}." --get-values match.interface-name connection show ".$uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
if (($output ne $wanted_interface.",".$old_device) && ($output ne $old_device.",".$wanted_interface))
{
# This should have been blank
print "[ Error ] - Failed to create the 'match.interface-name' value. Expected: [".$wanted_interface.",".$old_device."], got: [".$output."], aborting!\n";
$anvil->nice_exit({exit_code => 1});
}
# Set the connection.id to the old name.
print "- Setting the connection.id to the bios device name: [".$old_device."]\n";
$shell_call = $anvil->data->{path}{exe}{nmcli}." connection modify ".$uuid." connection.id \"".$old_device."\"";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
# Read it back
$shell_call = $anvil->data->{path}{exe}{nmcli}." --get-values connection.id connection show ".$uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
}
# Set the reboot flag.
$anvil->data->{sys}{reboot_needed} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sys::reboot_needed" => $anvil->data->{sys}{reboot_needed} }});
}
if ($anvil->data->{sys}{reboot_needed})
{
print "Reboot needed.\n";
print "- Regenerating dracute initrd image, this can take a moment...\n";
my $shell_call = $anvil->data->{path}{exe}{dracut}." --force";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
print "- New initrd image created.\n";
print "[ Note ] - Reboot needed. Re-run this after the reboot to complete setup.\n";
print "- Rebooting in 60 seconds (press 'ctrl + c' to abort).\n";
my $timeout = 60;
while($timeout)
{
if ($timeout % 10)
{
print "."
}
else
{
print $timeout;
}
sleep 1;
$timeout--;
}
print "0\n";
print "Rebooting NOW!\n";
$shell_call = $anvil->data->{path}{exe}{systemctl}." reboot";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
($output, $return_code) = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, return_code => $return_code }});
}
return(0);
}
sub configure_ifcfg_network
{
my ($anvil, $network_type) = @_;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_type => $network_type }});
my $count = 0;
if ($network_type eq "bcn") { $count = $bcn_count; }
elsif ($network_type eq "sn") { $count = $sn_count; }
@ -514,18 +884,19 @@ ORDER BY
link1_key => $link1_key,
}});
next if not exists $anvil->data->{variables}{form}{config_step2}{$link1_key};
next if not $anvil->data->{variables}{form}{config_step2}{$link1_key}{value};
next if not exists $anvil->data->{config}{$link1_key};
next if not $anvil->data->{config}{$link1_key};
my $link2_key = $this_network."_link2_mac_to_set";
my $subnet_mask_key = $this_network."_subnet_mask";
my $ip_key = $this_network."_ip";
my $bridge_key = $this_network."_create_bridge";
my $link1_mac = $anvil->data->{variables}{form}{ config_step2 }{$link1_key}{value };
my $link1_mac = $anvil->data->{config}{$link1_key};
my $is_gateway = $this_network eq $gateway_interface ? 1 : 0;
my $link2_mac = defined $anvil->data->{variables}{form}{config_step2}{$link2_key}{value} ? $anvil->data->{variables}{form}{config_step2}{$link2_key}{value} : "";
my $link2_mac = defined $anvil->data->{config}{$link2_key} ? $anvil->data->{config}{$link2_key} : "";
my $old_link1_iface = $anvil->data->{network}{$local_host}{mac_address}{$link1_mac}{interface} ? $anvil->data->{network}{$local_host}{mac_address}{$link1_mac}{interface} : "";
my $old_link2_iface = defined $anvil->data->{network}{$local_host}{mac_address}{$link2_mac}{interface} ? $anvil->data->{network}{$local_host}{mac_address}{$link2_mac}{interface} : "";
my $bridge = defined $anvil->data->{variables}{form}{config_step2}{$bridge_key}{value} ? $anvil->data->{variables}{form}{config_step2}{$bridge_key}{value} : 0;
my $bridge = defined $anvil->data->{config}{$bridge_key} ? $anvil->data->{config}{$bridge_key} : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
ip_key => $ip_key,
is_gateway => $is_gateway,
@ -572,30 +943,30 @@ ORDER BY
}
# Skip if this doesn't exist or isn't a valid IPv4 address.
if (not exists $anvil->data->{variables}{form}{ config_step2 }{$ip_key}{value })
if (not exists $anvil->data->{config}{$ip_key})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0176", variables => { ip_key => $ip_key }});
next;
}
else
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "variables::form:: config_step2 ::${ip_key}::value " => $anvil->data->{variables}{form}{ config_step2 }{$ip_key}{value } }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "config::${ip_key}" => $anvil->data->{config}{$ip_key} }});
}
if (($anvil->data->{variables}{form}{ config_step2 }{$ip_key}{value }) &&
($anvil->data->{variables}{form}{ config_step2 }{$ip_key}{value } ne "dhcp") &&
(not $anvil->Validate->ipv4({ip => $anvil->data->{variables}{form}{ config_step2 }{$ip_key}{value }})))
if (($anvil->data->{config}{$ip_key}) &&
($anvil->data->{config}{$ip_key} ne "dhcp") &&
(not $anvil->Validate->ipv4({ip => $anvil->data->{config}{$ip_key}})))
{
# Something was set, but it isn't valid.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "log_0148", variables => {
network => $this_network,
ip => $anvil->data->{variables}{form}{ config_step2 }{$ip_key}{value },
ip => $anvil->data->{config}{$ip_key},
}});
next;
}
# The IP could be 'dhcp', we'll handle that in a bit.
my $ip_address = $anvil->data->{variables}{form}{ config_step2 }{$ip_key}{value };
my $subnet_mask = defined $anvil->data->{variables}{form}{ config_step2 }{$subnet_mask_key}{value } ? $anvil->data->{variables}{form}{ config_step2 }{$subnet_mask_key}{value } : "";
my $ip_address = $anvil->data->{config}{$ip_key};
my $subnet_mask = defined $anvil->data->{config}{$subnet_mask_key} ? $anvil->data->{config}{$subnet_mask_key} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
ip_address => $ip_address,
subnet_mask => $subnet_mask,
@ -1166,13 +1537,13 @@ ORDER BY
}});
}
}
elsif ((exists $anvil->data->{variables}{form}{ config_step2 }{$link1_key}{value }) && ($anvil->Validate->mac({mac => $anvil->data->{variables}{form}{ config_step2 }{$link1_key}{value }})))
elsif ((exists $anvil->data->{config}{$link1_key}) && ($anvil->Validate->mac({mac => $anvil->data->{config}{$link1_key}})))
{
### NOTE: This only applies when configuring Striker dashboards. They can't
### be 'dhcp', either, so no checks are made for those cases. Likewise,
### bridges are not used.
# Single interface, set it up
my $link1_mac = $anvil->data->{variables}{form}{ config_step2 }{$link1_key}{value };
my $link1_mac = $anvil->data->{config}{$link1_key};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { link1_mac => $link1_mac }});
my $say_network = "";
@ -1356,160 +1727,6 @@ ORDER BY
next;
}
}
=cut
}
die;
# If we should reset, do so now.
if ($anvil->data->{sys}{reboot})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0687", variables => { reason => "#!string!log_0631!#" }});
do_reboot($anvil);
}
if ($changes)
{
# In an attempt to make network changes more reliable, we'll just reboot. This shouldn't
# actually be hit anymore as any change should have triggered the reboot above.
$anvil->data->{sys}{reboot} = 1;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0687", variables => { reason => "#!string!log_0631!#" }});
do_reboot($anvil);
# # Re-read the config
# $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0463"});
#
# my $shell_call = $anvil->data->{path}{exe}{nmcli}." connection reload";
# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
# my ($output, $return_code) = $anvil->System->call({debug => 3, shell_call => $shell_call});
# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
# output => $output,
# return_code => $return_code,
# }});
#
# # Give a couple seconds for the reload
# sleep 2;
#
# # Now check the bonds
# my $repaired = $anvil->Network->check_network({heal => "all"});
# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { repaired => $repaired }});
# if ($repaired)
# {
# # It can take a bit for the bonds to allow traffic, so sleep for a bit.
# sleep 30;
# }
}
# Wait for a DB connection. We'll wait up to 130 seconds, as sometimes it takes a while for the network
# to start routing traffic.
# 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, key => "log_0132"});
# if (not $anvil->data->{sys}{database}{connections})
# {
# if (time > $wait_until)
# {
# # Failed to reconnect, reboot. Hopefully the network comes up cleanly
# # next time..
# $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0107"});
# do_reboot($anvil);
# }
#
# # No databases, sleep and then try again.
# sleep 10;
# }
# }
# We're half-way there.
$anvil->Job->update_progress({
progress => 50,
job_uuid => $anvil->data->{job}{uuid},
});
# If any virtio bridges exist, remove it/them.
my $start = 0;
my ($bridges, $return_code) = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." net-list"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bridges => $bridges, return_code => $return_code }});
if ($return_code)
{
### NOTE: We're doing a bunch of deletes, so to be safe we statically define the directory
### here.
# Libvirtd isn't running, check the directory directly.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0478"});
my $directory = "/etc/libvirt/qemu/networks/autostart";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { directory => $directory }});
if (-d $directory)
{
# Delete all files.
local(*DIRECTORY);
opendir(DIRECTORY, $directory);
while(my $file = readdir(DIRECTORY))
{
next if $file eq ".";
next if $file eq "..";
my $full_path = $directory."/".$file;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
file => $file,
full_path => $full_path,
}});
if (-l $full_path)
{
# It's a symlink, remove it.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0479", variables => { 'symlink' => $full_path }});
unlink $full_path;
if (-l $full_path)
{
# It didn't work...
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 0, priority => "err", key => "error_0132", variables => { 'symlink' => $full_path }});;
}
}
}
closedir(DIRECTORY);
}
}
else
{
foreach my $line (split/\n/, $bridges)
{
$line = $anvil->Words->clean_spaces({string => $line});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
if ($line =~ /^----------/)
{
$start = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { start => $start }});
next;
}
next if not $start;
my $bridge = ($line =~ /(.*?)\s/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bridge => $bridge }});
$anvil->data->{virsh}{bridge}{$bridge} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "virsh::bridge::$bridge" => $anvil->data->{virsh}{bridge}{$bridge} }});
}
foreach my $bridge (sort {$a cmp $b} keys %{$anvil->data->{virsh}{bridge}})
{
# Destroy (stop) it.
my ($destroy, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." net-destroy ".$bridge});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { destroy => $destroy, return_code => $return_code }});
# Disable it from auto-start.
(my $disable, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." net-autostart ".$bridge." --disable"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { disable => $disable, return_code => $return_code }});
# Undefine (delete)
(my $undefine, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." net-undefine ".$bridge});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { undefine => $undefine, return_code => $return_code }});
}
}
$anvil->Job->update_progress({
progress => 75,
job_uuid => $anvil->data->{job}{uuid},
});
return(0);
}
@ -1633,9 +1850,26 @@ sub pickup_job_details
}});
}
### These are the new variables
$anvil->data->{config}{striker_password} = "";
$anvil->data->{config}{prefix} = "";
$anvil->data->{config}{sequence} = "";
$anvil->data->{config}{domain} = "";
$anvil->data->{config}{host_name} = "";
$anvil->data->{config}{organization} = "";
$anvil->data->{config}{bcn_count} = 1;
$anvil->data->{config}{ifn_count} = 1;
$anvil->data->{config}{sn_count} = 0;
$anvil->data->{config}{mn_count} = 0;
$anvil->data->{config}{dns} = "";
$anvil->data->{config}{gateway} = "";
$anvil->data->{config}{gateway_interface} = "";
### TODO: Remove this later
# This will store the variables from the database
$anvil->data->{variables} = {};
### TODO: Remove this, it shouldn't be needed once we confirm everything is in the job_data.
# If we're still alive, pick up the details.
my $query = "
SELECT
@ -1673,6 +1907,7 @@ AND
$anvil->_make_hash_reference($anvil->data->{variables}, $this_variable, $this_value);
}
### TODO: This is the only way we should do it, but the variable names need to change to be more sensible.
# Overwrite variables with job data.
foreach my $line (split/\n/, $anvil->data->{jobs}{job_data})
{
@ -1684,6 +1919,37 @@ AND
}});
$anvil->_make_hash_reference($anvil->data->{variables}, $1, $2);
}
elsif ($line =~ /^(.*?)=(.*)$/)
{
my $variable = $1;
my $value = $2;
my $secure = $variable =~ /passw/ ? 1 : 0;
$anvil->data->{config}{$variable} = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:variable' => $variable,
's2:value' => $anvil->Log->is_secure($value),
"s3:config::${variable}" => $anvil->Log->is_secure($anvil->data->{config}{$variable}),
}});
}
}
### TODO: Remove this when no longer needed.
# Convert old variables to new ones.
foreach my $config_step (sort {$a cmp $b} keys %{$anvil->data->{variables}{form}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { config_step => $config_step }});
foreach my $variable (sort {$a cmp $b} keys %{$anvil->data->{variables}{form}{$config_step}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { variable => $variable }});
if (exists $anvil->data->{variables}{form}{$config_step}{$variable}{value})
{
$anvil->data->{config}{$variable} = $anvil->data->{variables}{form}{$config_step}{$variable}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"config::${variable}" => $anvil->data->{config}{$variable},
}});
}
}
}
# Clear previous data