From 685ec021080269e8f5dbfe4b940c8037b8289ec3 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 5 Aug 2017 22:10:58 +0100 Subject: [PATCH] pass $job to the core worker --- lib/App/Netdisco/Core/Plugin.pm | 10 ++++++---- lib/App/Netdisco/Manual/WritingCoreWorkers.pod | 12 ++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/App/Netdisco/Core/Plugin.pm b/lib/App/Netdisco/Core/Plugin.pm index 9042f19c..04f0314a 100644 --- a/lib/App/Netdisco/Core/Plugin.pm +++ b/lib/App/Netdisco/Core/Plugin.pm @@ -26,7 +26,7 @@ register 'register_core_worker' => sub { unless $workerconf->{hook} =~ m/^(?:before|on|after)$/; my $worker = sub { - my $device = shift or return false; + my $job = shift or return false; my $no = (exists $workerconf->{no} ? $workerconf->{no} : undef); my $only = (exists $workerconf->{only} ? $workerconf->{only} : undef); @@ -36,8 +36,10 @@ register 'register_core_worker' => sub { # reduce device_auth by driver, plugin, worker's only/no foreach my $stanza (@userconf) { - next if $no and check_acl_no($device, $no); - next if $only and not check_acl_only($device, $only); + if (ref $job->device) { + next if $no and check_acl_no($job->device->ip, $no); + next if $only and not check_acl_only($job->device->ip, $only); + } next if exists $stanza->{driver} and (($stanza->{driver} || '') ne $workerconf->{driver}); push @newuserconf, $stanza; @@ -51,7 +53,7 @@ register 'register_core_worker' => sub { # run worker my $happy = false; try { - $code->($device, $workerconf); + $code->($job, $workerconf); $happy = true; } catch { debug $_ }; diff --git a/lib/App/Netdisco/Manual/WritingCoreWorkers.pod b/lib/App/Netdisco/Manual/WritingCoreWorkers.pod index 370deffc..5c0f5a61 100644 --- a/lib/App/Netdisco/Manual/WritingCoreWorkers.pod +++ b/lib/App/Netdisco/Manual/WritingCoreWorkers.pod @@ -55,13 +55,13 @@ An explanation of the C<%workerconf> options is below. The C<$coderef> is the main body of your worker. Your worker is run in a L statement to catch errors, and passed the following arguments: - $coderef->($device, $workerconf); + $coderef->($job, $workerconf); -The C<$device> is an instance of L (that -is, an object representation of a row in the database). Note that for early -discover phases this row may not yet exist in the database. The C<$workerconf> -hashref is the set of configuration parameters you used to declare the worker -(documented below). +The C<$job> is an instance of L. Note that this +class has a C slot which may be filled, depending on the action, and +if the device is not yet discovered then the row will not yet be in storage. +The C<$workerconf> hashref is the set of configuration parameters you used +to declare the worker (documented below). =head2 Package Naming Convention