From d82e14b56656482279d58e38295a9900e82ba056 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Thu, 28 Apr 2016 00:18:56 -0400 Subject: [PATCH] Change the usage to contain the short options for simplicity - Fix the behavior so we obtain the default user/pass from the passwd table - overwrite the default using the command line options - only the --check requires the user and pass to be passed in - Do not display anything or write if the user/pass is incorrect, ERROR out --- .../references/man1/bmcdiscover.1.rst | 10 +-- xCAT-client/pods/man1/bmcdiscover.1.pod | 10 +-- xCAT-server/lib/xcat/plugins/bmcdiscover.pm | 81 ++++++++++--------- 3 files changed, 55 insertions(+), 46 deletions(-) diff --git a/docs/source/guides/admin-guides/references/man1/bmcdiscover.1.rst b/docs/source/guides/admin-guides/references/man1/bmcdiscover.1.rst index 82a4f1330..25cb6d2fe 100644 --- a/docs/source/guides/admin-guides/references/man1/bmcdiscover.1.rst +++ b/docs/source/guides/admin-guides/references/man1/bmcdiscover.1.rst @@ -23,11 +23,11 @@ SYNOPSIS \ **bmcdiscover**\ [\ **-v | -**\ **-version**\ ] -\ **bmcdiscover**\ [\ **-s**\ \ *scan_method*\ ] \ **-**\ **-range**\ \ *ip_ranges*\ [{\ **-u | -**\ **-bmcuser**\ } \ *bmc_username*\ {\ **-p | -**\ **-bmcpasswd**\ }] [\ **-z**\ ] [\ **-w**\ ] [\ **-t**\ ] +\ **bmcdiscover**\ [\ **-s**\ \ *scan_method*\ ] [\ **-u**\ \ *bmc_user*\ ] [\ **-p**\ \ *bmc_passwd*\ ] [\ **-z**\ ] [\ **-w**\ ] [\ **-t**\ ] \ **-**\ **-range**\ \ *ip_ranges*\ -\ **bmcdiscover**\ {\ **-i | -**\ **-bmcip**\ } \ *bmc_ip*\ {\ **-u | -**\ **-bmcuser**\ } \ *bmc_username*\ {\ **-p | -**\ **-bmcpasswd**\ } \ *bmc_password*\ \ **-**\ **-check**\ +\ **bmcdiscover**\ \ **-u**\ \ *bmc_user*\ \ **-p**\ \ *bmc_passwd*\ \ **-i**\ \ *bmc_ip*\ \ **-**\ **-check**\ -\ **bmcdiscover**\ {\ **-i | -**\ **-bmcip**\ } \ *bmc_ip*\ {\ **-u | -**\ **-bmcuser**\ } \ *bmc_username*\ {\ **-p | -**\ **-bmcpasswd**\ } \ *bmc_password*\ \ **-**\ **-ipsource**\ +\ **bmcdiscover**\ [\ **-u**\ \ *bmc_user*\ ] [\ **-p**\ \ *bmc_passwd*\ ] \ **-i**\ \ *bmc_ip*\ \ **-**\ **-ipsource**\ *********** @@ -100,13 +100,13 @@ OPTIONS \ **-c|-**\ **-check**\ - Check + Check BMC administrator User/Password. \ **-**\ **-ipsource**\ - BMC IP source + Display the BMC IP configuration. diff --git a/xCAT-client/pods/man1/bmcdiscover.1.pod b/xCAT-client/pods/man1/bmcdiscover.1.pod index d49f3dfcf..ad0f3ed55 100644 --- a/xCAT-client/pods/man1/bmcdiscover.1.pod +++ b/xCAT-client/pods/man1/bmcdiscover.1.pod @@ -8,11 +8,11 @@ B [B<-?>|B<-h>|B<--help>] B [B<-v>|B<--version>] -B [B<-s> I] B<--range> I [{B<-u>|B<--bmcuser>} I {B<-p>|B<--bmcpasswd>}] [B<-z>] [B<-w>] [B<-t>] +B [B<-s> I] [B<-u> I] [B<-p> I] [B<-z>] [B<-w>] [B<-t>] B<--range> I -B {B<-i>|B<--bmcip>} I {B<-u>|B<--bmcuser>} I {B<-p>|B<--bmcpasswd>} I B<--check> +B B<-u> I B<-p> I B<-i> I B<--check> -B {B<-i>|B<--bmcip>} I {B<-u>|B<--bmcuser>} I {B<-p>|B<--bmcpasswd>} I B<--ipsource> +B [B<-u> I] [B<-p> I] B<-i> I B<--ipsource> =head1 DESCRIPTION @@ -63,11 +63,11 @@ BMC user password. =item B<-c|--check> -Check +Check BMC administrator User/Password. =item B<--ipsource> -BMC IP source +Display the BMC IP configuration. =item B<-h|--help> diff --git a/xCAT-server/lib/xcat/plugins/bmcdiscover.pm b/xCAT-server/lib/xcat/plugins/bmcdiscover.pm index bccabe675..5b96a7a10 100644 --- a/xCAT-server/lib/xcat/plugins/bmcdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/bmcdiscover.pm @@ -113,9 +113,13 @@ sub bmcdiscovery_usage { push @{ $rsp->{data} }, "Usage:"; push @{ $rsp->{data} }, "\tbmcdiscover [-?|-h|--help]"; push @{ $rsp->{data} }, "\tbmcdiscover [-v|--version]"; - push @{ $rsp->{data} }, "\tbmcdiscover [-s scan_method] --range ip_range [-z] [-w] [-t]"; - push @{ $rsp->{data} }, "\tbmcdiscover {-i|--bmcip} bmc_ip {-u|--bmcuser} bmc_user {-p|--bmcpasswd} bmc_password --check"; - push @{ $rsp->{data} }, "\tbmcdiscover {-i|--bmcip} bmc_ip {-u|--bmcuser} bmc_user {-p|--bmcpasswd} bmc_password --ipsource"; + push @{ $rsp->{data} }, "\tbmcdiscover [-s scan_method] [-u bmc_user] [-p bmc_passwd] [-z] [-w] [-t] --range ip_range\n"; + + push @{ $rsp->{data} }, "\tCheck BMC administrator User/Password:\n"; + push @{ $rsp->{data} }, "\t\tbmcdiscover -u bmc_user -p bmc_password -i bmc_ip --check\n"; + + push @{ $rsp->{data} }, "\tDisplay the BMC IP configuration:\n"; + push @{ $rsp->{data} }, "\t\tbmcdiscover [-u bmc_user] [-p bmc_passwd] -i bmc_ip --ipsource"; xCAT::MsgUtils->message( "I", $rsp, $::CALLBACK ); return 0; @@ -197,6 +201,18 @@ sub bmcdiscovery_processargs { return 1; } + # + # Get the default bmc account from passwd table + # + ($bmc_user, $bmc_pass) = bmcaccount_from_passwd(); + # overwrite the default user/pass with what is passed in + if ($::opt_P) { + $bmc_pass = $::opt_P; + if ($::opt_U) { + $bmc_user = $::opt_U; + } + } + ######################################### # Option -s -r should be together ###################################### @@ -220,15 +236,6 @@ sub bmcdiscovery_processargs { xCAT::MsgUtils->message( "E", $rsp, $::CALLBACK ); return 1; } - ($bmc_user, $bmc_pass) = bmcaccount_from_passwd(); - if ($::opt_P) { - $bmc_pass = $::opt_P; - if (!$::opt_U) { - $bmc_user = ''; - } else { - $bmc_user = $::opt_U; - } - } scan_process($::opt_M,$::opt_R,$::opt_Z,$::opt_W,$request_command); return 0; } @@ -241,19 +248,20 @@ sub bmcdiscovery_processargs { return 2; } - #################################################### - # --check option, requires -i and -p to be specified - #################################################### + ######################################################### + # --check option, requires -i, -u, and -p to be specified + ######################################################### if ( defined($::opt_C) ) { - if ( defined($::opt_P) && defined($::opt_I) ) { - my $option_u = defined $::opt_U ? $::opt_U : "none"; - my $res=check_auth_process($::opt_I,$option_u,$::opt_P); + if ( defined($::opt_P) && defined($::opt_U) && defined($::opt_I) ) { + my $res=check_auth_process($::opt_I,$::opt_U,$::opt_P); return $res; } else { my $msg = ""; if (!defined($::opt_I)) { $msg = "The check option requires a BMC IP. Specify the IP using the -i|--bmcip option."; + } elsif (!defined($::opt_U)) { + $msg = "The check option requires a user. Specify the user with the -u|--bmcuser option."; } elsif (!defined($::opt_P)) { $msg = "The check option requires a password. Specify the password with the -p|--bmcpasswd option."; } @@ -268,9 +276,8 @@ sub bmcdiscovery_processargs { # --ipsource option, requires -i, -p to be specified #################################################### if ( defined($::opt_S) ) { - if ( defined($::opt_P) && defined($::opt_I) ) { - my $option_u = defined $::opt_U ? $::opt_U : "none"; - my $res=get_bmc_ip_source($::opt_I,$option_u,$::opt_P); + if ( defined($bmc_user) && defined($bmc_pass) && defined($::opt_I) ) { + my $res=get_bmc_ip_source($::opt_I,$bmc_user,$bmc_pass); return $res; } else { @@ -881,23 +888,25 @@ sub bmcdiscovery_ipmi { $node =~ s/(.*)/\L$1/g; } } elsif ($output =~ /error : unauthorized name/){ - xCAT::MsgUtils->message("I", {data=>["Warning: bmc username is incorrect for $node"]}, $::CALLBACK); + xCAT::MsgUtils->message("E", {data=>["BMC username is incorrect for $node"]}, $::CALLBACK); + return 1; } elsif ($output =~ /RAKP \S* \S* is invalid/) { - xCAT::MsgUtils->message("I", {data=>["Warning: bmc password is incorrect for $node"]}, $::CALLBACK); + xCAT::MsgUtils->message("E", {data=>["BMC password is incorrect for $node"]}, $::CALLBACK); + return 1; } - if ( defined($opz) || defined($opw) ) - { - format_stanza($node, $ip); - if (defined($opw)) - { - write_to_xcatdb($node, $ip,$request_command); - } - } - else{ - my $rsp = {}; - push @{ $rsp->{data} }, "$ip"; - xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); - } + if ( defined($opz) || defined($opw) ) + { + format_stanza($node, $ip); + if (defined($opw)) + { + write_to_xcatdb($node, $ip,$request_command); + } + } + else{ + my $rsp = {}; + push @{ $rsp->{data} }, "$ip"; + xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); + } } }