2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-08-14 07:10:21 +00:00

Merge pull request #4001 from cxhong/3977

Add -c option for switchdiscover command to pass in community string
This commit is contained in:
Victor Hu
2017-09-29 13:15:44 -04:00
committed by GitHub
4 changed files with 60 additions and 22 deletions

View File

@@ -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

View File

@@ -328,7 +328,7 @@ my %usage = (
pdudiscover [<noderange>|--range ipranges] [-r|-x|-z] [-w] [-V|--verbose] [--setup]",
"switchdiscover" =>
"Usage: switchdiscover [-h|--help|-v|--version]
switchdiscover [<noderange>|--range ipranges] [-s scan_methods] [-r|-x|-z] [-w] [-V|--verbose] [--setup]",
switchdiscover [<noderange>|--range ipranges] [-s scan_methods] [-c community] [-r|-x|-z] [-w] [-V|--verbose] [--setup]",
"switchprobe" =>
"Usage: switchprobe [<noderange>] [-V|--verbose | -c|--check]",
"makentp" =>

View File

@@ -10,7 +10,7 @@ B<switchdiscover [-h| --help]>
B<switchdiscover [-v| --version]>
B<switchdiscover> [I<noderange> | B<--range> I<ip_ranges>] B<[-V] [-w][-r|-x|-z][-s> I<scan_methods> B<--setup>]
B<switchdiscover> [I<noderange> | B<--range> I<ip_ranges>] B<[-V] [-w][-r|-x|-z][-s> I<scan_methods>] [B<--setup>] [B<-c> I<community>]
@@ -24,7 +24,7 @@ To view all the switches defined in the xCAT database use B<lsdef -w "nodetype=s
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 B<-c> 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

View File

@@ -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;
}