2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-08-20 10:10:22 +00:00

Second pass for autogenerating usage

This commit is contained in:
Mark Gurevich
2018-01-23 11:32:44 -05:00
parent 0d29e5d5e1
commit 99cac5264a
4 changed files with 75 additions and 49 deletions

View File

@@ -57,7 +57,7 @@ OpenBMC specific:
\ **rspconfig**\ \ *noderange*\ \ **powersupplyredundancy**\
\ **rspconfig**\ \ *noderange*\ \ **powersupplyredundancy={0|1}**\
\ **rspconfig**\ \ *noderange*\ \ **powersupplyredundancy={disabled|enabled}**\
\ **rspconfig**\ \ *noderange*\ \ **autoreboot**\
@@ -446,19 +446,19 @@ OPTIONS
\ **powerrestorepolicy**\
Display or control BMC powerrestorepolicy attribute setting.
Display or control BMC Power Restore Policy attribute setting.
\ **powersupplyredundancy**\
Display or control BMC powersupplyredundancy attribute setting.
Display or control BMC Power Supply Redundancy attribute setting.
\ **autoreboot**\
Display or control BMC autoreboot attribute setting.
Display or control BMC Auto Reboot attribute setting.

View File

@@ -134,21 +134,28 @@ my %usage = (
"rscan" =>
"Usage: rscan <noderange> [-u][-w][-x|-z] [-V|--verbose]
rscan [-h|--help|-v|--version]",
"rspconfig" =>
"rspconfig" => "",
"rspconfig.common" =>
"Usage:
Common:
rspconfig [-h|--help|-v|--version|-V|--verbose]
BMC/MPA Common:
",
"rspconfig.openbmc" =>
"OpenBMC specific:
rspconfig <noderange> [ipsrc|ip|netmask|gateway|hostname|vlan]
rspconfig <noderange> dump [-l|--list] [-g|--generate] [-c|--clear {<id>|all}] [-d|--download {<id>|all}]
",
"rspconfig.begin" =>
"BMC/MPA Common:
rspconfig <noderange> [snmpdest|alert|community] [-V|--verbose]
rspconfig <noderange> [snmpdest=<dest ip address>|alert=<on|off|en|dis|enable|disable>|community=<string>]
BMC specific:
rspconfig <noderange> [ip|netmask|gateway|backupgateway|garp|vlan]
rspconfig <noderange> [garp=<number of 1/2 second>]
rspconfig <noderange> [userid=<userid> username=<username> password=<password>]
OpenBMC specific:
rspconfig <noderange> [ipsrc|ip|netmask|gateway|hostname|vlan]
rspconfig <noderange> dump [-l|--list] [-g|--generate] [-c|--clear {<id>|all}] [-d|--download {<id>|all}]
iDataplex specific:
",
"rspconfig.end" =>
"iDataplex specific:
rspconfig <noderange> [thermprofile]
rspconfig <noderange> [thermprofile=<two digit number from chassis>]
MPA specific:
@@ -528,6 +535,17 @@ Options:
"Usage:
clonevm noderange [-t createmaster -f | -b basemaster -d | -h]",
);
# Rebuild full command usage from its components
$usage{"rspconfig"} = $usage{"rspconfig.common"} .
$usage{"rspconfig.begin"} .
$usage{"rspconfig.openbmc"} .
" " .
$usage{"rspconfig.end"};
$usage{"rspconfig.openbmc"} = $usage{"rspconfig.common"} .
$usage{"rspconfig.openbmc"};
my $vers = xCAT::Utils->Version();
my %version = (
"rnetboot" => "$vers",

View File

@@ -34,7 +34,7 @@ B<rspconfig> I<noderange> B<powerrestorepolicy={always_on|restore|always_off}>
B<rspconfig> I<noderange> B<powersupplyredundancy>
B<rspconfig> I<noderange> B<powersupplyredundancy={0|1}>
B<rspconfig> I<noderange> B<powersupplyredundancy={disabled|enabled}>
B<rspconfig> I<noderange> B<autoreboot>
@@ -340,15 +340,15 @@ The subnet mask.
=item B<powerrestorepolicy>
Display or control BMC powerrestorepolicy attribute setting.
Display or control BMC Power Restore Policy attribute setting.
=item B<powersupplyredundancy>
Display or control BMC powersupplyredundancy attribute setting.
Display or control BMC Power Supply Redundancy attribute setting.
=item B<autoreboot>
Display or control BMC autoreboot attribute setting.
Display or control BMC Auto Reboot attribute setting.
=item B<dump>

View File

@@ -563,7 +563,13 @@ my %status_info = (
},
);
# Setup configured subcommand. Currently only rspconfig is supported and only for boolean commands.
# Setup configured subcommand.
# Currently only rspconfig is supported and only for boolean commands or attribute settings.
#
# Usage can also be autogenerated for these commands. However, changes to the xCAT::Usage->usage
# need to be made to split a single string into its components. Look at "rspconfig" usage as an
# example.
#
# For example: rspconfig <subcommand>
# rspconfig <subcommand>=0
# rspconfig <subcommand>=1
@@ -587,8 +593,8 @@ my %api_config_info = (
type => "attribute",
subcommand => "powersupplyredundancy",
attr_value => {
enabled => "Enabled",
disabled => "Disabled",
enabled => "Enabled",
},
},
RSPCONFIG_POWERRESTORE_POLICY => {
@@ -727,24 +733,25 @@ sub preprocess_request {
my $extrargs = $request->{arg};
my @exargs = ($request->{arg});
my @requests;
my $usage_string;
$::cwd = $request->{cwd}->[0];
if (ref($extrargs)) {
@exargs = @$extrargs;
}
my $usage_string = xCAT::Usage->parseCommand($command, @exargs);
# Request usage for openbmc sections only
$usage_string = xCAT::Usage->parseCommand($command . ".openbmc", @exargs);
if ($usage_string =~ /cannot be found/) {
# Could not find usage for openbmc section, try getting usage for all sections
$usage_string = xCAT::Usage->parseCommand($command, @exargs);
}
else {
# Usage for openbmc section was extracted, append autogenerated usage for
# configured commands
$usage_string .= &build_config_api_usage($callback, $command);
}
if ($usage_string) {
# Insert config api defined OpenBMC specific usage
my $iDataplex_tag = "iDataplex specific:";
my @usage_block = split($iDataplex_tag, $usage_string);
my $usage_before_iDataplex = @usage_block[0];
$usage_before_iDataplex =~ s/\s+$//; # Get rid of all training blanks
my $usage_after_iDataplex = @usage_block[1];
$usage_string = $usage_before_iDataplex . "\n" .
&build_config_api_usage($callback) . " " .
$iDataplex_tag . $usage_after_iDataplex;
$callback->({ data => [$usage_string] });
$request = {};
return;
@@ -4526,6 +4533,7 @@ sub is_valid_config_api {
Build usage string from the api_config_info
Input:
$callback: callback for message display
$requested_command: command for the usage generation
Output:
returns usage string
@@ -4534,7 +4542,8 @@ sub is_valid_config_api {
#-------------------------------------------------------
sub build_config_api_usage {
my $subcommand = shift;
my $callback = shift;
my $requested_command = shift;
my $command = "";
my $subcommand = "";
my $type = "";
@@ -4542,28 +4551,27 @@ sub build_config_api_usage {
my $attr_values = "";
foreach my $config_subcommand (keys %api_config_info) {
foreach my $config_attribute (keys %{ $api_config_info{$config_subcommand} }) {
if ($config_attribute eq "command") {
$command = $api_config_info{$config_subcommand}{$config_attribute}
}
elsif ($config_attribute eq "subcommand") {
$subcommand = $api_config_info{$config_subcommand}{$config_attribute}
}
elsif ($config_attribute eq "type") {
$type = $api_config_info{$config_subcommand}{$config_attribute}
}
}
$usage_string .= " $command <noderange> $subcommand" . "\n";
$command = "";
$subcommand = "";
$type = "";
$attr_values = "";
if ($api_config_info{$config_subcommand}{command} eq $requested_command) {
$command = $api_config_info{$config_subcommand}{command};
$subcommand = $api_config_info{$config_subcommand}{subcommand};
$type = $api_config_info{$config_subcommand}{type};
if ($type eq "boolean") {
$usage_string .= " $command <noderange> $subcommand={0|1}" . "\n";
}
if ($type eq "attribute") {
foreach my $attribute_value (keys %{ $api_config_info{$config_subcommand}{attr_value} }) {
$attr_values .= $attribute_value . "|"
$usage_string .= " $command <noderange> $subcommand" . "\n";
if ($type eq "boolean") {
$usage_string .= " $command <noderange> $subcommand={0|1}" . "\n";
}
if ($type eq "attribute") {
foreach my $attribute_value (keys %{ $api_config_info{$config_subcommand}{attr_value} }) {
$attr_values .= $attribute_value . "|"
}
chop $attr_values;
$usage_string .= " $command <noderange> $subcommand={" . $attr_values . "}". "\n";
}
chop $attr_values;
$usage_string .= " $command <noderange> $subcommand={" . $attr_values . "}". "\n";
}
}
return $usage_string;