From 5ffaebd6367d375573e85661efa1374ebaca4c37 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Fri, 22 Sep 2017 16:36:06 -0400 Subject: [PATCH] Add -c option for switchdiscover command to pass in community string --- perl-xCAT/xCAT/Usage.pm | 2 +- .../lib/xcat/plugins/switchdiscover.pm | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) 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-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index bf3ca0a76..f584f6385 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -25,7 +25,7 @@ use xCAT::data::switchinfo; #global variables for this module my $device; -my $community; +my $community="public"; my %globalopt; my @filternodes; my @iprange; @@ -144,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 c=s setup pdu))) { return( usage() ); } @@ -252,6 +252,14 @@ 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/)