@ -48,7 +48,7 @@ if (not $connections)
pickup_job_details($anvil);
pickup_job_details($anvil);
reconfigure_network($anvil);
$anvil->nice_exit({code => 0});
$anvil->nice_exit({code => 0});
@ -56,6 +56,102 @@ $anvil->nice_exit({code => 0});
# Functions #
# Functions #
#############################################################################################################
#############################################################################################################
# This does the work of reconfiguring the network
sub reconfigure_network
{
my ($anvil) = @_;
my $prefix = $anvil->data->{variables}{form}{config_step1}{prefix}{value};
my $sequence = $anvil->data->{variables}{form}{config_step1}{sequence}{value};
my $domain = $anvil->data->{variables}{form}{config_step1}{domain}{value};
my $organization = $anvil->data->{variables}{form}{config_step1}{organization}{value};
my $bcn_count = 1; # TODO: This should be coming from the form, even though it's only '1' for now.
my $ifn_count = $anvil->data->{variables}{form}{config_step1}{ifn_count}{value};
my $new_hostname = $prefix."-striker".sprintf("%02d", $sequence).".".$domain;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
prefix => $prefix,
sequence => $sequence,
domain => $domain,
organization => $organization,
bcn_count => $bcn_count,
ifn_count => $ifn_count,
new_hostname => $new_hostname,
}});
=cut
print Dumper $anvil->data->{variables};
$VAR1 = {
'form' => {
'config_step2' => {
'bcn1_subnet' => {
'value' => '255.255.0.0'
},
'ifn1_iface1_mac' => {
'value' => '52:54:00:dd:ad:8a'
},
'dns' => {
'value' => '8.8.8.8, 8.8.4.4'
},
'gateway' => {
'value' => '192.168.122.1'
},
'bcn1_iface1_mac' => {
'value' => '52:54:00:6b:35:bc'
},
'striker_password' => {
'value' => 'super secret password'
},
'hostname' => {
'value' => 'an-striker01.alteeve.com'
},
'gateway_interface' => {
'value' => 'ifn1'
},
'ifn1_subnet' => {
'value' => '255.255.0.0'
},
'ifn1_ip' => {
'value' => '192.168.122.201'
},
'bcn1_ip' => {
'value' => '10.1.4.1'
},
'bcn1_iface2_mac' => {
'value' => '52:54:00:5d:5d:3d'
},
'ifn1_iface2_mac' => {
'value' => '52:54:00:1e:36:03'
},
'striker_user' => {
'value' => 'striker'
}
},
'config_step1' => {
'domain' => {
'value' => 'alteeve.com'
},
'sequence' => {
'value' => '1'
},
'ifn_count' => {
'value' => '1'
},
'prefix' => {
'value' => 'an'
},
'organization' => {
'value' => 'Alteeve'
}
}
}
};
=cut
return(0);
}
# This will pick up the job, or exit.
# This will pick up the job, or exit.
sub pickup_job_details
sub pickup_job_details
{
{
@ -110,11 +206,18 @@ LIMIT 1;";
# See if the job was picked up by another running instance.
# See if the job was picked up by another running instance.
if ($job_picked_up_by)
if ($job_picked_up_by)
{
{
### TODO: Check if the PID is still active.
# Check if the PID is still active.
# Yup.
my ($pids) = $anvil->System->pids({program_name => $THIS_FILE, ignore_me => 1});
my $count = @{$pids};
print "count: [".$count."], my pid: [".$$."]\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0132", variables => { pid => $job_picked_up_by }});
# Any other instance running?.
$anvil->nice_exit({code => 1});
if ($count)
{
# Yup, exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0146", variables => { pid => $job_picked_up_by }});
$anvil->nice_exit({code => 1});
}
}
}
# This will store the variables from the database
# This will store the variables from the database
@ -138,9 +241,11 @@ AND
AND
AND
variable_source_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid)."
variable_source_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid)."
;";
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results};
$count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2 , list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3 , list => {
results => $results,
results => $results,
count => $count,
count => $count,
}});
}});
@ -148,7 +253,7 @@ AND
{
{
my $this_variable = $row->[0];
my $this_variable = $row->[0];
my $this_value = defined $row->[1] ? $row->[1] : "";
my $this_value = defined $row->[1] ? $row->[1] : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2 , list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3 , list => {
this_variable => $this_variable,
this_variable => $this_variable,
this_value => $this_value,
this_value => $this_value,
}});
}});
@ -156,7 +261,11 @@ AND
$anvil->_make_hash_reference($anvil->data->{variables}, $this_variable, $this_value);
$anvil->_make_hash_reference($anvil->data->{variables}, $this_variable, $this_value);
}
}
print Dumper $anvil->data->{variables};
# Record that we've picked up this job.
$query = "UPDATE jobs SET job_picked_up_by = ".$$.", job_progress = 1, job_picked_up_at = ".time." WHERE job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid).";";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
return(0);
return(0);
}
}