From 99cac5264a0b123cfa22ba094c094a5d8b4bc102 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Tue, 23 Jan 2018 11:32:44 -0500 Subject: [PATCH] Second pass for autogenerating usage --- .../references/man1/rspconfig.1.rst | 8 +- perl-xCAT/xCAT/Usage.pm | 30 +++++-- xCAT-client/pods/man1/rspconfig.1.pod | 8 +- xCAT-server/lib/xcat/plugins/openbmc.pm | 78 ++++++++++--------- 4 files changed, 75 insertions(+), 49 deletions(-) diff --git a/docs/source/guides/admin-guides/references/man1/rspconfig.1.rst b/docs/source/guides/admin-guides/references/man1/rspconfig.1.rst index 916f0dae8..f8d9e8b85 100644 --- a/docs/source/guides/admin-guides/references/man1/rspconfig.1.rst +++ b/docs/source/guides/admin-guides/references/man1/rspconfig.1.rst @@ -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. diff --git a/perl-xCAT/xCAT/Usage.pm b/perl-xCAT/xCAT/Usage.pm index d28130199..f5b8eaaff 100755 --- a/perl-xCAT/xCAT/Usage.pm +++ b/perl-xCAT/xCAT/Usage.pm @@ -134,21 +134,28 @@ my %usage = ( "rscan" => "Usage: rscan [-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 [ipsrc|ip|netmask|gateway|hostname|vlan] + rspconfig dump [-l|--list] [-g|--generate] [-c|--clear {|all}] [-d|--download {|all}] +", + "rspconfig.begin" => + "BMC/MPA Common: rspconfig [snmpdest|alert|community] [-V|--verbose] rspconfig [snmpdest=|alert=|community=] BMC specific: rspconfig [ip|netmask|gateway|backupgateway|garp|vlan] rspconfig [garp=] rspconfig [userid= username= password=] - OpenBMC specific: - rspconfig [ipsrc|ip|netmask|gateway|hostname|vlan] - rspconfig dump [-l|--list] [-g|--generate] [-c|--clear {|all}] [-d|--download {|all}] - iDataplex specific: + ", + "rspconfig.end" => + "iDataplex specific: rspconfig [thermprofile] rspconfig [thermprofile=] 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", diff --git a/xCAT-client/pods/man1/rspconfig.1.pod b/xCAT-client/pods/man1/rspconfig.1.pod index e94aefaa8..2f72806f2 100644 --- a/xCAT-client/pods/man1/rspconfig.1.pod +++ b/xCAT-client/pods/man1/rspconfig.1.pod @@ -34,7 +34,7 @@ B I B B I B -B I B +B I B B I B @@ -340,15 +340,15 @@ The subnet mask. =item B -Display or control BMC powerrestorepolicy attribute setting. +Display or control BMC Power Restore Policy attribute setting. =item B -Display or control BMC powersupplyredundancy attribute setting. +Display or control BMC Power Supply Redundancy attribute setting. =item B -Display or control BMC autoreboot attribute setting. +Display or control BMC Auto Reboot attribute setting. =item B diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index a979fc45b..746de86a7 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -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 # rspconfig =0 # rspconfig =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 $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 $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 $subcommand" . "\n"; + + if ($type eq "boolean") { + $usage_string .= " $command $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 $subcommand={" . $attr_values . "}". "\n"; } - chop $attr_values; - $usage_string .= " $command $subcommand={" . $attr_values . "}". "\n"; } } return $usage_string;