allow netdisco-do to do all acton
This commit is contained in:
@@ -30,32 +30,21 @@ my $result = GetOptions(
|
|||||||
'debug|D' => \$debug,
|
'debug|D' => \$debug,
|
||||||
) or exit(1);
|
) or exit(1);
|
||||||
|
|
||||||
# reconfigure logging to use console
|
|
||||||
my $CONFIG = config();
|
my $CONFIG = config();
|
||||||
$CONFIG->{logger} = 'console';
|
$CONFIG->{logger} = 'console';
|
||||||
$CONFIG->{log} = ($debug ? 'debug' : 'info');
|
$CONFIG->{log} = ($debug ? 'debug' : 'info');
|
||||||
|
|
||||||
|
# reconfigure logging to force console output
|
||||||
Dancer::Logger->init('console', $CONFIG);
|
Dancer::Logger->init('console', $CONFIG);
|
||||||
|
|
||||||
# check requested action
|
# get requested action
|
||||||
my $action = shift @ARGV;
|
my $action = shift @ARGV;
|
||||||
my $PERMITTED_ACTIONS = qr/(?:discover|discover_neighbors)/;
|
|
||||||
|
|
||||||
if (!length $action) {
|
if (!length $action) {
|
||||||
error 'error: missing action!';
|
error 'error: missing action!';
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action !~ m/^$PERMITTED_ACTIONS$/) {
|
|
||||||
error sprintf 'error: netdisco-do cannot [%s]', $action;
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!length $device) {
|
|
||||||
error 'error: missing device!';
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
# create worker (placeholder object for the role methods)
|
# create worker (placeholder object for the role methods)
|
||||||
{
|
{
|
||||||
package MyWorker;
|
package MyWorker;
|
||||||
@@ -64,6 +53,12 @@ if (!length $device) {
|
|||||||
}
|
}
|
||||||
my $worker = MyWorker->new();
|
my $worker = MyWorker->new();
|
||||||
|
|
||||||
|
# belt and braces check before we go ahead
|
||||||
|
if (not $worker->can( $action )) {
|
||||||
|
error sprintf 'error: %s is not a valid action', $action;
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
# static configuration for the in-memory local job queue
|
# static configuration for the in-memory local job queue
|
||||||
setting('plugins')->{DBIC}->{daemon} = {
|
setting('plugins')->{DBIC}->{daemon} = {
|
||||||
dsn => 'dbi:SQLite:dbname=:memory:',
|
dsn => 'dbi:SQLite:dbname=:memory:',
|
||||||
@@ -85,12 +80,6 @@ my $job = schema('daemon')->resultset('Admin')->new_result({
|
|||||||
subaction => $extra,
|
subaction => $extra,
|
||||||
});
|
});
|
||||||
|
|
||||||
# belt and braces check before we go ahead
|
|
||||||
if (not $worker->can( $action )) {
|
|
||||||
error sprintf 'error: %s is not a valid action for netdisco-do', $action;
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
# do job
|
# do job
|
||||||
my ($status, $log);
|
my ($status, $log);
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user