move remaining interactive actions to be plugins
This commit is contained in:
38
lib/App/Netdisco/Worker/Plugin/Location.pm
Normal file
38
lib/App/Netdisco/Worker/Plugin/Location.pm
Normal file
@@ -0,0 +1,38 @@
|
||||
package App::Netdisco::Worker::Plugin::Location;
|
||||
|
||||
use Dancer ':syntax';
|
||||
use App::Netdisco::Worker::Plugin;
|
||||
use aliased 'App::Netdisco::Worker::Status';
|
||||
|
||||
use App::Netdisco::Transport::SNMP;
|
||||
|
||||
register_worker({ stage => 'check' }, sub {
|
||||
my ($job, $workerconf) = @_;
|
||||
my ($device, $data) = map {$job->$_} qw/device extra/;
|
||||
return Status->error('Missing device (-d).') if !defined $device;
|
||||
|
||||
# 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 location");
|
||||
|
||||
my $rv = $snmp->set_location($data);
|
||||
|
||||
if (!defined $rv) {
|
||||
return Status->error(
|
||||
"failed to set location on $device: ". ($snmp->error || ''));
|
||||
}
|
||||
|
||||
# confirm the set happened
|
||||
$snmp->clear_cache;
|
||||
my $new_data = ($snmp->location || '');
|
||||
if ($new_data ne $data) {
|
||||
return Status->error("verify of location failed on $device: $new_data");
|
||||
}
|
||||
|
||||
# update netdisco DB
|
||||
$device->update({location => $data});
|
||||
|
||||
return Status->done("Updated location on $device to [$data]");
|
||||
});
|
||||
|
||||
true;
|
||||
Reference in New Issue
Block a user