diff --git a/perl-xCAT/xCAT/Usage.pm b/perl-xCAT/xCAT/Usage.pm index 04cda85e2..9e44a774c 100755 --- a/perl-xCAT/xCAT/Usage.pm +++ b/perl-xCAT/xCAT/Usage.pm @@ -326,7 +326,7 @@ my %usage = ( pdudiscover [|--range ipranges] [-r|-x|-z] [-w] [-V|--verbose] [--setup]", "switchdiscover" => "Usage: switchdiscover [-h|--help|-v|--version] - switchdiscover [|--range ipranges] [-s scan_methods] [-r|-x|-z] [-w] [-V|--verbose] [--setup] [--pdu]", + switchdiscover [|--range ipranges] [-s scan_methods] [-r|-x|-z] [-w] [-V|--verbose] [--setup]", "switchprobe" => "Usage: switchprobe [] [-V|--verbose | -c|--check]", "makentp" => diff --git a/xCAT-server/lib/xcat/plugins/pdu.pm b/xCAT-server/lib/xcat/plugins/pdu.pm index 7242aaf80..e79b906e0 100644 --- a/xCAT-server/lib/xcat/plugins/pdu.pm +++ b/xCAT-server/lib/xcat/plugins/pdu.pm @@ -473,7 +473,7 @@ sub process_pdudiscover { Getopt::Long::Configure("no_pass_through"); my %opt; if (!GetOptions( \%opt, - qw(h|help V|Verbose x z w r n range=s setup))) { + qw(h|help V|verbose x z w r range=s setup))) { my $usage_string = xCAT::Usage->getUsage($request->{command}->[0]); $callback->({ data => $usage_string }); return; diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index ec1ebe953..f39141092 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -24,6 +24,7 @@ use Expect; use xCAT::data::switchinfo; #global variables for this module +my $device; my $community; my %globalopt; my @filternodes; @@ -143,7 +144,7 @@ sub parse_args { # Process command-line flags ############################################# if (!GetOptions( \%opt, - qw(h|help V|Verbose v|version x z w r n range=s s=s setup pdu))) { + qw(h|help V|verbose v|version x z w r n range=s s=s setup pdu))) { return( usage() ); } @@ -258,8 +259,10 @@ sub parse_args { $globalopt{setup} = 1; } + $device = "switch"; if ( exists( $opt{pdu} )) { - $globalopt{pdu} = 1; + $globalopt{pdu} = 1; + $device = "pdu"; } @@ -884,7 +887,7 @@ sub snmp_scan { # snmpwalk command has to be available for snmp_scan if (-x "/usr/bin/snmpwalk" ){ - send_msg($request, 0, "Discovering devices using snmpwalk for @$ranges ....."); + send_msg($request, 0, "Discovering $device using snmpwalk for @$ranges ....."); } else { send_msg($request, 0, "snmpwalk is not available, please install snmpwalk command first"); return 1; @@ -972,7 +975,7 @@ sub snmp_scan { $switches->{$mac}->{vendor} = $vendor; $switches->{$mac}->{name} = $hostname; if (exists($globalopt{verbose})) { - send_msg($request, 0, "found device: $hostname, $ip, $stype, $vendor"); + send_msg($request, 0, "found $device: $hostname, $ip, $stype, $vendor"); } } } @@ -1196,32 +1199,14 @@ sub xCATdB { $mac=" "; } - # check if this is for pdu or switches - my $device = "switch"; - if (exists($globalopt{pdu})) { - $device = "pdu"; - } - - ################################################# - # use lsdef command to check if this switch is - # already in the switch table - # if it is, use chdef to update it's attribute - # otherwise, use mkdef to add this switch to - # switch table + # use chdef command to make new device or update + # it's attribute ################################################## - $ret = xCAT::Utils->runxcmd( { command => ['lsdef'], arg => ['-t','node','-o',$host] }, $sub_req, 0, 1); - if ($::RUNCMD_RC == 0) - { - $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$host,"ip=$ip","mac=$mac","nodetype=$device","mgt=$device","usercomment=$vendor"] }, $sub_req, 0, 1); - $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$host,'-p',"groups=$device"] }, $sub_req, 0, 1); + if (exists($globalopt{pdu})) { + $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$host,"groups=$device","ip=$ip","mac=$mac","nodetype=$device","mgt=$device","usercomment=$vendor"] }, $sub_req, 0, 1); } else { - $ret = xCAT::Utils->runxcmd( { command => ['mkdef'], arg => ['-t','node','-o',$host,"groups=$device","ip=$ip","mac=$mac","nodetype=$device","mgt=$device","usercomment=$vendor"] }, $sub_req, 0, 1); - } - - if (!exists($globalopt{pdu})) - { - $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$host,'-p',"switchtype=$stype"] }, $sub_req, 0, 1); + $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$host,"groups=$device","ip=$ip","mac=$mac","nodetype=$device","mgt=$device","usercomment=$vendor","switchtype=$stype"] }, $sub_req, 0, 1); } } } @@ -1307,12 +1292,6 @@ sub format_stanza { $mac = " "; } - # check if this is for pdu or switches - my $device = "switch"; - if (exists($globalopt{pdu})) { - $device = "pdu"; - } - $result .= "$host:\n\tobjtype=node\n"; $result .= "\tgroups=$device\n"; $result .= "\tip=$ip\n"; @@ -1354,12 +1333,6 @@ sub format_xml { $mac = " "; } - # check if this is for pdu or switches - my $device = "switch"; - if (exists($globalopt{pdu})) { - $device = "pdu"; - } - $result .= "hostname=$host\n"; $result .= "objtype=node\n"; $result .= "groups=$device\n"; @@ -1423,7 +1396,7 @@ sub matchPredefineSwitch { my $node = $macmap->find_mac($mac,0,1); if (!$node) { - send_msg($request, 0, "Device discovered: $dswitch "); + send_msg($request, 0, "$device discovered: $dswitch "); $discoverswitch->{$mac}->{ip} = $ip; $discoverswitch->{$mac}->{vendor} = $vendor; $discoverswitch->{$mac}->{name} = $dswitch; @@ -1432,13 +1405,14 @@ sub matchPredefineSwitch { my $stype = get_switchtype($vendor); - send_msg($request, 0, "Device discovered and matched: $dswitch to $node" ); + send_msg($request, 0, "$device discovered and matched: $dswitch to $node" ); # only write to xcatdb if -w or --setup option specified if ( (exists($globalopt{w})) || (exists($globalopt{setup})) ) { - xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"otherinterfaces=$ip",'status=Matched',"mac=$mac","switchtype=$stype","usercomment=$vendor"] }, $sub_req, 0, 1); - if (!exists($globalopt{pdu})) { - xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"switchtype=$stype"] }, $sub_req, 0, 1); + if (exists($globalopt{pdu})) { + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"otherinterfaces=$ip",'status=Matched',"mac=$mac","switchtype=$stype","usercomment=$vendor"] }, $sub_req, 0, 1); + } else { + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"otherinterfaces=$ip",'status=Matched',"mac=$mac","switchtype=$stype","usercomment=$vendor","switchtype=$stype"] }, $sub_req, 0, 1); } }