introduce noop and refactor checks in all workers

This commit is contained in:
Oliver Gorwits
2017-10-06 07:15:59 +01:00
parent 98463c8cad
commit 3af13f0dfe
26 changed files with 172 additions and 55 deletions

View File

@@ -8,18 +8,27 @@ use App::Netdisco::Transport::SNMP;
use App::Netdisco::Util::Port ':all';
register_worker({ stage => 'check' }, sub {
my ($job, $workerconf) = @_;
return Status->error('Missing device (-d).') unless defined $job->device;
return Status->error('Missing port (-p).') unless defined $job->port;
return Status->error('Missing name (-e).') unless defined $job->subaction;
my $port = get_port($job->device, $job->port)
or return Status->error(sprintf "Unknown port name [%s] on device %s",
$job->port, $job->device);
return Status->done('PortName is able to run');
});
register_worker({ stage => 'main' }, sub {
my ($job, $workerconf) = @_;
my ($device, $pn, $data) = map {$job->$_} qw/device port extra/;
return Status->error('Missing device (-d).') if !defined $device;
return Status->error('Missing port (-p).') if !defined $pn;
return Status->error('Missing name (-e).') if !defined $data;
# snmp connect using rw community
my $snmp = App::Netdisco::Transport::SNMP->writer_for($device)
or return Status->defer("failed to connect to $device to update alias");
my $port = get_port($device, $pn)
or return Status->error("Unknown port name [$pn] on device $device");
my $port = get_port($device, $pn);
my $iid = get_iid($snmp, $port)
or return Status->error("Failed to get port ID for [$pn] from $device");