From 02569b0e923ff247836d908d7bcf76149e54328c Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 9 Jun 2019 22:15:10 +0100 Subject: [PATCH] pass action host list filtering to Util --- lib/App/Netdisco/Backend/Role/Scheduler.pm | 13 ++++++------- lib/App/Netdisco/Util/Device.pm | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/App/Netdisco/Backend/Role/Scheduler.pm b/lib/App/Netdisco/Backend/Role/Scheduler.pm index fb8154ae..52fc8160 100644 --- a/lib/App/Netdisco/Backend/Role/Scheduler.pm +++ b/lib/App/Netdisco/Backend/Role/Scheduler.pm @@ -2,9 +2,10 @@ package App::Netdisco::Backend::Role::Scheduler; use Dancer qw/:moose :syntax :script/; -use NetAddr::IP; use Algorithm::Cron; 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 Role::Tiny; @@ -68,14 +69,12 @@ sub worker_body { $win_start, $win_end, $sched->{when}->next_time($win_start); next unless $sched->{when}->next_time($win_start) <= $win_end; - my $net = NetAddr::IP->new($sched->{device}); - next if ($sched->{device} - and (!$net or $net->num == 0 or $net->addr eq '0.0.0.0')); + my @hostlist = device_ips_not_matching($sched->{no}, + device_ips_matching($sched->{device} || $sched->{only})); + +# TODO work for actions without a host/device - my @hostlist = map { (ref $_) ? $_->addr : undef } - (defined $sched->{device} ? ($net->hostenum) : (undef)); my @job_specs = (); - foreach my $host (@hostlist) { push @job_specs, { action => $real_action, diff --git a/lib/App/Netdisco/Util/Device.pm b/lib/App/Netdisco/Util/Device.pm index e0fbd211..c141408f 100644 --- a/lib/App/Netdisco/Util/Device.pm +++ b/lib/App/Netdisco/Util/Device.pm @@ -11,6 +11,7 @@ our @EXPORT_OK = qw/ delete_device renumber_device match_to_setting + device_ips_matching device_ips_not_matching is_discoverable is_discoverable_now is_arpnipable is_arpnipable_now is_macsuckable is_macsuckable_now @@ -144,6 +145,23 @@ sub match_to_setting { @{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; } =head2 is_discoverable( $ip, [$device_type, \@device_capabilities]? )