mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 03:12:30 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -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. | ||||
|   | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -8,11 +8,11 @@ B<bmcdiscover> [B<-?>|B<-h>|B<--help>] | ||||
|  | ||||
| B<bmcdiscover> [B<-v>|B<--version>] | ||||
|  | ||||
| B<bmcdiscover> [B<-s> I<scan_method>] B<--range> I<ip_ranges> [{B<-u>|B<--bmcuser>} I<bmc_username> {B<-p>|B<--bmcpasswd>}] [B<-z>] [B<-w>] [B<-t>] | ||||
| B<bmcdiscover> [B<-s> I<scan_method>] [B<-u> I<bmc_user>] [B<-p> I<bmc_passwd>] [B<-z>] [B<-w>] [B<-t>] B<--range> I<ip_ranges> | ||||
|  | ||||
| B<bmcdiscover> {B<-i>|B<--bmcip>} I<bmc_ip> {B<-u>|B<--bmcuser>} I<bmc_username> {B<-p>|B<--bmcpasswd>} I<bmc_password> B<--check> | ||||
| B<bmcdiscover> B<-u> I<bmc_user> B<-p> I<bmc_passwd> B<-i> I<bmc_ip> B<--check> | ||||
|  | ||||
| B<bmcdiscover> {B<-i>|B<--bmcip>} I<bmc_ip> {B<-u>|B<--bmcuser>} I<bmc_username> {B<-p>|B<--bmcpasswd>} I<bmc_password> B<--ipsource> | ||||
| B<bmcdiscover> [B<-u> I<bmc_user>] [B<-p> I<bmc_passwd>] B<-i> I<bmc_ip> 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> | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user