pass action host list filtering to Util
This commit is contained in:
@@ -2,9 +2,10 @@ package App::Netdisco::Backend::Role::Scheduler;
|
|||||||
|
|
||||||
use Dancer qw/:moose :syntax :script/;
|
use Dancer qw/:moose :syntax :script/;
|
||||||
|
|
||||||
use NetAddr::IP;
|
|
||||||
use Algorithm::Cron;
|
use Algorithm::Cron;
|
||||||
use App::Netdisco::Util::MCE;
|
use App::Netdisco::Util::MCE;
|
||||||
|
use App::Netdisco::Util::Device
|
||||||
|
qw/device_ips_matching device_ips_not_matching/;
|
||||||
use App::Netdisco::JobQueue qw/jq_insert/;
|
use App::Netdisco::JobQueue qw/jq_insert/;
|
||||||
|
|
||||||
use Role::Tiny;
|
use Role::Tiny;
|
||||||
@@ -68,14 +69,12 @@ sub worker_body {
|
|||||||
$win_start, $win_end, $sched->{when}->next_time($win_start);
|
$win_start, $win_end, $sched->{when}->next_time($win_start);
|
||||||
next unless $sched->{when}->next_time($win_start) <= $win_end;
|
next unless $sched->{when}->next_time($win_start) <= $win_end;
|
||||||
|
|
||||||
my $net = NetAddr::IP->new($sched->{device});
|
my @hostlist = device_ips_not_matching($sched->{no},
|
||||||
next if ($sched->{device}
|
device_ips_matching($sched->{device} || $sched->{only}));
|
||||||
and (!$net or $net->num == 0 or $net->addr eq '0.0.0.0'));
|
|
||||||
|
# TODO work for actions without a host/device
|
||||||
|
|
||||||
my @hostlist = map { (ref $_) ? $_->addr : undef }
|
|
||||||
(defined $sched->{device} ? ($net->hostenum) : (undef));
|
|
||||||
my @job_specs = ();
|
my @job_specs = ();
|
||||||
|
|
||||||
foreach my $host (@hostlist) {
|
foreach my $host (@hostlist) {
|
||||||
push @job_specs, {
|
push @job_specs, {
|
||||||
action => $real_action,
|
action => $real_action,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ our @EXPORT_OK = qw/
|
|||||||
delete_device
|
delete_device
|
||||||
renumber_device
|
renumber_device
|
||||||
match_to_setting
|
match_to_setting
|
||||||
|
device_ips_matching device_ips_not_matching
|
||||||
is_discoverable is_discoverable_now
|
is_discoverable is_discoverable_now
|
||||||
is_arpnipable is_arpnipable_now
|
is_arpnipable is_arpnipable_now
|
||||||
is_macsuckable is_macsuckable_now
|
is_macsuckable is_macsuckable_now
|
||||||
@@ -144,6 +145,23 @@ sub match_to_setting {
|
|||||||
@{setting($setting_name) || []});
|
@{setting($setting_name) || []});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=head2 device_ips_matching( $setting_name | $acl_entry | \@acl, @IPs? )
|
||||||
|
|
||||||
|
Returns a list of Device IPs that match the given ACL. If the ACL is
|
||||||
|
missing then no device IPs will be returned. If the C< @IPs > list is
|
||||||
|
provided then it will be used otherwise the current devices in Netdisco's
|
||||||
|
database will be used as the source list.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub device_ips_matching {
|
||||||
|
my ($acl, @ips) = @_;
|
||||||
|
return () unless $acl;
|
||||||
|
my $config = (exists config->{"$acl"} ? setting($acl) : $acl);
|
||||||
|
my @startlist = (scalar @ips ? @ips :
|
||||||
|
schema('netdisco')->resultset('Device')->get_column('ip')->all);
|
||||||
|
}
|
||||||
|
|
||||||
sub _bail_msg { debug $_[0]; return 0; }
|
sub _bail_msg { debug $_[0]; return 0; }
|
||||||
|
|
||||||
=head2 is_discoverable( $ip, [$device_type, \@device_capabilities]? )
|
=head2 is_discoverable( $ip, [$device_type, \@device_capabilities]? )
|
||||||
|
|||||||
Reference in New Issue
Block a user