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

@@ -9,20 +9,28 @@ use App::Netdisco::Util::Port ':all';
register_worker({ stage => 'check' }, sub {
my ($job, $workerconf) = @_;
my ($device, $pn) = map {$job->$_} qw/device port/;
return Status->error('Missing device (-d).') if !defined $device;
return Status->error('Missing port (-p).') if !defined $pn;
return Status->error('Missing status (-e).') if !defined $job->subaction;
return Status->error('Missing device (-d).') unless defined $job->device;
return Status->error('Missing port (-p).') unless defined $job->port;
return Status->error('Missing status (-e).') unless defined $job->subaction;
my $port = get_port($device, $pn)
or return Status->error("Unknown port name [$pn] on device $device");
my $port = get_port($job->device, $job->port)
or return Status->error(sprintf "Unknown port name [%s] on device %s",
$job->port, $job->device);
my $vlan_reconfig_check = vlan_reconfig_check($port);
return Status->error("Cannot alter vlan: $vlan_reconfig_check")
if $vlan_reconfig_check;
return Status->error("No PoE service on port [$pn] on device $device")
unless $port->power;
my $port_reconfig_check = port_reconfig_check($port);
return Status->error("Cannot alter port: $port_reconfig_check")
if $port_reconfig_check;
return Status->done('Power is able to run');
});
register_worker({ stage => 'main' }, sub {
my ($job, $workerconf) = @_;
my ($device, $pn) = map {$job->$_} qw/device port/;
my $port = get_port($device, $pn);
# munge data
(my $data = $job->subaction) =~ s/-\w+//; # remove -other