From d395e8b73bbf787b0eb9f78a78ee427fcbbee2a7 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Tue, 16 Jan 2018 13:25:29 -0500 Subject: [PATCH 1/4] Build usage string based on command definitions --- xCAT-server/lib/xcat/plugins/openbmc.pm | 64 ++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 63c9d8983..6d42b17b7 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -732,6 +732,18 @@ sub preprocess_request { @exargs = @$extrargs; } my $usage_string = xCAT::Usage->parseCommand($command, @exargs); + + # 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) . "\n" . + $iDataplex_tag . $usage_after_iDataplex; + if ($usage_string) { $callback->({ data => [$usage_string] }); $request = {}; @@ -4478,7 +4490,7 @@ sub rflash_upload { =head3 is_valid_config_api - Verify passed in subcomaand is defined in the api_config_info + Verify passed in subcommand is defined in the api_config_info Input: $subcommand: subcommand to verify $callback: callback for message display @@ -4506,4 +4518,54 @@ sub is_valid_config_api { } return -1; } + +#------------------------------------------------------- + +=head3 build_config_api_usage + + Build usage string from the api_config_info + Input: + $callback: callback for message display + + Output: + returns usage string + +=cut + +#------------------------------------------------------- +sub build_config_api_usage { + my $subcommand = shift; + my $command = ""; + my $subcommand = ""; + my $type = ""; + my $usage_string = ""; + 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"; + + 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"; + } + } + return $usage_string; +} 1; From 8788b13235fdb88bdd70833392554f7a7b735baa Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Tue, 16 Jan 2018 13:52:47 -0500 Subject: [PATCH 2/4] Man page changes for OpenBMC rspconfig --- xCAT-client/pods/man1/rspconfig.1.pod | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/xCAT-client/pods/man1/rspconfig.1.pod b/xCAT-client/pods/man1/rspconfig.1.pod index 9088188f7..e94aefaa8 100644 --- a/xCAT-client/pods/man1/rspconfig.1.pod +++ b/xCAT-client/pods/man1/rspconfig.1.pod @@ -28,6 +28,18 @@ B I {B|B|B|B|B|B I B [B<-l>|B<--list>] [B<-g>|B<--generate>] [B<-c>|B<--clear> {I | B}] [B<-d>|B<--download> {I | B}] +B I B + +B I B + +B I B + +B I B + +B I B + +B I B + =head2 MPA specific: B I {B|B|B|B|B|B|B|B|B} @@ -326,6 +338,18 @@ Select whether each memory bank should be enabled or disabled. State changes tak The subnet mask. +=item B + +Display or control BMC powerrestorepolicy attribute setting. + +=item B + +Display or control BMC powersupplyredundancy attribute setting. + +=item B + +Display or control BMC autoreboot attribute setting. + =item B Manage OpenBMC system dumps. If no sub-option is provided, will generate, wait, and download the dump. From 0d29e5d5e1e65259f4f8488690eef205bb77f347 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Tue, 16 Jan 2018 14:46:36 -0500 Subject: [PATCH 3/4] Move code block for usage string processing --- .../references/man1/rspconfig.1.rst | 30 +++++++++++++++++++ xCAT-server/lib/xcat/plugins/openbmc.pm | 22 +++++++------- 2 files changed, 41 insertions(+), 11 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 c9278d2f7..916f0dae8 100644 --- a/docs/source/guides/admin-guides/references/man1/rspconfig.1.rst +++ b/docs/source/guides/admin-guides/references/man1/rspconfig.1.rst @@ -51,6 +51,18 @@ OpenBMC specific: \ **rspconfig**\ \ *noderange*\ \ **dump**\ [\ **-l | -**\ **-list**\ ] [\ **-g | -**\ **-generate**\ ] [\ **-c | -**\ **-clear**\ {\ *id*\ | \ **all**\ }] [\ **-d | -**\ **-download**\ {\ *id*\ | \ **all**\ }] +\ **rspconfig**\ \ *noderange*\ \ **powerrestorepolicy**\ + +\ **rspconfig**\ \ *noderange*\ \ **powerrestorepolicy={always_on|restore|always_off}**\ + +\ **rspconfig**\ \ *noderange*\ \ **powersupplyredundancy**\ + +\ **rspconfig**\ \ *noderange*\ \ **powersupplyredundancy={0|1}**\ + +\ **rspconfig**\ \ *noderange*\ \ **autoreboot**\ + +\ **rspconfig**\ \ *noderange*\ \ **autoreboot={0|1}**\ + MPA specific: ============= @@ -432,6 +444,24 @@ OPTIONS +\ **powerrestorepolicy**\ + + Display or control BMC powerrestorepolicy attribute setting. + + + +\ **powersupplyredundancy**\ + + Display or control BMC powersupplyredundancy attribute setting. + + + +\ **autoreboot**\ + + Display or control BMC autoreboot attribute setting. + + + \ **dump**\ Manage OpenBMC system dumps. If no sub-option is provided, will generate, wait, and download the dump. diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 6d42b17b7..a979fc45b 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -733,18 +733,18 @@ sub preprocess_request { } my $usage_string = xCAT::Usage->parseCommand($command, @exargs); - # 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) . "\n" . - $iDataplex_tag . $usage_after_iDataplex; - 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; From 99cac5264a0b123cfa22ba094c094a5d8b4bc102 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Tue, 23 Jan 2018 11:32:44 -0500 Subject: [PATCH 4/4] 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;