#1124 netdisco-do --force --enqueue -d bigfile.txt does not work

This commit is contained in:
Oliver Gorwits
2023-11-18 09:40:23 +00:00
parent 0ae7c69b5a
commit 6e1753aba8

View File

@@ -104,20 +104,24 @@ unless ($action) {
with 'App::Netdisco::Worker::Runner'; with 'App::Netdisco::Worker::Runner';
} }
sub _test_device { # list of NetAddr::IP instances resolved from the -d params
my @hostlist = ();
sub _test_and_resolve_device {
my $d = shift or return; my $d = shift or return;
$d =~ s/\s//g; $d =~ s/\s//g;
return unless $d;
my $net = NetAddr::IP->new($d); my $net = NetAddr::IP->new($d);
if ($d and (!$net or $net->num == 0 or $net->addr eq '0.0.0.0')) { if (!$net or $net->num == 0 or $net->addr eq '0.0.0.0') {
error sprintf 'unable to understand as host, IP, or prefix: %s', $d; error sprintf 'unable to understand as host, IP, or prefix: %s', $d;
exit 1; exit 1;
} }
return ($d ? $net->hostenum : undef); push @hostlist, $net->hostenum;
return;
} }
my @hostlist = ();
foreach my $device (@$devices) { foreach my $device (@$devices) {
if (-f $device) { if (-f $device) {
my @dlist = read_lines $device; my @dlist = read_lines $device;
@@ -128,11 +132,11 @@ foreach my $device (@$devices) {
} }
foreach my $entry (@dlist) { foreach my $entry (@dlist) {
push(@hostlist, _test_device($entry)) if _test_device($entry); _test_and_resolve_device($entry);
} }
} }
else { else {
push(@hostlist, _test_device($device)) if _test_device($device); _test_and_resolve_device($device);
} }
} }
@@ -148,18 +152,9 @@ if (not $force and scalar @hostlist > 512) {
@hostlist = (undef) if 0 == scalar @hostlist; @hostlist = (undef) if 0 == scalar @hostlist;
foreach my $host (@hostlist) { foreach my $host (@hostlist) {
my $dev = $host
? ((not ($queue_only and $force)) ? get_device($host->addr) : $host->addr)
: undef;
if ($dev and not (blessed $dev and $dev->in_storage) and $action !~ m/^(?:discover|addpseudodevice)/) {
info sprintf "%s: error - Don't know device: %s", $action, $host->addr;
next;
}
# what job are we asked to do?
push @job_specs, { push @job_specs, {
action => $action, action => $action,
device => $dev, device => $host ? $host->addr : undef,
port => $port, port => $port,
subaction => ($extra || (($action eq 'discover') ? 'with-nodes' : undef)), subaction => ($extra || (($action eq 'discover') ? 'with-nodes' : undef)),
username => ($ENV{USER} || 'netdisco-do'), username => ($ENV{USER} || 'netdisco-do'),
@@ -178,7 +173,7 @@ else {
$CONFIG->{$1."_min_age"} = 0 if $job->action =~ m/^(arpnip|macsuck|discover)$/; $CONFIG->{$1."_min_age"} = 0 if $job->action =~ m/^(arpnip|macsuck|discover)$/;
my $actiontext = ( my $actiontext = (
($job->device ? ('['.$job->device->ip.']') : '') . ($job->device ? ('['.$job->device.']') : '') .
($job->action eq 'show' ? ('/'. ($job->subaction || 'interfaces')) : '') ($job->action eq 'show' ? ('/'. ($job->subaction || 'interfaces')) : '')
); );