mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-22 11:42:05 +00:00
modified from review
This commit is contained in:
parent
c3159a5b20
commit
762ee31628
@ -326,7 +326,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] [--pdu]",
|
||||
switchdiscover [<noderange>|--range ipranges] [-s scan_methods] [-r|-x|-z] [-w] [-V|--verbose] [--setup]",
|
||||
"switchprobe" =>
|
||||
"Usage: switchprobe [<noderange>] [-V|--verbose | -c|--check]",
|
||||
"makentp" =>
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user