-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Discover.pm
30 lines (21 loc) · 935 Bytes
/
Discover.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package App::Netdisco::Worker::Plugin::Discover;
use Dancer ':syntax';
use App::Netdisco::Worker::Plugin;
use aliased 'App::Netdisco::Worker::Status';
use App::Netdisco::Util::Device 'is_discoverable_now';
register_worker({ phase => 'check' }, sub {
my ($job, $workerconf) = @_;
my $device = $job->device;
return Status->error('discover failed: unable to interpret device param')
unless defined $device;
return Status->error("discover failed: no device param (need -d ?)")
if $device->ip eq '0.0.0.0';
# runner has already called get_device to promote $job->device
return $job->cancel("fresh discover cancelled: $device already known")
if $device->in_storage
and ($job->subaction eq 'with-nodes' and not $job->username);
return Status->info("discover skipped: $device is not discoverable")
unless is_discoverable_now($device);
return Status->done('Discover is able to run.');
});
true;