From 3db242cbe868e0672cba3b8ba1756e55cf46980c Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 23 Nov 2017 22:16:50 +0000 Subject: [PATCH] support action::namespace for netdisco-do --- bin/netdisco-do | 4 ++-- lib/App/Netdisco/Backend/Job.pm | 10 ++++++++++ lib/App/Netdisco/Worker/Plugin.pm | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bin/netdisco-do b/bin/netdisco-do index ab60f98e..859de29d 100755 --- a/bin/netdisco-do +++ b/bin/netdisco-do @@ -109,7 +109,7 @@ my $exitstatus = 0; foreach my $host (@hostlist) { my $dev = $host ? get_device($host->addr) : undef; - if ($dev and not (blessed $dev and $dev->in_storage) and $action ne 'discover') { + if ($dev and not (blessed $dev and $dev->in_storage) and $action !~ m/^discover/) { info sprintf "%s: error - Don't know device: %s", $action, $host->addr; next; } @@ -139,7 +139,7 @@ foreach my $host (@hostlist) { $job->log("error running job: $_"); }; - if ($job->log eq 'failed to report from any worker!') { + if ($job->log eq 'failed to report from any worker!' and not $job->only_namespace) { pod2usage( -msg => (sprintf 'error: %s is not a valid action', $action), -verbose => 2, diff --git a/lib/App/Netdisco/Backend/Job.pm b/lib/App/Netdisco/Backend/Job.pm index 72850e8f..ddbfd034 100644 --- a/lib/App/Netdisco/Backend/Job.pm +++ b/lib/App/Netdisco/Backend/Job.pm @@ -14,6 +14,7 @@ foreach my $slot (qw/ device port action + only_namespace subaction status username @@ -36,6 +37,15 @@ has '_statuslist' => ( default => sub { [] }, ); +sub BUILD { + my ($job, $args) = @_; + + if ($job->action =~ m/^(\w+)::(\w+)$/i) { + $job->action($1); + $job->only_namespace($2); + } +} + =head1 METHODS =head2 summary diff --git a/lib/App/Netdisco/Worker/Plugin.pm b/lib/App/Netdisco/Worker/Plugin.pm index 68440f52..746d8de0 100644 --- a/lib/App/Netdisco/Worker/Plugin.pm +++ b/lib/App/Netdisco/Worker/Plugin.pm @@ -36,6 +36,13 @@ register 'register_worker' => sub { # check to see if this namespace has already passed at higher priority return if $job->namespace_passed($workerconf); + # support part-actions via action::namespace + if ($job->only_namespace and $workerconf->{phase} ne 'check') { + return unless $workerconf->{namespace} eq lc( $job->only_namespace ) + or (($workerconf->{phase} eq 'early') + and ($job->device and not $job->device->in_storage)); + } + my @newuserconf = (); my @userconf = @{ setting('device_auth') || [] };