Merge branch 'master' into og-api-tokens-simple
This commit is contained in:
@@ -4,7 +4,7 @@ use strict;
|
||||
use warnings;
|
||||
use 5.010_000;
|
||||
|
||||
our $VERSION = '2.042000';
|
||||
our $VERSION = '2.042002';
|
||||
use App::Netdisco::Configuration;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
@@ -81,14 +81,35 @@ sub cancel {
|
||||
return Status->error($msg);
|
||||
}
|
||||
|
||||
=head2 best_status
|
||||
|
||||
Find the best status so far. The process is to track back from the last worker
|
||||
and find the highest scoring status, skipping the check phase.
|
||||
|
||||
=cut
|
||||
|
||||
sub best_status {
|
||||
my $job = shift;
|
||||
my $cur_level = 0;
|
||||
my $cur_status = '';
|
||||
|
||||
foreach my $status (reverse @{ $job->_statuslist }) {
|
||||
next if $status->phase
|
||||
and $status->phase !~ m/^(?:early|main|store|late)$/;
|
||||
|
||||
if ($status->level >= $cur_level) {
|
||||
$cur_level = $status->level;
|
||||
$cur_status = $status->status;
|
||||
}
|
||||
}
|
||||
|
||||
return $cur_status;
|
||||
}
|
||||
|
||||
=head2 finalise_status
|
||||
|
||||
Find the best status and log it into the job's C<status> and C<log> slots.
|
||||
|
||||
The process is to track back from the last worker and find the best status,
|
||||
which is C<done> in early or main phases, or else any status in any non-user
|
||||
phase.
|
||||
|
||||
=cut
|
||||
|
||||
sub finalise_status {
|
||||
|
||||
@@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces(
|
||||
);
|
||||
|
||||
our # try to hide from kwalitee
|
||||
$VERSION = 55; # schema version used for upgrades, keep as integer
|
||||
$VERSION = 56; # schema version used for upgrades, keep as integer
|
||||
|
||||
use Path::Class;
|
||||
use File::ShareDir 'dist_dir';
|
||||
|
||||
@@ -3,6 +3,7 @@ package App::Netdisco::Util::DeviceAuth;
|
||||
use Dancer qw/:syntax :script/;
|
||||
use App::Netdisco::Util::DNS 'hostname_from_ip';
|
||||
|
||||
use Storable 'dclone';
|
||||
use Try::Tiny;
|
||||
|
||||
use base 'Exporter';
|
||||
@@ -67,8 +68,8 @@ sub fixup_device_auth {
|
||||
}
|
||||
|
||||
# import legacy sshcollector configuration
|
||||
my $sshcollector = (setting('sshcollector') || []);
|
||||
foreach my $stanza (@$sshcollector) {
|
||||
my @sshcollector = @{ dclone (setting('sshcollector') || []) };
|
||||
foreach my $stanza (@sshcollector) {
|
||||
# defaults
|
||||
$stanza->{driver} = 'cli';
|
||||
$stanza->{read} = 1;
|
||||
|
||||
@@ -36,6 +36,7 @@ ajax '/ajax/control/admin/pseudodevice/add' => require_role admin => sub {
|
||||
ip => param('ip'),
|
||||
dns => param('dns'),
|
||||
vendor => 'netdisco',
|
||||
layers => '00000100',
|
||||
last_discover => \'now()',
|
||||
});
|
||||
return unless $device;
|
||||
|
||||
@@ -16,13 +16,10 @@ register_worker({ phase => 'check' }, sub {
|
||||
return Status->error("arpnip skipped: $device not yet discovered")
|
||||
unless $device->in_storage;
|
||||
|
||||
return Status->defer("arpnip skipped: $device is pseudo-device")
|
||||
if $device->is_pseudo;
|
||||
|
||||
return Status->defer("arpnip skipped: $device has no layer 3 capability")
|
||||
return Status->info("arpnip skipped: $device has no layer 3 capability")
|
||||
unless $device->has_layer(3);
|
||||
|
||||
return Status->defer("arpnip deferred: $device is not arpnipable")
|
||||
return Status->info("arpnip skipped: $device is not arpnipable")
|
||||
unless is_arpnipable_now($device);
|
||||
|
||||
return Status->done('arpnip is able to run');
|
||||
|
||||
@@ -35,7 +35,9 @@ register_worker({ phase => 'store' }, sub {
|
||||
$device->ip, scalar @{ vars->{'v6arps'} };
|
||||
|
||||
$device->update({last_arpnip => \$now});
|
||||
return Status->done("Ended arpnip for $device");
|
||||
|
||||
my $status = $job->best_status;
|
||||
return Status->$status("Ended arpnip for $device");
|
||||
});
|
||||
|
||||
register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
||||
@@ -53,7 +55,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
||||
push @{ vars->{'v6arps'} },
|
||||
@{get_arps_snmp($device, $snmp->ipv6_n2p_mac, $snmp->ipv6_n2p_addr) };
|
||||
|
||||
return Status->info("Gathered arp caches from $device");
|
||||
return Status->done("Gathered arp caches from $device");
|
||||
});
|
||||
|
||||
# get an arp table (v4 or v6)
|
||||
@@ -97,7 +99,7 @@ register_worker({ phase => 'main', driver => 'cli' }, sub {
|
||||
push @{ vars->{'v6arps'} },
|
||||
grep { NetAddr::IP::Lite->new($_->{ip})->bits == 128 } @arps;
|
||||
|
||||
return Status->info("Gathered arp caches from $device");
|
||||
return Status->done("Gathered arp caches from $device");
|
||||
});
|
||||
|
||||
sub get_arps_cli {
|
||||
|
||||
@@ -11,9 +11,8 @@ register_worker({ phase => 'main' }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
|
||||
my %queued = map {$_ => 1} jq_queued('arpnip');
|
||||
my @devices = schema('netdisco')->resultset('Device')->search({
|
||||
-or => [ 'vendor' => undef, 'vendor' => { '!=' => 'netdisco' }],
|
||||
})->has_layer('3')->get_column('ip')->all;
|
||||
my @devices = schema('netdisco')->resultset('Device')
|
||||
->has_layer('3')->get_column('ip')->all;
|
||||
my @filtered_devices = grep {!exists $queued{$_}} @devices;
|
||||
|
||||
jq_insert([
|
||||
|
||||
@@ -16,7 +16,7 @@ register_worker({ phase => 'check' }, sub {
|
||||
return Status->error("discover failed: no device param (need -d ?)")
|
||||
if $device->ip eq '0.0.0.0';
|
||||
|
||||
return Status->defer("discover skipped: $device is pseudo-device")
|
||||
return Status->info("discover skipped: $device is pseudo-device")
|
||||
if $device->is_pseudo;
|
||||
|
||||
# runner has already called get_device to promote $job->device
|
||||
@@ -24,7 +24,7 @@ register_worker({ phase => 'check' }, sub {
|
||||
if $device->in_storage
|
||||
and ($job->subaction eq 'with-nodes' and not $job->username);
|
||||
|
||||
return Status->defer("discover deferred: $device is not discoverable")
|
||||
return Status->info("discover skipped: $device is not discoverable")
|
||||
unless is_discoverable_now($device);
|
||||
|
||||
return Status->done('Discover is able to run.');
|
||||
|
||||
@@ -16,13 +16,13 @@ register_worker({ phase => 'check' }, sub {
|
||||
return Status->error("macsuck skipped: $device not yet discovered")
|
||||
unless $device->in_storage;
|
||||
|
||||
return Status->defer("macsuck skipped: $device is pseudo-device")
|
||||
return Status->info("macsuck skipped: $device is pseudo-device")
|
||||
if $device->is_pseudo;
|
||||
|
||||
return Status->defer("macsuck skipped: $device has no layer 2 capability")
|
||||
return Status->info("macsuck skipped: $device has no layer 2 capability")
|
||||
unless $device->has_layer(2);
|
||||
|
||||
return Status->defer("macsuck deferred: $device is not macsuckable")
|
||||
return Status->info("macsuck skipped: $device is not macsuckable")
|
||||
unless is_macsuckable_now($device);
|
||||
|
||||
return Status->done('Macsuck is able to run.');
|
||||
|
||||
@@ -12,7 +12,7 @@ register_worker({ phase => 'check' }, sub {
|
||||
return Status->error('nbtstat failed: unable to interpret device param')
|
||||
unless defined $job->device;
|
||||
|
||||
return Status->defer(sprintf 'nbtstat deferred: %s is not macsuckable', $job->device->ip)
|
||||
return Status->info(sprintf 'nbtstat skipped: %s is not macsuckable', $job->device->ip)
|
||||
unless is_macsuckable($job->device);
|
||||
|
||||
return Status->done('Nbtstat is able to run.');
|
||||
|
||||
@@ -97,8 +97,9 @@ A numeric constant for the status, to allow comparison.
|
||||
sub level {
|
||||
my $self = shift;
|
||||
return (($self->status eq 'done') ? 4
|
||||
: ($self->status eq 'info') ? 3
|
||||
: ($self->status eq 'defer') ? 2 : 1);
|
||||
: ($self->status eq 'defer') ? 3
|
||||
: ($self->status eq 'info') ? 2
|
||||
: ($self->status eq 'error') ? 1 : 0);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Reference in New Issue
Block a user