#1067 add --force for enqueue of more than 512 jobs

This commit is contained in:
Oliver Gorwits
2023-07-12 13:48:22 +01:00
parent 91409d1bb0
commit bd61c0c2bd

View File

@@ -49,7 +49,7 @@ use App::Netdisco::Util::Device 'get_device';
use Getopt::Long; use Getopt::Long;
Getopt::Long::Configure ("bundling"); Getopt::Long::Configure ("bundling");
my ($port, $extra, $debug, $quiet, $queue_only, $rollback); my ($port, $extra, $debug, $quiet, $queue_only, $force, $rollback);
my ($devices, $infotrace, $snmptrace, $sqltrace) = ([], 0, 0, 0); my ($devices, $infotrace, $snmptrace, $sqltrace) = ([], 0, 0, 0);
my $result = GetOptions( my $result = GetOptions(
@@ -58,6 +58,7 @@ my $result = GetOptions(
'extra|e=s' => \$extra, 'extra|e=s' => \$extra,
'debug|D' => \$debug, 'debug|D' => \$debug,
'enqueue' => \$queue_only, 'enqueue' => \$queue_only,
'force' => \$force,
'quiet' => \$quiet, 'quiet' => \$quiet,
'rollback|R' => \$rollback, 'rollback|R' => \$rollback,
'infotrace|I+' => \$infotrace, 'infotrace|I+' => \$infotrace,
@@ -114,7 +115,7 @@ foreach my $device (@$devices) {
my @job_specs = (); my @job_specs = ();
my $exitstatus = 0; my $exitstatus = 0;
if (scalar @hostlist > 512) { if (not $force and scalar @hostlist > 512) {
info sprintf '%s: aborted - unwise to attempt %s jobs at once', $action, (scalar @hostlist); info sprintf '%s: aborted - unwise to attempt %s jobs at once', $action, (scalar @hostlist);
exit 1; exit 1;
} }
@@ -123,7 +124,9 @@ if (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 ? get_device($host->addr) : undef; 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)/) { 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; info sprintf "%s: error - Don't know device: %s", $action, $host->addr;
next; next;