cancel jobs when it is known fresh device is already discovered
This commit is contained in:
@@ -22,6 +22,7 @@ foreach my $slot (qw/
|
|||||||
log
|
log
|
||||||
device_key
|
device_key
|
||||||
job_priority
|
job_priority
|
||||||
|
is_cancelled
|
||||||
|
|
||||||
_current_phase
|
_current_phase
|
||||||
_last_namespace
|
_last_namespace
|
||||||
@@ -45,6 +46,10 @@ sub BUILD {
|
|||||||
$job->action($1);
|
$job->action($1);
|
||||||
$job->only_namespace($2);
|
$job->only_namespace($2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!defined $job->subaction) {
|
||||||
|
$job->subaction('');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
=head1 METHODS
|
=head1 METHODS
|
||||||
@@ -63,6 +68,19 @@ sub display_name {
|
|||||||
($job->port || '');
|
($job->port || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=head2 cancel
|
||||||
|
|
||||||
|
Log a status and prevent other stages from runnning.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub cancel {
|
||||||
|
my ($job, $msg) = @_;
|
||||||
|
$msg ||= 'unknown reason for cancelled job';
|
||||||
|
$job->is_cancelled(true);
|
||||||
|
return Status->info($msg);
|
||||||
|
}
|
||||||
|
|
||||||
=head2 finalise_status
|
=head2 finalise_status
|
||||||
|
|
||||||
Find the best status and log it into the job's C<status> and C<log> slots.
|
Find the best status and log it into the job's C<status> and C<log> slots.
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ register 'register_worker' => sub {
|
|||||||
debug sprintf '-> run worker %s/%s/%s',
|
debug sprintf '-> run worker %s/%s/%s',
|
||||||
@$workerconf{qw/phase namespace priority/};
|
@$workerconf{qw/phase namespace priority/};
|
||||||
|
|
||||||
|
return if $job->is_cancelled;
|
||||||
|
|
||||||
# check to see if this namespace has already passed at higher priority
|
# check to see if this namespace has already passed at higher priority
|
||||||
# and also update job's record of namespace and priority
|
# and also update job's record of namespace and priority
|
||||||
return $job->add_status( Status->info('skip: namespace passed at higher priority') )
|
return $job->add_status( Status->info('skip: namespace passed at higher priority') )
|
||||||
|
|||||||
@@ -69,17 +69,25 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
|||||||
|
|
||||||
return if $new_ip eq $old_ip;
|
return if $new_ip eq $old_ip;
|
||||||
|
|
||||||
schema('netdisco')->txn_do(sub {
|
return schema('netdisco')->txn_do(sub {
|
||||||
# delete target device with the same vendor and serial number
|
my $existing = schema('netdisco')->resultset('Device')->search({
|
||||||
schema('netdisco')->resultset('Device')->search({
|
|
||||||
ip => $new_ip, vendor => $device->vendor, serial => $device->serial,
|
ip => $new_ip, vendor => $device->vendor, serial => $device->serial,
|
||||||
})->delete;
|
});
|
||||||
|
|
||||||
|
if (($job->subaction eq 'with-nodes') and $existing->count) {
|
||||||
|
$device->delete;
|
||||||
|
return $job->cancel(
|
||||||
|
" [$old_ip] device - cancelling fresh discover: already known as $new_ip");
|
||||||
|
}
|
||||||
|
|
||||||
|
# discover existing device but change IP, need to remove existing device
|
||||||
|
$existing->delete;
|
||||||
|
|
||||||
# if target device exists then this will die
|
# if target device exists then this will die
|
||||||
$device->renumber($new_ip)
|
$device->renumber($new_ip)
|
||||||
or die "cannot renumber to: $new_ip"; # rollback
|
or die "cannot renumber to: $new_ip"; # rollback
|
||||||
|
|
||||||
# is not done in renumber but required otherwise confusing at job end!
|
# is not done in renumber, but required, otherwise confusing at job end!
|
||||||
schema('netdisco')->resultset('Admin')
|
schema('netdisco')->resultset('Admin')
|
||||||
->find({job => $job->id})->update({device => $new_ip}) if $job->id;
|
->find({job => $job->id})->update({device => $new_ip}) if $job->id;
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
|
|
||||||
# if requested, and the device has not yet been
|
# if requested, and the device has not yet been
|
||||||
# arpniped/macsucked, queue those jobs now
|
# arpniped/macsucked, queue those jobs now
|
||||||
return unless $device->in_storage
|
return unless $device->in_storage and $job->subaction eq 'with-nodes';
|
||||||
and $job->subaction and $job->subaction eq 'with-nodes';
|
|
||||||
|
|
||||||
if (!defined $device->last_macsuck and $device->has_layer(2)) {
|
if (!defined $device->last_macsuck and $device->has_layer(2)) {
|
||||||
jq_insert({
|
jq_insert({
|
||||||
|
|||||||
Reference in New Issue
Block a user