| 1 | package App::Netdisco::Worker::Plugin::Vlan; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use App::Netdisco::Worker::Plugin; | ||
| 5 | use aliased 'App::Netdisco::Worker::Status'; | ||
| 6 | |||
| 7 | use App::Netdisco::Util::Port ':all'; | ||
| 8 | |||
| 9 | register_worker({ phase => 'check' }, sub { | ||
| 10 | my ($job, $workerconf) = @_; | ||
| 11 | my ($device, $port, $data) = map {$job->$_} qw/device port extra/; | ||
| 12 | |||
| 13 | return Status->error('Vlan failed: unable to interpret device param') | ||
| 14 | unless defined $device; | ||
| 15 | |||
| 16 | return Status->error("Vlan skipped: $device not yet discovered") | ||
| 17 | unless $device->in_storage; | ||
| 18 | |||
| 19 | return Status->error('Missing port (-p).') unless defined $job->port; | ||
| 20 | |||
| 21 | vars->{'port'} = get_port($device, $port) | ||
| 22 | or return Status->error("Unknown port name [$port] on device $device"); | ||
| 23 | |||
| 24 | return Status->error('Missing vlan (-e).') unless defined $job->subaction; | ||
| 25 | |||
| 26 | return Status->error("Permission denied to alter native vlan") | ||
| 27 | unless port_acl_pvid(vars->{'port'}, $device, $job->username); | ||
| 28 | |||
| 29 | return Status->done("Vlan is able to run."); | ||
| 30 | }); | ||
| 31 | |||
| 32 | true; |