* Updated Get->switches() to take 'list' and 'man' parameters. With list, the passed in switches can be checked to ensure they're valid. With 'man', if set to the name of a man page (usually $THIS_FILE) will be displayed if --help, -h or -? are used.

* Disabled striker-parse-oui until it can be reworked to store the the OUI data in a flat file instead of in the database.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 2 years ago
parent cd220e97dc
commit be612ff878
  1. 128
      Anvil/Tools/Get.pm
  2. 24
      man/anvil-daemon.8
  3. 3
      notes
  4. 14
      tools/anvil-daemon
  5. 11
      tools/striker-parse-oui

@ -2145,8 +2145,26 @@ Switches in the form 'C<< -x foo >>', 'C<< --x foo >>', 'C<< -x=foo >>' and 'C<<
The switches 'C<< -v >>', 'C<< -vv >>', 'C<< -vvv >>' and 'C<< -vvvv >>' will cause the active log level to automatically change to 1, 2, 3 or 4 respectively. Passing 'C<< -V >>' will set the log level to '0'.
The switch 'C<< --log-secure >>' will enable logging of "secure" data, like passwords.
Anything after 'C<< -- >>' is treated as a raw string and is not processed.
The switches C<< -h >>, C<< -? >> and C<< --help >> will set the C<< help >> switch to C<< #!set!# >> so that calling program knows to display it's help, if available.
Parameters
=head3 list (optional)
If set to an anonymous array, only switches in the list will be allowed. If a switch is passed that doesn't match an entry in this list, an error message is printed to STDOUT and C<< #!error!# >> is returned.. If this is set but it is not an array reference, C<< #!error!# >> is returned.
B<< NOTE >>: The always-supported switches described above are allowed regardless of the contents of the C<< list >> parameter.
=head3 man (optional)
This is the name of the man page for the calling program. If C<< --help >> and C<< man >> are set, the man page will be displayed to the user, and then exit when the program returns.
B<< NOTE >>: The always-supported switches described above are allowed regardless of the contents of the C<< list >> parameter.
=cut
### TODO: This doesn't handle quoted values, System->parse_arguments() does. Switch to using it. Note that
### we'll still need to process '--raw' here (or make it work there)
@ -2157,13 +2175,39 @@ sub switches
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $list = defined $parameter->{list} ? $parameter->{list} : "";
my $man = defined $parameter->{man} ? $parameter->{man} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
list => $list,
man => $man,
}});
if ($list)
{
if (ref($list) ne "ARRAY")
{
# No logging here.
return('#!error!#');
}
# Set all switches to be empty strings
foreach my $switch (@{$list})
{
$anvil->data->{switches}{$switch} = "";
}
}
my $last_argument = "";
foreach my $argument (@ARGV)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { argument => $argument }});
if ($last_argument eq "raw")
{
# Don't process anything.
$anvil->data->{switches}{raw} .= " $argument";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"switches::raw" => $anvil->data->{switches}{raw},
}});
}
elsif ($argument =~ /^-/)
{
@ -2172,33 +2216,53 @@ sub switches
{
$last_argument = "raw";
$anvil->data->{switches}{raw} = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
last_argument => $last_argument,
"switches::raw" => $anvil->data->{switches}{raw},
}});
}
else
{
($last_argument) = ($argument =~ /^-{1,2}(.*)/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { last_argument => $last_argument }});
if ($last_argument =~ /=/)
{
# Break up the variable/value.
($last_argument, my $value) = (split /=/, $last_argument, 2);
($last_argument, my $value) = (split /=/, $last_argument, 2);
$anvil->data->{switches}{$last_argument} = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
value => $value,
"switches::${last_argument}" => $anvil->data->{switches}{$last_argument},
}});
}
else
{
$anvil->data->{switches}{$last_argument} = "#!SET!#";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"switches::${last_argument}" => $anvil->data->{switches}{$last_argument},
}});
}
}
}
else
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { last_argument => $last_argument }});
if ($last_argument)
{
$anvil->data->{switches}{$last_argument} = $argument;
$last_argument = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
last_argument => $last_argument,
"switches::${last_argument}" => $anvil->data->{switches}{$last_argument},
}});
}
else
{
# Got a value without an argument, so just record it as '#!SET!#'.
$anvil->data->{switches}{$argument} = "#!SET!#";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"switches::${last_argument}" => $anvil->data->{switches}{$last_argument},
}});
}
}
}
@ -2207,11 +2271,73 @@ sub switches
if ($anvil->data->{switches}{raw})
{
$anvil->data->{switches}{raw} =~ s/^ //;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"switches::raw" => $anvil->data->{switches}{raw},
}});
}
# Adjust the log level if requested.
$anvil->Log->_adjust_log_level();
# Make sure 'help' is set if 'h' or '?' is set.
if (($anvil->data->{switches}{'?'}) or ($anvil->data->{switches}{h}))
{
$anvil->data->{switches}{help} = "#!SET!#";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"switches::help" => $anvil->data->{switches}{help},
}});
}
# Check for any switches not in the list, if used.
if ($list)
{
my $problem = 0;
foreach my $set_switch (sort {$a cmp $b} keys %{$anvil->data->{switches}})
{
next if $set_switch eq "?";
next if $set_switch eq "h";
next if $set_switch eq "help";
next if $set_switch eq "raw";
next if $set_switch eq "v";
next if $set_switch eq "vv";
next if $set_switch eq "vvv";
next if $set_switch eq "vvvv";
next if $set_switch eq "log-secure";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { set_switch => $set_switch }});
my $found = 0;
foreach my $allowed_switch (@{$list})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { allowed_switch => $allowed_switch }});
if ($allowed_switch eq $set_switch)
{
$found = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { found => $found }});
last;
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { found => $found }});
if (not $found)
{
print "Switch '--".$set_switch." not recognized.\n";
$problem = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { problem => $problem }});
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { problem => $problem }});
if ($problem)
{
return('#!error!#');
}
}
if (($anvil->data->{switches}{help}) && ($man))
{
# Show the man page and then exit.
system($anvil->data->{path}{exe}{man}." ".$man);
$anvil->nice_exit({exit_code => 0});
}
return(0);
}

@ -1,8 +1,24 @@
.TH anvil-daemon
.\" Manpage for the Anvil! daemon.
.\" Contact mkelly@alteeve.com to report issues, concerns or suggestions.
.TH anvil-daemon "8" "July 29 2022" "Anvil! Intelligent Availability™ Platform"
.SH NAME
anvil-daemon - Main systemd daemon for the Anvil! IA platform. Provides all job management, monitoring and Striker back-end functions.
anvil-daemon \- Main systemd daemon for the M3 Anvil! IA cluster. Provides all job management, monitoring and Striker back-end functions.
.SH SYNOPSIS
.B anvil-daemon
\fI\,<command> \/\fR[\fI\,options\/\fR]
.SH DESCRIPTION
.B anvil-daemon
Main daemon for the M3 Anvil! Intelligent Availability\*(Tm platform. Usually managed via
anvil-daemon \- Main systemd daemon that can be run manually for testing and debug reasons. No switches needed for normal operation by systemd.
.SH OPTIONS
.TP
\-?, \-h, \fB\-\-help\fR
Show a prompt to read this man page.
.TP
\fB\-\-refresh-json\fR (derecated)
Short hand for '--run-once', '--main-loop-only' and '--no-start'. Used to be use to refresh the JSON file used by striker's web interface to know hardware states.
\fB\-\-refresh-json\fR (derecated)
Short hand for '--run-once', '--main-loop-only' and '--no-start'. Used to be use to refresh the JSON file used by striker's web interface to know hardware states.
.SH AUTHOR
Written by Madison Kelly, Alteeve staff and the Anvil! project contributors.
.SH "REPORTING BUGS"
Report bugs to users@clusterlabs.org

@ -6,6 +6,9 @@ dnf -y update && dnf -y install https://www.alteeve.com/an-repo/m3/anvil-release
dnf -y update && dnf -y install https://www.alteeve.com/an-repo/m3/anvil-release-latest.noarch.rpm && alteeve-repo-setup -y && dnf -y install anvil-node --allowerasing
dnf -y update && dnf -y install https://www.alteeve.com/an-repo/m3/anvil-release-latest.noarch.rpm && alteeve-repo-setup -y && dnf -y install anvil-dr --allowerasing
### Get OUI out of the fucking database.
### Currently set default zone;
# Doesn't seem to matter - /etc/firewalld/firewalld.conf:6:DefaultZone=public

@ -139,13 +139,8 @@ if (not $anvil->data->{sys}{database}{connections})
}
# Read switches
$anvil->data->{switches}{'refresh-json'} = "";
$anvil->data->{switches}{'run-once'} = 0;
$anvil->data->{switches}{'main-loop-only'} = 0;
$anvil->data->{switches}{'no-start'} = 0;
$anvil->data->{switches}{'purge'} = 0;
$anvil->data->{switches}{'startup-only'} = 0;
$anvil->Get->switches;
$anvil->Get->switches({list => ["?", "help", "h", "refresh-json", "run-once", "main-loop-only", "no-start", "purge", "startup-only"], man => $THIS_FILE});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => $anvil->data->{switches}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0115", variables => { program => $THIS_FILE }});
@ -154,6 +149,11 @@ if ($anvil->data->{switches}{'refresh-json'})
$anvil->data->{switches}{'run-once'} = 1;
$anvil->data->{switches}{'main-loop-only'} = 1;
$anvil->data->{switches}{'no-start'} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"switches::run-once" => $anvil->data->{switches}{'run-once'},
"switches::main-loop-only" => $anvil->data->{switches}{'main-loop-only'},
"switches::no-start" => $anvil->data->{switches}{'no-start'},
}});
}
# This is used to track initial checkes / repairs of network issues.

@ -3,6 +3,9 @@
# This periodically reads in http://standards-oui.ieee.org/oui/oui.txt, if possible, and parses it to update/
# populate the oui database table.
#
# NOTE:
# - Disabled for now. Move the OUI data to a flat file and change lookup to read the file. Too big for the DB / resync.
#
# TODO:
#
@ -47,6 +50,14 @@ $anvil->data->{progress} = 1;
check_if_time($anvil);
### NOTE: Disabled
print $anvil->Words->string({key => "message_0291"})."\n";
update_progress($anvil, 100, "message_0291");
$anvil->nice_exit({exit_code => 0});
my $oui_file = $anvil->Get->users_home({debug => 3})."/oui.txt";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { oui_file => $oui_file }});

Loading…
Cancel
Save