Merge the backend worker plugins branch og-coreplugins

Squashed commit of the following:

commit 86d0f61d0b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Nov 16 22:26:32 2017 +0000

    fix typo

commit 5aff19621c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Nov 16 22:10:18 2017 +0000

    fix use of snmp_connect_ip which does not work for SNMPv3

commit 68a56d35bb
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Nov 16 20:50:16 2017 +0000

    no need for Array::Iterator even though it was cute

commit 71ee869c02
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Nov 15 22:14:47 2017 +0000

    additional doc examples

commit 620b3fe544
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Nov 15 22:09:05 2017 +0000

    stash workers within poller instance, and load plugins explicitly

commit 2431365583
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Nov 13 22:17:11 2017 +0000

    better fix for duplicate module entity index

commit a400b26704
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Nov 13 22:14:42 2017 +0000

    add ignore interfaces for HPE routers

commit 1502ec1966
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Nov 13 22:08:02 2017 +0000

    bug fixes after testing on a real network

commit 840b6b4069
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Nov 12 20:38:35 2017 +0000

    add tests

commit 2de36c69ba
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Nov 12 00:14:21 2017 +0000

    some reengineering to support proper testing

commit c5f138fe62
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Nov 11 14:43:53 2017 +0000

    correct algorithm on finalise status, correct logging

commit 98442a2308
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Nov 9 21:49:45 2017 +0000

    bug fixes

commit e0c6615c87
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Nov 8 20:29:33 2017 +0000

    fix bugs

commit 1eeaba441d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Nov 7 22:30:55 2017 +0000

    finish refactor to new desired behaviour (buggy?)

commit 7edfe88f25
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Nov 6 22:50:51 2017 +0000

    fix to work, and correct namespace check

commit 25907d3544
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Nov 6 21:26:01 2017 +0000

    move status tracking and checking inside job instance

commit 4436150bf4
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Nov 5 20:54:28 2017 +0000

    remove global rubbish

commit 28b016e713
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Nov 4 23:31:51 2017 +0000

    fix docs

commit 650f6c719b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Nov 4 23:22:12 2017 +0000

    tidy line

commit 10f78d5dbe
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Nov 4 23:06:20 2017 +0000

    add priority and namespace to support fancy worker overrides

commit b9f9816d09
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Oct 11 18:33:46 2017 +0100

    release 2.036012_001

commit c33bf204a4
Merge: 5b7ce3f7 d3d81eb6
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Oct 11 18:30:23 2017 +0100

    Merge branch 'master' into og-coreplugins

commit 5b7ce3f797
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Oct 9 15:46:09 2017 +0100

    cannot Sereal::Encode DBIC row

commit 0a575f02ba
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Oct 9 14:07:56 2017 +0100

    fix bug in job->device init

commit 207476950d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Oct 9 14:03:37 2017 +0100

    default causes no attr to be created?!

commit 912f2fa91f
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Oct 8 18:43:51 2017 +0100

    better debug logging

commit dfeb9d9ddc
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Oct 8 18:40:02 2017 +0100

    make device_auth have driver setting for snmp entries

commit 460c0c0ee9
Merge: 3ccd107b 98423445
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Oct 8 18:08:58 2017 +0100

    Merge branch 'master' into og-coreplugins

commit 3ccd107bd4
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 14:13:58 2017 +0100

    fix bug in device->has_layer

commit a4b9bf2036
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 13:58:52 2017 +0100

    netdisco-do show takes a param for method in -p

commit 4389cd0459
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 13:36:06 2017 +0100

    fix to only check last poll on devices in storage

commit 58d0fbddda
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 13:21:13 2017 +0100

    do not run discover parts if properties failed to complete

commit b52aaaf1a1
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 13:08:46 2017 +0100

    fix typo

commit 41be926921
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 13:04:45 2017 +0100

    run all check workers

commit a41d114965
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 13:02:46 2017 +0100

    fix driver config

commit b10908a138
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 12:43:50 2017 +0100

    use vars() cache between phases

commit 08b34e083d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 11:39:17 2017 +0100

    remove die() calls

commit b8108986fb
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 11:31:59 2017 +0100

    phase fixups

commit 273cbbc11b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 09:42:41 2017 +0100

    change stage to phase

commit 256c10bae5
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 09:35:14 2017 +0100

    multi worker actions need not return done from all workers

commit ee38bae48a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 09:05:25 2017 +0100

    store result of worker if best for this phase so far

commit 5bddfc73ba
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Oct 7 08:50:31 2017 +0100

    auto debug-log worker return messages

commit 8b660a89c0
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Oct 6 07:48:58 2017 +0100

    bug fixes

commit b58a5816a9
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Oct 6 07:44:20 2017 +0100

    remove unnecessary check phases

commit e44f06364a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Oct 6 07:18:03 2017 +0100

    fix unknown command check in netdisco-do

commit 3af13f0dfe
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Oct 6 07:15:59 2017 +0100

    introduce noop and refactor checks in all workers

commit 98463c8cad
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Oct 1 10:49:12 2017 +0100

    no need to debug log if there are no hooks in phase

commit 3b32e84312
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Oct 1 08:18:13 2017 +0100

    fiddle about with runner logic to fix exit states

commit 8fdba38ee0
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Sep 29 08:01:42 2017 +0100

    cannot reuse a worker as the job will be already set and the wrong plugins loaded

commit a155d9cb77
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Sep 29 08:01:06 2017 +0100

    should defer when we cannot connect to device

commit 10b5f6cbc4
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Sep 29 08:00:32 2017 +0100

    fix bug in where workerconf acls are checked

commit 2a74e0befa
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Sep 29 07:38:05 2017 +0100

    can pass device instance to check_*

commit 4256b117df
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Sep 29 07:27:14 2017 +0100

    move device_auth build to be with community defaults setting

commit a2de2c1616
Merge: 32be11c3 8dc4b9bc
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Sep 29 07:21:03 2017 +0100

    Merge branch 'master' into og-coreplugins

commit 32be11c3ff
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Sep 21 00:09:29 2017 +0100

    move remaining interactive actions to be plugins

commit 3e41c93f5a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 20 21:47:50 2017 +0100

    clean snmp handling

commit 30a2d5dd86
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 20 21:00:29 2017 +0100

    make sure check plugins are loaded/run before phases

commit 3454d95a84
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 20 20:53:52 2017 +0100

    capture result on main phase as well

commit 559fa4f93f
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Sep 18 22:46:35 2017 +0100

    build device_auth from communities

commit 1969291719
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Sep 18 22:04:22 2017 +0100

    simplify to remove phases and fewer hooks

commit 6f78032e28
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Thu Sep 14 21:30:03 2017 +0100

    add phase to test worker

commit 6edd2dc879
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 13 21:51:40 2017 +0100

    no need to list all plugins

commit dfaeb34d8c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 13 20:42:41 2017 +0100

    add reset after messing with snmp context or community index

commit 09214dce92
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 13 20:29:21 2017 +0100

    no need to pass $snmp around

commit 58cd488ccc
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 13 19:22:40 2017 +0100

    refactor layer and pseudo checks

commit 753acc607f
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 13 10:53:12 2017 +0100

    use overloaded $device

commit d5d39289d6
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 13 10:44:31 2017 +0100

    rename init stage to check

commit 1fdb086183
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Sep 12 08:12:12 2017 +0100

    refactor to remove second loop

commit 64a9491115
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Sep 10 16:09:45 2017 +0100

    change to init, first, second stages

commit 5f2da69697
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Sep 9 22:26:04 2017 +0100

    move discover and discoverall to worker plugins

commit c6ebb7cf07
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Sep 9 16:44:32 2017 +0100

    move arpnip and arpwalk to worker plugins

commit 16a79463cb
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Sep 9 16:27:58 2017 +0100

    set snmp driver on macsuck phase workers

commit 9167e02de5
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Sep 9 15:55:53 2017 +0100

    move macsuck and macwalk to worker plugins (macsuck needs snmp scope guard)

commit 68ca85643b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Sep 9 14:56:15 2017 +0100

    move expire and expirenodes to worker plugins

commit 271ef1a25c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Sep 9 14:46:00 2017 +0100

    move nbtstat and nbtwalk to worker plugins

commit e7508a9eca
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 6 21:23:54 2017 +0100

    move all netdisco-do action to worker plugins

commit 707fc82b99
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 6 21:01:37 2017 +0100

    remove psql code from netdisco-do and fix detection of misspelled action

commit 411918e3f8
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 6 20:56:26 2017 +0100

    only load worker plugins for the action

commit 1f9740c0e2
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 6 18:30:43 2017 +0100

    shorten hook names

commit a59c23de79
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Sep 6 18:27:34 2017 +0100

    make psql worker primary, add hook debug log

commit 36c70220a2
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Sep 5 22:39:22 2017 +0100

    allow two forms of worker declaration, and update docs

commit a79cb9a9e4
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Sep 5 22:10:53 2017 +0100

    all the bug fixes and a working plugin!!!!!!!!! :-D

commit 04896202e0
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Sep 5 21:39:41 2017 +0100

    refine runner

commit 547fce2f3c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Sep 5 20:56:21 2017 +0100

    hack the status class to regen if needed

commit cd71a0b7a8
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Sep 5 20:41:05 2017 +0100

    move status update to job class

commit c8e5cea4ed
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Sep 5 20:37:13 2017 +0100

    objectify the running

commit f48004fffa
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Sep 5 19:58:28 2017 +0100

    bug squish

commit 46ece568f6
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Sep 5 19:54:57 2017 +0100

    implement runner?!

commit fc9c60f707
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Sep 5 19:28:38 2017 +0100

    rename ok to is_ok and change slot names to avoid conflict with creators

commit 3ee85383ab
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Sep 5 19:25:41 2017 +0100

    skip worker when action is per-device but no creds

commit 75abdad812
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Sep 4 21:54:37 2017 +0100

    further work on retval handling from workers

commit 4c1fdf4f92
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Sep 4 20:37:53 2017 +0100

    move worker plugin loader to Worker.pm

commit be0c5181a3
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Sep 4 20:35:42 2017 +0100

    move Runner to Worker namespace

commit 1c2cf924bc
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Sep 4 20:33:20 2017 +0100

    worker roles in Role namespace

commit 3099eda393
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Sep 4 20:30:58 2017 +0100

    load workers when runner role is loaded

commit a8c58a7b05
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Sep 3 22:30:28 2017 +0100

    initial broken implementation of the runner

commit 49b5274c33
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Sep 3 19:04:20 2017 +0100

    use run() mixin to exec action

commit e0a666668a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Sep 3 18:54:44 2017 +0100

    fix pod; set status defaults; stub runner mixin

commit 8eaa33770c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Sep 3 18:45:00 2017 +0100

    rename Core to Worker and move other packages around

commit 4def0af0b0
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Sep 3 17:58:03 2017 +0100

    better use of new status class

commit 8675bf62c6
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Sep 3 17:27:38 2017 +0100

    fix hook naming and implement primary workers

commit ef1bb81f2b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Sep 3 17:26:27 2017 +0100

    new backend status class

commit 5f50dfadf1
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Sep 3 16:51:55 2017 +0100

    new Backend package to load core plugins

commit 3baa7a818a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Sep 3 16:22:29 2017 +0100

    remove unnecessary Worker::Common role

commit 36b4adcc06
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Sep 3 16:17:29 2017 +0100

    disambiguate util/backend package and remove backend prelaod

commit 98bff731bd
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Sep 2 08:25:06 2017 +0100

    settle on a design for hook override, I think

commit fe5c16a16d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Aug 30 20:37:36 2017 +0100

    rework docs to be more clear and reflect new operation

commit b34ba1977c
Merge: 31d1977f c34ed61d
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Aug 21 21:17:46 2017 +0100

    Merge branch 'master' into og-coreplugins

commit 31d1977f1e
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Aug 14 18:11:42 2017 +0100

    Revert "move expire code to be initial plugin pilot (broken)"

    I think we'll only do the new backend code for jobs with a device.

    This reverts commit 07998b72d9.

commit 61dc80aff8
Merge: 07998b72 ade02db1
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Aug 14 18:10:29 2017 +0100

    Merge branch 'master' into og-coreplugins

commit 07998b72d9
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Aug 5 22:15:00 2017 +0100

    move expire code to be initial plugin pilot (broken)

commit 685ec02108
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Aug 5 22:10:58 2017 +0100

    pass $job to the core worker

commit d6523fe543
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Aug 5 22:01:49 2017 +0100

    $job->device is always a DBIC row

commit ee6deea01b
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Aug 5 18:12:34 2017 +0100

    load plugins

commit fd80096ca2
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Aug 5 16:53:16 2017 +0100

    rename all the things

commit 464c42d1f5
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Aug 2 10:19:16 2017 +0100

    use Scope::Guard to reduce device_auth

commit ec041dafd2
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Aug 1 15:34:37 2017 +0100

    the other way around

commit 33d2fe13bd
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jul 31 17:57:29 2017 +0100

    fix pod

commit 3faee1cf16
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Mon Jul 31 17:55:10 2017 +0100

    remove need for instance() call

commit c6d0f1c035
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 26 13:51:23 2017 +0100

    add doc note on accessing transports

commit dca4b4fc03
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 26 11:50:10 2017 +0100

    add backend driver documentation

commit 052a2acd79
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 26 10:16:58 2017 +0100

    rename web plugins doc

commit 69c9a6393a
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 26 10:12:42 2017 +0100

    rename args to driverconf

commit 2586a36f8c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Jul 25 22:41:10 2017 +0100

    new version of core plugin manager with better config and filters

commit 4056831f99
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Tue Jul 25 20:53:56 2017 +0100

    change SNMP to be a cached transport singleton

commit c31030ef70
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sun Jul 23 13:46:27 2017 +0100

    fixes because Dancer docs are a mess!

commit f65ef90b86
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jul 22 08:11:36 2017 +0100

    rename snmp_auth to device_auth and include a little doc on transports

commit d61556e1cf
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Sat Jul 22 07:54:26 2017 +0100

    plugin config added

commit de8de56308
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Wed Jul 12 21:38:31 2017 +0100

    initial core plugin implementation
This commit is contained in:
Oliver Gorwits
2017-11-19 13:34:35 +00:00
parent d3d81eb67d
commit 5ff7d6fe47
85 changed files with 4078 additions and 2502 deletions

View File

@@ -1,5 +1,8 @@
package App::Netdisco::Backend::Job;
use Dancer qw/:moose :syntax !error/;
use aliased 'App::Netdisco::Worker::Status';
use Moo;
use namespace::clean;
@@ -16,7 +19,10 @@ foreach my $slot (qw/
username
userip
log
debug
_current_phase
_last_namespace
_last_priority
/) {
has $slot => (
@@ -24,25 +30,147 @@ foreach my $slot (qw/
);
}
has '_statuslist' => (
is => 'rw',
default => sub { [] },
);
=head1 METHODS
=head2 summary
An attempt to make a meaningful statement about the job.
An attempt to make a meaningful written statement about the job.
=cut
sub summary {
my $job = shift;
return join ' ',
$job->action,
($job->device || ''),
($job->port || '');
# ($job->subaction ? (q{'}. $job->subaction .q{'}) : '');
my $job = shift;
return join ' ',
$job->action,
($job->device || ''),
($job->port || '');
}
=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 {
my $job = shift;
# use DDP; p $job->_statuslist;
# fallback
$job->status('error');
$job->log('failed to report from any worker!');
my $max_level = Status->error()->level;
foreach my $status (reverse @{ $job->_statuslist }) {
next if $status->phase
and $status->phase !~ m/^(?:check|early|main)$/;
next if $status->phase eq 'check'
and $status->level eq Status->done()->level;
if ($status->level >= $max_level) {
$job->status( $status->status );
$job->log( $status->log );
$max_level = $status->level;
}
}
}
=head2 check_passed
Returns true if at least one worker during the C<check> phase flagged status
C<done>.
=cut
sub check_passed {
my $job = shift;
return true if 0 == scalar @{ $job->_statuslist };
foreach my $status (@{ $job->_statuslist }) {
next unless $status->phase and $status->phase eq 'check';
return true if $status->is_ok;
}
return false;
}
=head2 namespace_passed( \%workerconf )
Returns true when, for the namespace specified in the given configuration, a
worker of a higher priority level has already succeeded.
=cut
sub namespace_passed {
my ($job, $workerconf) = @_;
if ($job->_last_namespace) {
foreach my $status (@{ $job->_statuslist }) {
next unless ($status->phase and $status->phase eq $workerconf->{phase})
and ($workerconf->{namespace} eq $job->_last_namespace)
and ($workerconf->{priority} < $job->_last_priority);
return true if $status->is_ok;
}
}
$job->_last_namespace( $workerconf->{namespace} );
$job->_last_priority( $workerconf->{priority} );
return false;
}
=head2 enter_phase( $phase )
Pass the name of the phase being entered.
=cut
sub enter_phase {
my ($job, $phase) = @_;
$job->_current_phase( $phase );
debug "=> running workers for phase: $phase";
$job->_last_namespace( undef );
$job->_last_priority( undef );
}
=head2 add_status
Passed an L<App::Netdisco::Worker::Status> will add it to this job's internal
status cache. Phase slot of the Status will be set to the current phase.
=cut
sub add_status {
my ($job, $status) = @_;
return unless ref $status eq 'App::Netdisco::Worker::Status';
$status->phase( $job->_current_phase || '' );
push @{ $job->_statuslist }, $status;
debug $status->log if $status->log
and (($status->phase eq 'check')
or ($status->level ne Status->done()->level));
}
=head1 ADDITIONAL COLUMNS
=head2 id
Alias for the C<job> column.
=cut
sub id { (shift)->job }
=head2 extra
Alias for the C<subaction> column.
@@ -51,4 +179,4 @@ Alias for the C<subaction> column.
sub extra { (shift)->subaction }
1;
true;

View File

@@ -1,16 +1,16 @@
package App::Netdisco::Backend::Worker::Manager;
package App::Netdisco::Backend::Role::Manager;
use Dancer qw/:moose :syntax :script/;
use List::Util 'sum';
use App::Netdisco::Util::Backend;
use Role::Tiny;
use namespace::clean;
use App::Netdisco::Util::MCE;
use App::Netdisco::JobQueue
qw/jq_locked jq_getsome jq_getsomep jq_lock jq_warm_thrusters/;
use Role::Tiny;
use namespace::clean;
sub worker_begin {
my $self = shift;
my $wid = $self->wid;
@@ -58,7 +58,7 @@ sub worker_body {
# mark job as running
next unless jq_lock($job);
info sprintf "mgr (%s): job %s booked out for this processing node",
$wid, $job->job;
$wid, $job->id;
# copy job to local queue
$self->{queue}->enqueuep(100, $job);
@@ -75,7 +75,7 @@ sub worker_body {
# mark job as running
next unless jq_lock($job);
info sprintf "mgr (%s): job %s booked out for this processing node",
$wid, $job->job;
$wid, $job->id;
# copy job to local queue
$self->{queue}->enqueue($job);

View File

@@ -1,15 +1,18 @@
package App::Netdisco::Backend::Worker::Common;
package App::Netdisco::Backend::Role::Poller;
use Dancer qw/:moose :syntax :script/;
use Try::Tiny;
use App::Netdisco::Util::Backend;
use App::Netdisco::Util::MCE;
use Time::HiRes 'sleep';
use App::Netdisco::JobQueue qw/jq_defer jq_complete/;
use Role::Tiny;
use namespace::clean;
use Time::HiRes 'sleep';
use App::Netdisco::JobQueue qw/jq_defer jq_complete/;
# add dispatch methods for poller tasks
with 'App::Netdisco::Worker::Runner';
sub worker_begin { (shift)->{started} = time }
@@ -22,17 +25,14 @@ sub worker_body {
my $job = $self->{queue}->dequeue(1);
next unless defined $job;
my $action = $job->action;
try {
$job->started(scalar localtime);
prctl sprintf 'nd2: #%s poll: #%s: %s',
$wid, $job->job, $job->summary;
$wid, $job->id, $job->summary;
info sprintf "pol (%s): starting %s job(%s) at %s",
$wid, $action, $job->job, $job->started;
my ($status, $log) = $self->$action($job);
$job->status($status);
$job->log($log);
$wid, $job->action, $job->id, $job->started;
$self->run($job);
}
catch {
$job->status('error');
@@ -51,7 +51,7 @@ sub close_job {
my $now = scalar localtime;
info sprintf "pol (%s): wrapping up %s job(%s) - status %s at %s",
$self->wid, $job->action, $job->job, $job->status, $now;
$self->wid, $job->action, $job->id, $job->status, $now;
try {
if ($job->status eq 'defer') {

View File

@@ -1,15 +1,15 @@
package App::Netdisco::Backend::Worker::Scheduler;
package App::Netdisco::Backend::Role::Scheduler;
use Dancer qw/:moose :syntax :script/;
use Algorithm::Cron;
use App::Netdisco::Util::Backend;
use App::Netdisco::Util::MCE;
use App::Netdisco::JobQueue qw/jq_insert/;
use Role::Tiny;
use namespace::clean;
use App::Netdisco::JobQueue qw/jq_insert/;
sub worker_begin {
my $self = shift;
my $wid = $self->wid;

View File

@@ -1,17 +0,0 @@
package App::Netdisco::Backend::Util;
use strict;
use warnings;
# support utilities for Backend Actions
use base 'Exporter';
our @EXPORT = ();
our @EXPORT_OK = qw/ job_done job_error job_defer /;
our %EXPORT_TAGS = (all => \@EXPORT_OK);
sub job_done { return ('done', shift) }
sub job_error { return ('error', shift) }
sub job_defer { return ('defer', shift) }
1;

View File

@@ -1,50 +0,0 @@
package App::Netdisco::Backend::Worker::Interactive::DeviceActions;
use App::Netdisco::Util::SNMP 'snmp_connect_rw';
use App::Netdisco::Util::Device 'get_device';
use App::Netdisco::Backend::Util ':all';
use Role::Tiny;
use namespace::clean;
sub location {
my ($self, $job) = @_;
return _set_device_generic($job->device, 'location', $job->subaction);
}
sub contact {
my ($self, $job) = @_;
return _set_device_generic($job->device, 'contact', $job->subaction);
}
sub _set_device_generic {
my ($ip, $slot, $data) = @_;
$data ||= '';
# snmp connect using rw community
my $info = snmp_connect_rw($ip)
or return job_defer("Failed to connect to device [$ip] to update $slot");
my $method = 'set_'. $slot;
my $rv = $info->$method($data);
if (!defined $rv) {
return job_error(sprintf 'Failed to set %s on [%s]: %s',
$slot, $ip, ($info->error || ''));
}
# confirm the set happened
$info->clear_cache;
my $new_data = ($info->$slot || '');
if ($new_data ne $data) {
return job_error("Verify of $slot update failed on [$ip]: $new_data");
}
# update netdisco DB
my $device = get_device($ip);
$device->update({$slot => $data});
return job_done("Updated $slot on [$ip] to [$data]");
}
1;

View File

@@ -1,159 +0,0 @@
package App::Netdisco::Backend::Worker::Interactive::PortActions;
use App::Netdisco::Util::Port ':all';
use App::Netdisco::Util::SNMP 'snmp_connect_rw';
use App::Netdisco::Util::Device 'get_device';
use App::Netdisco::Backend::Util ':all';
use Role::Tiny;
use namespace::clean;
sub portname {
my ($self, $job) = @_;
return _set_port_generic($job, 'alias', 'name');
}
sub portcontrol {
my ($self, $job) = @_;
my $port = get_port($job->device, $job->port)
or return job_error(sprintf "Unknown port name [%s] on device [%s]",
$job->port, $job->device);
my $reconfig_check = port_reconfig_check($port);
return job_error("Cannot alter port: $reconfig_check")
if $reconfig_check;
# need to remove "-other" which appears for power/portcontrol
(my $sa = $job->subaction) =~ s/-\w+//;
$job->subaction($sa);
if ($sa eq 'bounce') {
$job->subaction('down');
my @stat = _set_port_generic($job, 'up_admin');
return @stat if $stat[0] ne 'done';
$job->subaction('up');
return _set_port_generic($job, 'up_admin');
}
else {
return _set_port_generic($job, 'up_admin');
}
}
sub vlan {
my ($self, $job) = @_;
my $port = get_port($job->device, $job->port)
or return job_error(sprintf "Unknown port name [%s] on device [%s]",
$job->port, $job->device);
my $port_reconfig_check = port_reconfig_check($port);
return job_error("Cannot alter port: $port_reconfig_check")
if $port_reconfig_check;
my $vlan_reconfig_check = vlan_reconfig_check($port);
return job_error("Cannot alter vlan: $vlan_reconfig_check")
if $vlan_reconfig_check;
my @stat = _set_port_generic($job, 'pvid'); # for Cisco trunk
return @stat if $stat[0] eq 'done';
return _set_port_generic($job, 'vlan');
}
sub _set_port_generic {
my ($job, $slot, $column) = @_;
$column ||= $slot;
my $device = get_device($job->device);
my $ip = $device->ip;
my $pn = $job->port;
my $data = $job->subaction;
my $port = get_port($ip, $pn)
or return job_error("Unknown port name [$pn] on device [$ip]");
if ($device->vendor ne 'netdisco') {
# snmp connect using rw community
my $info = snmp_connect_rw($ip)
or return job_defer("Failed to connect to device [$ip] to control port");
my $iid = get_iid($info, $port)
or return job_error("Failed to get port ID for [$pn] from [$ip]");
my $method = 'set_i_'. $slot;
my $rv = $info->$method($data, $iid);
if (!defined $rv) {
return job_error(sprintf 'Failed to set [%s] %s to [%s] on [%s]: %s',
$pn, $slot, $data, $ip, ($info->error || ''));
}
# confirm the set happened
$info->clear_cache;
my $check_method = 'i_'. $slot;
my $state = ($info->$check_method($iid) || '');
if (ref {} ne ref $state or $state->{$iid} ne $data) {
return job_error("Verify of [$pn] $slot failed on [$ip]");
}
}
# update netdisco DB
$port->update({$column => $data});
return job_done("Updated [$pn] $slot status on [$ip] to [$data]");
}
sub power {
my ($self, $job) = @_;
my $port = get_port($job->device, $job->port)
or return job_error(sprintf "Unknown port name [%s] on device [%s]",
$job->port, $job->device);
return job_error("No PoE service on port [%s] on device [%s]")
unless $port->power;
my $reconfig_check = port_reconfig_check($port);
return job_error("Cannot alter port: $reconfig_check")
if $reconfig_check;
my $device = get_device($job->device);
my $ip = $device->ip;
my $pn = $job->port;
# munge data
(my $data = $job->subaction) =~ s/-\w+//; # remove -other
$data = 'true' if $data =~ m/^(on|yes|up)$/;
$data = 'false' if $data =~ m/^(off|no|down)$/;
# snmp connect using rw community
my $info = snmp_connect_rw($ip)
or return job_defer("Failed to connect to device [$ip] to control power");
my $powerid = get_powerid($info, $port)
or return job_error("Failed to get power ID for [$pn] from [$ip]");
my $rv = $info->set_peth_port_admin($data, $powerid);
if (!defined $rv) {
return job_error(sprintf 'Failed to set [%s] power to [%s] on [%s]: %s',
$pn, $data, $ip, ($info->error || ''));
}
# confirm the set happened
$info->clear_cache;
my $state = ($info->peth_port_admin($powerid) || '');
if (ref {} ne ref $state or $state->{$powerid} ne $data) {
return job_error("Verify of [$pn] power failed on [$ip]");
}
# update netdisco DB
$port->power->update({
admin => $data,
status => ($data eq 'false' ? 'disabled' : 'searching'),
});
return job_done("Updated [$pn] power status on [$ip] to [$data]");
}
1;

View File

@@ -1,18 +0,0 @@
package App::Netdisco::Backend::Worker::Poller;
use Role::Tiny;
use namespace::clean;
# main worker body
with 'App::Netdisco::Backend::Worker::Common';
# add dispatch methods for poller tasks
with 'App::Netdisco::Backend::Worker::Poller::Device',
'App::Netdisco::Backend::Worker::Poller::Arpnip',
'App::Netdisco::Backend::Worker::Poller::Macsuck',
'App::Netdisco::Backend::Worker::Poller::Nbtstat',
'App::Netdisco::Backend::Worker::Poller::Expiry',
'App::Netdisco::Backend::Worker::Interactive::DeviceActions',
'App::Netdisco::Backend::Worker::Interactive::PortActions';
1;

View File

@@ -1,18 +0,0 @@
package App::Netdisco::Backend::Worker::Poller::Arpnip;
use App::Netdisco::Core::Arpnip 'do_arpnip';
use App::Netdisco::Util::Device 'is_arpnipable_now';
use Role::Tiny;
use namespace::clean;
with 'App::Netdisco::Backend::Worker::Poller::Common';
sub arpnip_action { \&do_arpnip }
sub arpnip_filter { \&is_arpnipable_now }
sub arpnip_layer { 3 }
sub arpwalk { (shift)->_walk_body('arpnip', @_) }
sub arpnip { (shift)->_single_body('arpnip', @_) }
1;

View File

@@ -1,99 +0,0 @@
package App::Netdisco::Backend::Worker::Poller::Common;
use Dancer qw/:moose :syntax :script/;
use App::Netdisco::Util::SNMP 'snmp_connect';
use App::Netdisco::Util::Device 'get_device';
use App::Netdisco::Backend::Util ':all';
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
use Dancer::Plugin::DBIC 'schema';
use NetAddr::IP::Lite ':lower';
use Role::Tiny;
use namespace::clean;
# queue a job for all devices known to Netdisco
sub _walk_body {
my ($self, $job_type, $job) = @_;
my $layer_method = $job_type .'_layer';
my $job_layer = $self->$layer_method;
my %queued = map {$_ => 1} jq_queued($job_type);
my @devices = schema('netdisco')->resultset('Device')->search({
-or => [ 'vendor' => undef, 'vendor' => { '!=' => 'netdisco' }],
})->has_layer($job_layer)->get_column('ip')->all;
my @filtered_devices = grep {!exists $queued{$_}} @devices;
jq_insert([
map {{
device => $_,
action => $job_type,
username => $job->username,
userip => $job->userip,
}} (@filtered_devices)
]);
return job_done("Queued $job_type job for all devices");
}
sub _single_body {
my ($self, $job_type, $job) = @_;
my $action_method = $job_type .'_action';
my $job_action = $self->$action_method;
my $layer_method = $job_type .'_layer';
my $job_layer = $self->$layer_method;
my $device = get_device($job->device)
or job_error("$job_type failed: unable to interpret device parameter");
my $host = $device->ip;
if ($device->in_storage
and $device->vendor and $device->vendor eq 'netdisco') {
return job_done("$job_type skipped: $host is pseudo-device");
}
my $filter_method = $job_type .'_filter';
my $job_filter = $self->$filter_method;
unless ($job_filter->($device->ip)) {
return job_defer("$job_type deferred: $host is not ${job_type}able");
}
my $snmp = snmp_connect($device);
if (!defined $snmp) {
return job_defer("$job_type failed: could not SNMP connect to $host");
}
unless ($snmp->has_layer( $job_layer )) {
return job_done("Skipped $job_type for device $host without OSI layer $job_layer capability");
}
$job_action->($device, $snmp);
return job_done("Ended $job_type for $host");
}
sub _single_node_body {
my ($self, $job_type, $node, $now) = @_;
my $action_method = $job_type .'_action';
my $job_action = $self->$action_method;
my $filter_method = $job_type .'_filter';
my $job_filter = $self->$filter_method;
unless ($job_filter->($node)) {
return job_defer("$job_type deferred: $node is not ${job_type}able");
}
$job_action->($node, $now);
# would be ignored if wrapped in a loop
return job_done("Ended $job_type for $node");
}
1;

View File

@@ -1,100 +0,0 @@
package App::Netdisco::Backend::Worker::Poller::Device;
use Dancer qw/:moose :syntax :script/;
use App::Netdisco::Util::SNMP 'snmp_connect';
use App::Netdisco::Util::Device qw/get_device is_discoverable_now/;
use App::Netdisco::Core::Discover ':all';
use App::Netdisco::Backend::Util ':all';
use App::Netdisco::JobQueue qw/jq_queued jq_insert/;
use Dancer::Plugin::DBIC 'schema';
use NetAddr::IP::Lite ':lower';
use Role::Tiny;
use namespace::clean;
# queue a discover job for all devices known to Netdisco
sub discoverall {
my ($self, $job) = @_;
my %queued = map {$_ => 1} jq_queued('discover');
my @devices = schema('netdisco')->resultset('Device')->search({
-or => [ 'vendor' => undef, 'vendor' => { '!=' => 'netdisco' }],
})->get_column('ip')->all;
my @filtered_devices = grep {!exists $queued{$_}} @devices;
jq_insert([
map {{
device => $_,
action => 'discover',
username => $job->username,
userip => $job->userip,
}} (@filtered_devices)
]);
return job_done("Queued discover job for all devices");
}
# run a discover job for one device, and its *new* neighbors
sub discover {
my ($self, $job) = @_;
my $device = get_device($job->device)
or return job_error(
"discover failed: unable to interpret device parameter: "
. ($job->device || "''"));
my $host = $device->ip;
if ($device->ip eq '0.0.0.0') {
return job_error("discover failed: no device param (need -d ?)");
}
if ($device->in_storage
and $device->vendor and $device->vendor eq 'netdisco') {
return job_done("discover skipped: $host is pseudo-device");
}
unless (is_discoverable_now($device)) {
return job_defer("discover deferred: $host is not discoverable");
}
my $snmp = snmp_connect($device);
if (!defined $snmp) {
return job_defer("discover failed: could not SNMP connect to $host");
}
store_device($device, $snmp);
set_canonical_ip($device, $snmp); # must come after store_device
store_interfaces($device, $snmp);
store_wireless($device, $snmp);
store_vlans($device, $snmp);
store_power($device, $snmp);
store_modules($device, $snmp) if setting('store_modules');
discover_new_neighbors($device, $snmp);
# if requested, and the device has not yet been arpniped/macsucked, queue now
if ($device->in_storage and $job->subaction and $job->subaction eq 'with-nodes') {
if (!defined $device->last_macsuck) {
jq_insert({
device => $device->ip,
action => 'macsuck',
username => $job->username,
userip => $job->userip,
});
}
if (!defined $device->last_arpnip) {
jq_insert({
device => $device->ip,
action => 'arpnip',
username => $job->username,
userip => $job->userip,
});
}
}
return job_done("Ended discover for $host");
}
1;

View File

@@ -1,78 +0,0 @@
package App::Netdisco::Backend::Worker::Poller::Expiry;
use Dancer qw/:moose :syntax :script/;
use Dancer::Plugin::DBIC 'schema';
use App::Netdisco::Backend::Util ':all';
use App::Netdisco::Util::Statistics 'update_stats';
use Role::Tiny;
use namespace::clean;
# expire devices and nodes according to config
sub expire {
my ($self, $job) = @_;
if (setting('expire_devices') and setting('expire_devices') > 0) {
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('Device')->search({
-or => [ 'vendor' => undef, 'vendor' => { '!=' => 'netdisco' }],
last_discover => \[q/< (now() - ?::interval)/,
(setting('expire_devices') * 86400)],
})->delete();
});
}
if (setting('expire_nodes') and setting('expire_nodes') > 0) {
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('Node')->search({
time_last => \[q/< (now() - ?::interval)/,
(setting('expire_nodes') * 86400)],
})->delete();
});
}
if (setting('expire_nodes_archive') and setting('expire_nodes_archive') > 0) {
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('Node')->search({
-not_bool => 'active',
time_last => \[q/< (now() - ?::interval)/,
(setting('expire_nodes_archive') * 86400)],
})->delete();
});
}
if (setting('expire_jobs') and setting('expire_jobs') > 0) {
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('Admin')->search({
entered => \[q/< (now() - ?::interval)/,
(setting('expire_jobs') * 86400)],
})->delete();
});
}
# now update stats
update_stats();
return job_done("Checked expiry and updated stats");
}
# expire nodes for a specific device
sub expirenodes {
my ($self, $job) = @_;
return job_error('Missing device') unless $job->device;
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('Node')->search({
switch => $job->device->ip,
($job->port ? (port => $job->port) : ()),
})->delete(
($job->extra ? () : ({ archive_nodes => 1 }))
);
});
return job_done("Expired nodes for ". $job->device->ip);
}
1;

View File

@@ -1,18 +0,0 @@
package App::Netdisco::Backend::Worker::Poller::Macsuck;
use App::Netdisco::Core::Macsuck 'do_macsuck';
use App::Netdisco::Util::Device 'is_macsuckable_now';
use Role::Tiny;
use namespace::clean;
with 'App::Netdisco::Backend::Worker::Poller::Common';
sub macsuck_action { \&do_macsuck }
sub macsuck_filter { \&is_macsuckable_now }
sub macsuck_layer { 2 }
sub macwalk { (shift)->_walk_body('macsuck', @_) }
sub macsuck { (shift)->_single_body('macsuck', @_) }
1;

View File

@@ -1,73 +0,0 @@
package App::Netdisco::Backend::Worker::Poller::Nbtstat;
use Dancer qw/:moose :syntax :script/;
use Dancer::Plugin::DBIC 'schema';
use App::Netdisco::Core::Nbtstat qw/nbtstat_resolve_async store_nbt/;
use App::Netdisco::Util::Node 'is_nbtstatable';
use App::Netdisco::Util::Device qw/get_device is_macsuckable/;
use App::Netdisco::Backend::Util ':all';
use NetAddr::IP::Lite ':lower';
use Time::HiRes 'gettimeofday';
use Role::Tiny;
use namespace::clean;
with 'App::Netdisco::Backend::Worker::Poller::Common';
sub nbtstat_action { \&do_nbtstat }
sub nbtstat_filter { \&is_nbtstatable }
sub nbtstat_layer { 2 }
sub nbtwalk { (shift)->_walk_body('nbtstat', @_) }
sub nbtstat {
my ($self, $job) = @_;
my $device = get_device($job->device)
or job_error("nbtstat failed: unable to interpret device parameter");
my $host = $device->ip;
unless (is_macsuckable($device)) {
return job_defer("nbtstat deferred: $host is not macsuckable");
}
# get list of nodes on device
my $interval = (setting('nbtstat_max_age') || 7) . ' day';
my $rs = schema('netdisco')->resultset('NodeIp')->search({
-bool => 'me.active',
-bool => 'nodes.active',
'nodes.switch' => $device->ip,
'me.time_last' => \[ '>= now() - ?::interval', $interval ],
},{
join => 'nodes',
columns => 'ip',
distinct => 1,
})->ip_version(4);
my @nodes = $rs->get_column('ip')->all;
# Unless we have IP's don't bother
if (scalar @nodes) {
# filter exclusions from config
@nodes = grep { is_nbtstatable( $_ ) } @nodes;
# setup the hash nbtstat_resolve_async expects
my @ips = map {+{'ip' => $_}} @nodes;
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
my $resolved_nodes = nbtstat_resolve_async(\@ips);
# update node_nbt with status entries
foreach my $result (@$resolved_nodes) {
if (defined $result->{'nbname'}) {
store_nbt($result, $now);
}
}
}
return job_done("Ended nbtstat for $host");
}
1;