diff --git a/docs/source/guides/admin-guides/references/man1/switchdiscover.1.rst b/docs/source/guides/admin-guides/references/man1/switchdiscover.1.rst index e84f3e74d..e219a5ea8 100644 --- a/docs/source/guides/admin-guides/references/man1/switchdiscover.1.rst +++ b/docs/source/guides/admin-guides/references/man1/switchdiscover.1.rst @@ -15,7 +15,7 @@ SYNOPSIS \ **switchdiscover [-v| -**\ **-version]**\ -\ **switchdiscover**\ [\ *noderange*\ | \ **-**\ **-range**\ \ *ip_ranges*\ ] \ **[-V] [-w][-r|-x|-z][-s**\ \ *scan_methods*\ \ **-**\ **-setup**\ ] +\ **switchdiscover**\ [\ *noderange*\ | \ **-**\ **-range**\ \ *ip_ranges*\ ] \ **[-V] [-w][-r|-x|-z][-s**\ \ *scan_methods*\ ] [\ **-**\ **-setup**\ ] [\ **-c**\ \ *community*\ ] *********** @@ -31,7 +31,7 @@ To view all the switches defined in the xCAT database use \ **lsdef -w "nodetype For lldp method, make sure that lldpd package is installed and lldpd is running on the xCAT management node. lldpd comes from xcat-dep package or you can get it from http://vincentbernat.github.io/lldpd/installation.html. -For snmp method, make sure that snmpwalk command is installed and snmp is enabled for switches. To install snmpwalk, "yum install net-snmp-utils" for redhat and sles, "apt-get install snmp" for Ubuntu. +For snmp method, make sure that snmpwalk command is installed and snmp is enabled for switches. To install snmpwalk, "yum install net-snmp-utils" for redhat and sles, "apt-get install snmp" for Ubuntu. The switchdiscover command only check the switches with default community string, if user already configured switch with other commmunity string, need to pass in with \ **-c**\ option for switchdiscover command to be able to discover. ******* @@ -118,6 +118,12 @@ OPTIONS +\ **-c**\ + + User defined community string for snmp scan. + + + ************ RETURN VALUE diff --git a/perl-xCAT/xCAT/Usage.pm b/perl-xCAT/xCAT/Usage.pm index efa72327e..6b1dab41c 100755 --- a/perl-xCAT/xCAT/Usage.pm +++ b/perl-xCAT/xCAT/Usage.pm @@ -328,7 +328,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]", + switchdiscover [|--range ipranges] [-s scan_methods] [-c community] [-r|-x|-z] [-w] [-V|--verbose] [--setup]", "switchprobe" => "Usage: switchprobe [] [-V|--verbose | -c|--check]", "makentp" => diff --git a/xCAT-client/pods/man1/switchdiscover.1.pod b/xCAT-client/pods/man1/switchdiscover.1.pod index ec16fcaad..20f8e56e1 100755 --- a/xCAT-client/pods/man1/switchdiscover.1.pod +++ b/xCAT-client/pods/man1/switchdiscover.1.pod @@ -10,7 +10,7 @@ B B -B [I | B<--range> I] B<[-V] [-w][-r|-x|-z][-s> I B<--setup>] +B [I | B<--range> I] B<[-V] [-w][-r|-x|-z][-s> I] [B<--setup>] [B<-c> I] @@ -24,7 +24,7 @@ To view all the switches defined in the xCAT database use B option for switchdiscover command to be able to discover. =head1 OPTIONS @@ -87,6 +87,10 @@ Stanza formatted output. Process switch-based switch discovery. Update discovered switch's ip address, hostname and enable snmpv3 configuration based on the predefined switch. +=item B<-c> + +User defined community string for snmp scan. + =back =head1 RETURN VALUE diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index bf3ca0a76..40a9fd640 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -21,6 +21,7 @@ no strict; use Data::Dumper; use Socket; use Expect; +use SNMP; use xCAT::data::switchinfo; #global variables for this module @@ -144,7 +145,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 c=s setup pdu))) { return( usage() ); } @@ -252,6 +253,13 @@ sub parse_args { $globalopt{n} = 1; } + ######################################################### + # Accept the community string from user + ######################################################### + if ( exists( $opt{c} )) { + $community=$opt{c}; + } + ######################################################### # setup discover switch ######################################################### @@ -892,13 +900,6 @@ sub snmp_scan { } my @lines = split /\n/, $result; - #set community string for switch - $community = "public"; - my @snmpcs = xCAT::TableUtils->get_site_attribute("snmpc"); - my $tmp = $snmpcs[0]; - if (defined($tmp)) { $community = $tmp } - - foreach my $line (@lines) { my @array = split / /, $line; if ($line =~ /\b(\d{1,3}(?:\.\d{1,3}){3})\b/) @@ -954,20 +955,47 @@ sub get_snmpvendorinfo { my $request = shift; my $ip = shift; my $snmpwalk_vendor; + my $result; + my $rc=1; + #checking snmp connection + #during discovery phase, xCAT will not know the community string for snmp + #so, will try community string from following way: + # 1) -c options from user input + # 2) snmpc attribute defined in the site table + # 3) default community string for the switches. - #Ubuntu only takes OID - #get sysDescr.0"; - my $ccmd = "snmpwalk -Os -v1 -c $community $ip 1.3.6.1.2.1.1.1"; - if (exists($globalopt{verbose})) { - send_msg($request, 0, "Process command: $ccmd\n"); + my @comm_list; + my $snmpver = '1'; + + my @snmpcs = xCAT::TableUtils->get_site_attribute("snmpc"); + my $snmp_site = $snmpcs[0]; + + if ($community) { + push @comm_list, $community; } + if ($snmp_site) { + push @comm_list, $snmp_site; + } + push @comm_list, 'public'; - my $result = xCAT::Utils->runcmd($ccmd, 0); - if ($::RUNCMD_RC != 0) - { + foreach $comms(@comm_list) { + #get sysDescr.0"; + my $ccmd = "snmpwalk -Os -v1 -c $comms $ip 1.3.6.1.2.1.1.1"; if (exists($globalopt{verbose})) { - send_msg($request, 1, "Could not process this command: $ccmd" ); + send_msg($request, 0, "Process command: $ccmd\n"); + } + $result = xCAT::Utils->runcmd($ccmd, 0); + if ($::RUNCMD_RC == 0) + { + $community = $comms; + $rc=0; + last; + } + } + if ($rc == 1) { + if (exists($globalopt{verbose})) { + send_msg($request, 1, "Could not process snmpwalk command to get sysDescr, please verify community string" ); } return $snmpwalk_vendor; }