From 91d803ec389c3b42f9928a5d00ecf021dbab0424 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Mon, 11 Jul 2016 17:03:00 -0400 Subject: [PATCH 01/21] Switch-based switch discovery for BNT and Mellanox --- .../lib/xcat/plugins/switchdiscover.pm | 189 ++++++++++++++- xCAT-server/share/xcat/tools/configBNT | 224 ++++++++++++++++++ xCAT-server/share/xcat/tools/configMellanox | 115 +++++++++ 3 files changed, 527 insertions(+), 1 deletion(-) create mode 100755 xCAT-server/share/xcat/tools/configBNT create mode 100755 xCAT-server/share/xcat/tools/configMellanox diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index f9f571909..e789b577f 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -14,11 +14,13 @@ use xCAT::NodeRange; use xCAT::NetworkUtils; use xCAT::Utils; use xCAT::SvrUtils; +use xCAT::MacMap; use xCAT::Table; use XML::Simple; no strict; use Data::Dumper; use Socket; +use Expect; #global variables for this module my %globalopt; @@ -37,6 +39,7 @@ my %global_switch_type = ( cisco => "Cisco", BNT => "BNT", Blade => "BNT", + G8052 => "BNT", Mellanox => "Mellanox", mellanox => "Mellanox", MLNX => "Mellanox", @@ -153,7 +156,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))) { + qw(h|help V|Verbose v|version x z w r n range=s s=s setup))) { return( usage() ); } @@ -261,6 +264,14 @@ sub parse_args { $globalopt{n} = 1; } + ######################################################### + # setup discover switch + ######################################################### + if ( exists( $opt{setup} )) { + $globalopt{setup} = 1; + } + + return; } @@ -460,6 +471,16 @@ sub process_request { xCATdB($result, \%request, $sub_req); } + if (exists($globalopt{setup})) { + #discovered switches need to write to xcatdb before we can set them up + # It will be removed once we found predefine switch. + if (!exists($globalopt{w})) { + xCATdB($result, \%request, $sub_req); + } + switchsetup($result, \%request, $sub_req); + } + + return; } @@ -1328,5 +1349,171 @@ sub format_xml { return ($xml); } +#-------------------------------------------------------------------------------- +=head3 switchsetup + find discovered switches with predefine switches + Arguments: + outhash: a hash containing the switches discovered + Returns: + result: +=cut +#-------------------------------------------------------------------------------- + +sub switchsetup { + my $outhash = shift; + my $request = shift; + my $sub_req = shift; + my $ret; + my @switchnode = (); + my $switchInfo; + my $output; + my $dshcmd; + + #print Dumper($outhash); + my $macmap = xCAT::MacMap->new(); + + ################################################# + # call find_mac to match pre-defined switch and + # discovery switch + ################################################## + + foreach my $mac ( keys %$outhash ) { + my $ip = $outhash->{$mac}->{ip}; + my $vendor = $outhash->{$mac}->{vendor}; + my $node = $macmap->find_mac($mac,0); + + # get predefine node ip address + $static_ip = xCAT::NetworkUtils->getipaddr($node); + + # issue makehosts so we can use xdsh + my $dswitch = get_hostname($outhash->{$mac}->{name}, $ip); + + + #add discovered switch to /etc/hosts + $output = xCAT::Utils->runxcmd({command => ["makehosts"], + node =>[$dswitch]}, $sub_req, 0, 1); + + #run xdsh command to set discover ip address to static ip address + #each switch type has different CLI for setup ip address + my $stype = get_switchtype($vendor); + + if (exists($globalopt{verbose})) { + send_msg($request, 0, "Found Discovery switch $dswitch, $ip, $mac with predefine switch $node, $static_ip $stype switch\n" ); + } + + if ( $stype =~ /BNT/ ) { + # BNT switches + #xdsh switch-192-168-5-152 --devicetype EthSwitch::BNT + # "enable;configure terminal;show interface ip;interface ip 1;ip address 192.168.5.22" + $dshcmd="enable;configure terminal;show interface ip;interface ip 1;ip address $static_ip"; + $output = xCAT::Utils->runxcmd({command => ["xdsh"], + node =>[$dswitch], + arg => ["--devicetype", "EthSwitch::BNT", "$dshcmd"] }, $sub_req, 0, 1); + #send_msg($request, 0, Dumper($output)); + + #set up hostname + $dshcmd="enable;configure terminal;hostname $node;write memory"; + $output = xCAT::Utils->runxcmd({command => ["xdsh"], + node =>[$node], + arg => ["--devicetype", "EthSwitch::BNT", "$dshcmd"] }, $sub_req, 0, 1); + } + elsif ( $stype =~ /Mellanox/ ) { + #set static ip address the mgmt0, we don't have EthSwitch yet, will use IBSwitch for now + #NOTE: this expect routine will timeout after set up address + + my $myexp = new Expect; + my $timeout = 10; + my $login_cmd = "ssh -ladmin $dswitch\r"; + my $first_prompt = "^.*>"; + my $config_prompt="^.*#"; + my $cfg_ip="mgmt0\r"; + my $cfg_ip="no interface mgmt0 dhcp\r"; + my $cfg_ip1="interface mgmt0 ip address $static_ip 255.255.0.0\r"; + + unless ($myexp->spawn($login_cmd)) + { + $myexp->soft_close(); + send_msg($request, 0, "Unable to run $login_cmd\n"); + next; + } + my @result = $myexp->expect( + $timeout, + [ + $first_prompt, + sub { + $myexp->clear_accum(); + $myexp->send("enable\r"); + $myexp->clear_accum(); + $myexp->send("configure terminal\r"); + $myexp->clear_accum(); + $myexp->exp_continue(); + } + ], + [ + "-re", $config_prompt, + sub { + $myexp->clear_accum(); + $myexp->send($cfg_ip); + $myexp->send($cfg_ip1); + $myexp->clear_accum(); + $myexp->send("configuration write\r"); + $myexp->send("exit\r"); + $myexp->send("exit\r"); + } + ], + ); + if (defined($result[1])) + { + my $errmsg = $result[1]; + $myexp->soft_close(); + send_msg($request,0,"Failed expect command $errmsg\n"); + } + + + $myexp->soft_close(); + + #set up hostname + $dshcmd="enable;configure terminal;hostname $node;configuration write"; + $output = xCAT::Utils->runxcmd({command => ["xdsh"], + node =>[$node], + arg => ["-l", "admin", "--devicetype", "IBSwitch::Mellanox", "$dshcmd"] }, $sub_req, 0, 1); + } + else { + send_msg($request, 0, "the switch type $stype is not support\n"); + } + + #after switch ip address is setup to static ip + #remove discover switch definition + if (exists($globalopt{verbose})) { + send_msg($request, 0, "remove discover switch $dswitch from xCAT"); + } + $output = xCAT::Utils->runxcmd({command => ["makehosts"], + node =>[$dswitch], + arg => ['-d'] }, $sub_req, 0, 1); + + my $ccmd = "rmdef $dswitch"; + $output = xCAT::Utils->runcmd($ccmd, 0); + #send_msg($request, 0, Dumper($output)); + + #add mac to predefine switch + if (exists($globalopt{verbose})) { + send_msg($request, 0, "Update Mac address for switch $node"); + } + + my $mactab = xCAT::Table->new('mac'); + my $upmac; + if ($mactab) { + $upmac->{$node}->{mac} = $mac; + $mactab->setNodesAttribs($upmac); + } + + } + + return; + + +} + + 1; diff --git a/xCAT-server/share/xcat/tools/configBNT b/xCAT-server/share/xcat/tools/configBNT new file mode 100755 index 000000000..80bd15bb8 --- /dev/null +++ b/xCAT-server/share/xcat/tools/configBNT @@ -0,0 +1,224 @@ +#!/usr/bin/env perl + +#--------------------------------------------------------- +# Configure Ethnet BNT switches +#--------------------------------------------------------- + +use strict; +use Getopt::Long; +use Expect; + +my $args = join ' ', @ARGV; +$::command = "$0 $args"; + +Getopt::Long::Configure("bundling"); +$Getopt::Long::ignorecase = 0; + + +#--------------------------------------------------------- +#Main + +# parse the options +if ( + !GetOptions( + 'h|help' => \$::HELP, + 'r|range=s' => \$::SWITCH, + 'p|port=s' => \$::PORT, + 'v|vlan=s' => \$::VLAN, + 'u|user=s' => \$::USER, + 'w|password=s' => \$::PASSWORD, + 'g|group=s' => \$::GROUP, + 'snmp' => \$::SNMP, + ) + ) +{ + &usage; + exit(1); +} + +# display the usage if -h or --help is specified +if ($::HELP) +{ + &usage; + exit(0); +} + +my $switch; +if ($::SWITCH) +{ + $switch = $::SWITCH; +} else { + &usage; + exit(1); +} + +my $cmd; + +#default root/password and protcol for BNT switch +my $cmd = `chdef $switch protocol=telnet username=root password=admin`; + +my $vlan; +my $port; +if ($::VLAN) +{ + if ($::PORT) { + $port = $::PORT; + } else { + print "Need port number to set up VLAN\n"; + &usage; + exit(1); + } + $vlan = $::VLAN; + print "Tagging VLAN=$vlan for $switch port $port\n"; + #create vlan + #tagged vlan + $cmd = `xdsh $switch --devicetype EthSwitch::BNT "enable;configure terminal;vlan $vlan;exit;interface port $port;switchport mode trunk;switchport trunk allowed vlan $vlan;write memory;exit;exit"`; +} + +#setup secure SNMP v3 +if ($::SNMP){ + my $mysw; + my $enable_cmd="enable\r"; + my $config_cmd="configure terminal\r"; + my $exit_cmd="exit\r"; + + my $pwd_prompt = "password: "; + my $sw_prompt = "$switch>"; + my $enable_prompt="$switch#"; + my $config_prompt="^.*\\\(config\\\)\#"; + + $mysw = new Expect; + my $timeout = 20; + my $login_cmd = "telnet $switch\r"; + my $passwd = "admin\r"; + my $snmp_user; + my $snmp_passwd; + my $snmp_group; + if ($::USER) { + $snmp_user = $::USER; + } else { + $snmp_user = "xcatadmin\r"; + } + if ($::PASSWORD) { + $snmp_passwd = $::PASSWORD; + } else { + # Need a special character + $snmp_passwd = "xcatadminpassw0rd\@snmp\r"; + } + if ($::GROUP) { + $snmp_group = $::GROUP; + } else { + $snmp_group = "xcatgroup\r"; + } + print "Setup SNMP server for user=$snmp_user, password=$snmp_passwd, group=$snmp_group\n"; + #create a SNMP user + my $cfg_user1="snmp-server user 5 name $snmp_user\r"; + my $cfg_user2="snmp-server user 5 authentication-protocol sha authentication-password\r"; + #create a SNMP group + my $cfg_group1="snmp-server group 5 group-name $snmp_group\r"; + my $cfg_group2="snmp-server group 5 user-name $snmp_user\r"; + my $cfg_group3="snmp-server group 5 security usm\r"; + #Add access permission + my $cfg_access1="snmp-server access 5 name $snmp_group\r"; + my $cfg_access2="snmp-server access 5 level authNoPriv\r"; + my $cfg_access3="snmp-server access 5 security usm\r"; + my $cfg_access4="snmp-server access 5 read-view iso\r"; + + $mysw->slave->stty(qw(sane -echo)); + + unless ($mysw->spawn($login_cmd)) + { + $mysw->soft_close(); + print "Unable to run $login_cmd\n"; + next; + } + my @result = $mysw->expect( + $timeout, + [ + $pwd_prompt, + sub { + $mysw->clear_accum(); + $mysw->send("$passwd\r"); + $mysw->clear_accum(); + $mysw->exp_continue(); + } + ], + [ + "-re", $sw_prompt, + sub { + #print "$switch: sending enable command: $enable_cmd\n"; + $mysw->clear_accum(); + $mysw->send($enable_cmd); + $mysw->exp_continue(); + } + ], + [ + "-re", $enable_prompt, + sub { + #print "$switch: sending config command: $config_cmd\n"; + $mysw->clear_accum(); + $mysw->send($config_cmd); + $mysw->exp_continue(); + } + ], + [ + "-re", $config_prompt, + sub { + $mysw->clear_accum(); + $mysw->send($cfg_user1); + $mysw->send($cfg_user2); + $mysw->send($passwd); + $mysw->send($snmp_passwd); + $mysw->send($snmp_passwd); + sleep 1; + $mysw->clear_accum(); + # create snmp group + $mysw->send($cfg_group1); + $mysw->send($cfg_group2); + $mysw->send($cfg_group3); + $mysw->clear_accum(); + $mysw->send($cfg_access1); + $mysw->send($cfg_access2); + $mysw->send($cfg_access3); + $mysw->send($cfg_access4); + $mysw->clear_accum(); + $mysw->send("write memory\r"); + $mysw->send($exit_cmd); + $mysw->send($exit_cmd); + } + ], + ); + ########################################## + # Expect error - report and quit + ########################################## + if (defined($result[1])) + { + my $errmsg = $result[1]; + $mysw->soft_close(); + print "Failed expect command $errmsg\n"; + exit(1); + } + $mysw->soft_close(); + + +} + +#--------------------------------------------------------- + +=head3 usage + + Displays message for -h option + +=cut + +#--------------------------------------------------------- +sub usage +{ + print "Usage: + configBNT [-?│-h│--help] + configBNT [--range switchnames] [-p|--port port] [-v|--vlan vlan] + configBNT [--range switchnames] [--snmp] [-u|--user snmp_user] [-w|--password snmp_password] [-g|--group snmp_group] + \n"; +} + + diff --git a/xCAT-server/share/xcat/tools/configMellanox b/xCAT-server/share/xcat/tools/configMellanox new file mode 100755 index 000000000..be79c17a4 --- /dev/null +++ b/xCAT-server/share/xcat/tools/configMellanox @@ -0,0 +1,115 @@ +#!/usr/bin/env perl + +#--------------------------------------------------------- +# Configure Ethnet Mellonax switches +#--------------------------------------------------------- + +use strict; +use Getopt::Long; +use Expect; + +my $args = join ' ', @ARGV; +$::command = "$0 $args"; + +Getopt::Long::Configure("bundling"); +$Getopt::Long::ignorecase = 0; + + +#--------------------------------------------------------- +#Main + +# parse the options +if ( + !GetOptions( + 'h|help' => \$::HELP, + 'r|range=s' => \$::SWITCH, + 'u|user=s' => \$::USER, + 'i|ip=s' => \$::IP, + ) + ) +{ + &usage; + exit(1); +} + +# display the usage if -h or --help is specified +if ($::HELP) +{ + &usage; + exit(0); +} + +my $switch; +if ($::SWITCH) +{ + $switch = $::SWITCH; +} else { + &usage; + exit(1); +} + +my $user; + +if ($::USER) +{ + $user = $::USER; +} else { + &usage; + exit(1); +} + +my $ip; +if ($::IP) +{ + $ip = $::IP; +} else { + &usage; + exit(1); +} + + +my $cmd; + +#default root/password and protcol for Mellonax switch +$cmd = `chtab switch=$switch switches.sshusername=$user`; +print $cmd; + +#call rspconfig command to setup switch +#enable ssh +$cmd=`rscpconfig $switch sshcfg=enable`; +print $cmd; + +#enable snmp function on the switch +$cmd=`rscpconfig $switch snmpcfg=enable`; +print $cmd; + +#enable the snmp trap +$cmd=`rscpconfig $switch alert=enable`; +print $cmd; + +#Logging destination: +$cmd=`rscpconfig $switch logdest=$ip`; +print $cmd; + +#config ntp +$cmd = `xdsh $switch -l $user --devicetype IBSwitch::Mellanox "enable;configure terminal;ntp enable;ntpdate $ip; ntp server $ip;configuration write;show ntp" `; +print $cmd; + +#--------------------------------------------------------- + +=head3 usage + + Displays message for -h option + +=cut + +#--------------------------------------------------------- +sub usage +{ + print "Usage: + configMellonax [-?│-h│--help] + configMellonax [--range switchnames] [-u|--user sshusername] [-i|--ip xcatMN_ip_address] + \n"; +} + + From ab3a735edeffeae435132d24593e9a7c3b2ce695 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Tue, 12 Jul 2016 16:38:32 -0400 Subject: [PATCH 02/21] Create subroute for configBNT and configMerllanox --- .../lib/xcat/plugins/switchdiscover.pm | 253 ++++++++++++------ xCAT-server/share/xcat/tools/configBNT | 3 - xCAT-server/share/xcat/tools/configMellanox | 8 +- 3 files changed, 177 insertions(+), 87 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index e789b577f..2319bdc30 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -1352,6 +1352,11 @@ sub format_xml { #-------------------------------------------------------------------------------- =head3 switchsetup find discovered switches with predefine switches + for each discovered switches: + 1) matching mac to a predefined node + 2) if get predefined node, config the discovered switch, if failed, update + 'otherinterface' attribute of predefined node + 3) remove hosts record and node definition for the discovered switch Arguments: outhash: a hash containing the switches discovered Returns: @@ -1380,106 +1385,45 @@ sub switchsetup { foreach my $mac ( keys %$outhash ) { my $ip = $outhash->{$mac}->{ip}; my $vendor = $outhash->{$mac}->{vendor}; - my $node = $macmap->find_mac($mac,0); - - # get predefine node ip address - $static_ip = xCAT::NetworkUtils->getipaddr($node); # issue makehosts so we can use xdsh my $dswitch = get_hostname($outhash->{$mac}->{name}, $ip); - #add discovered switch to /etc/hosts $output = xCAT::Utils->runxcmd({command => ["makehosts"], node =>[$dswitch]}, $sub_req, 0, 1); - #run xdsh command to set discover ip address to static ip address - #each switch type has different CLI for setup ip address + my $node = $macmap->find_mac($mac,0); + if (!$node) { + send_message($request, 0, "NO predefined switch matched this switch $dswitch with mac address $mac"); + next; + } + + # get predefine node ip address + $static_ip = xCAT::NetworkUtils->getipaddr($node); my $stype = get_switchtype($vendor); if (exists($globalopt{verbose})) { send_msg($request, 0, "Found Discovery switch $dswitch, $ip, $mac with predefine switch $node, $static_ip $stype switch\n" ); } - if ( $stype =~ /BNT/ ) { - # BNT switches - #xdsh switch-192-168-5-152 --devicetype EthSwitch::BNT - # "enable;configure terminal;show interface ip;interface ip 1;ip address 192.168.5.22" - $dshcmd="enable;configure terminal;show interface ip;interface ip 1;ip address $static_ip"; - $output = xCAT::Utils->runxcmd({command => ["xdsh"], - node =>[$dswitch], - arg => ["--devicetype", "EthSwitch::BNT", "$dshcmd"] }, $sub_req, 0, 1); - #send_msg($request, 0, Dumper($output)); + #run xdsh command to set discover ip address to static ip address + #each switch type has different CLI for setup ip address - #set up hostname - $dshcmd="enable;configure terminal;hostname $node;write memory"; - $output = xCAT::Utils->runxcmd({command => ["xdsh"], - node =>[$node], - arg => ["--devicetype", "EthSwitch::BNT", "$dshcmd"] }, $sub_req, 0, 1); + # BNT switches + if ( $stype =~ /BNT/ ) { + config_BNT($dswitch, $node, $ip, $request, $sub_req); } + # Mellanox switches elsif ( $stype =~ /Mellanox/ ) { #set static ip address the mgmt0, we don't have EthSwitch yet, will use IBSwitch for now #NOTE: this expect routine will timeout after set up address + config_Mellanox($dswitch, $node, $ip, $request, $sub_req); - my $myexp = new Expect; - my $timeout = 10; - my $login_cmd = "ssh -ladmin $dswitch\r"; - my $first_prompt = "^.*>"; - my $config_prompt="^.*#"; - my $cfg_ip="mgmt0\r"; - my $cfg_ip="no interface mgmt0 dhcp\r"; - my $cfg_ip1="interface mgmt0 ip address $static_ip 255.255.0.0\r"; - - unless ($myexp->spawn($login_cmd)) - { - $myexp->soft_close(); - send_msg($request, 0, "Unable to run $login_cmd\n"); - next; - } - my @result = $myexp->expect( - $timeout, - [ - $first_prompt, - sub { - $myexp->clear_accum(); - $myexp->send("enable\r"); - $myexp->clear_accum(); - $myexp->send("configure terminal\r"); - $myexp->clear_accum(); - $myexp->exp_continue(); - } - ], - [ - "-re", $config_prompt, - sub { - $myexp->clear_accum(); - $myexp->send($cfg_ip); - $myexp->send($cfg_ip1); - $myexp->clear_accum(); - $myexp->send("configuration write\r"); - $myexp->send("exit\r"); - $myexp->send("exit\r"); - } - ], - ); - if (defined($result[1])) - { - my $errmsg = $result[1]; - $myexp->soft_close(); - send_msg($request,0,"Failed expect command $errmsg\n"); - } - - - $myexp->soft_close(); - - #set up hostname - $dshcmd="enable;configure terminal;hostname $node;configuration write"; - $output = xCAT::Utils->runxcmd({command => ["xdsh"], - node =>[$node], - arg => ["-l", "admin", "--devicetype", "IBSwitch::Mellanox", "$dshcmd"] }, $sub_req, 0, 1); } else { - send_msg($request, 0, "the switch type $stype is not support\n"); + send_msg($request, 0, "the switch $dswitch type $stype is not support\n"); + next; } #after switch ip address is setup to static ip @@ -1510,10 +1454,159 @@ sub switchsetup { } return; - - } +#-------------------------------------------------------------------------------- +=head3 config_BNT + config BNT switches + ---setup static ip address + ---setup hostname + ---set default user/password + Arguments: + dswitch: discovered switch + node: predefine switch + ip: static ip address + Returns: + result: +=cut +#-------------------------------------------------------------------------------- + +sub config_BNT { + my $dswitch=shift; + my $node = shift; + my $ip = shift; + my $request = shift; + my $sub_req = shift; + my $dshcmd; + + #xdsh switch-192-168-5-152 --devicetype EthSwitch::BNT + # "enable;configure terminal;show interface ip;interface ip 1;ip address 192.168.5.22" + $dshcmd="enable;configure terminal;show interface ip;interface ip 1;ip address $static_ip;exit;exit"; + $output = xCAT::Utils->runxcmd({command => ["xdsh"], + node =>[$dswitch], + arg => ["--devicetype", "EthSwitch::BNT", "$dshcmd"] }, $sub_req, 0, 1); + #send_msg($request, 0, Dumper($output)); + + #add default attribute for BNT switch + my $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=root','password=admin','protocol=telnet','switchtype=BNT'] }, $sub_req, 0, 1); + #send_msg($request, 0, Dumper($ret)); + + #set up hostname + $dshcmd="enable;configure terminal;hostname $node;write memory"; + $output = xCAT::Utils->runxcmd({command => ["xdsh"], + node =>[$node], + arg => ["--devicetype", "EthSwitch::BNT", "$dshcmd"] }, $sub_req, 0, 1); + #send_msg($request, 0, "hostname changed\n"); + + return; +} + +#-------------------------------------------------------------------------------- +=head3 config_Mellanox + config Mellanox switches + ---setup static ip address + ---setup hostname + ---set default user/password + Arguments: + dswitch: discovered switch + node: predefine switch + ip: static ip address + Returns: + result: +=cut +#-------------------------------------------------------------------------------- + +sub config_Mellanox { + my $dswitch=shift; + my $node = shift; + my $ip = shift; + my $request = shift; + my $sub_req = shift; + my $dshcmd; + my $mask; + + # get netmask from network table + my $nettab = xCAT::Table->new("networks"); + if ($nettab) { + my @nets = $nettab->getAllAttribs('net','mask'); + foreach my $net (@nets) { + if (xCAT::NetworkUtils::isInSameSubnet( $net->{'net'}, $ip, $net->{'mask'}, 0)) { + $mask=$net->{'mask'}; + } + } + } + + send_msg($request, 0, "setup Mellanox switch $node, $static_ip, $mask\n"); + #set static ip address the mgmt0, we don't have EthSwitch yet, will use IBSwitch for now + #NOTE: this expect routine will timeout after set up address + + my $myexp = new Expect; + my $timeout = 10; + my $login_cmd = "ssh -ladmin $dswitch\r"; + my $first_prompt = "^.*>"; + my $config_prompt="^.*#"; + my $cfg_ip="no interface mgmt0 dhcp\r"; + my $cfg_ip1="interface mgmt0 ip address $static_ip $mask\r"; + + unless ($myexp->spawn($login_cmd)) + { + $myexp->soft_close(); + send_msg($request, 0, "Unable to run $login_cmd\n"); + next; + } + + my @result = $myexp->expect( + $timeout, + [ + "-re", $first_prompt, + sub { + $myexp->clear_accum(); + $myexp->send("enable\r"); + $myexp->clear_accum(); + $myexp->send("configure terminal\r"); + $myexp->clear_accum(); + $myexp->exp_continue(); + } + ], + [ + "-re", $config_prompt, + sub { + $myexp->clear_accum(); + $myexp->send($cfg_ip); + $myexp->send($cfg_ip1); + $myexp->clear_accum(); + $myexp->send("configuration write\r"); + $myexp->send("exit\r"); + $myexp->send("exit\r"); + } + ], + ); + if (defined($result[1])) + { + my $errmsg = $result[1]; + $myexp->soft_close(); + send_msg($request,0,"Failed expect command $errmsg\n"); + } + + $myexp->soft_close(); + + #add default attribute for Mellanox switch + $output = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=admin','switchtype=Mellanox'] }, $sub_req, 0, 1); + send_msg($request, 0, Dumper($output)); + + + #set up hostname + $dshcmd="enable;configure terminal;hostname $node;configuration write"; + $output = xCAT::Utils->runxcmd({command => ["xdsh"], + node =>[$node], + arg => ["-l", "admin", "--devicetype", "IBSwitch::Mellanox", "$dshcmd"] }, $sub_req, 0, 1); + + return; +} + + + + 1; diff --git a/xCAT-server/share/xcat/tools/configBNT b/xCAT-server/share/xcat/tools/configBNT index 80bd15bb8..89e380103 100755 --- a/xCAT-server/share/xcat/tools/configBNT +++ b/xCAT-server/share/xcat/tools/configBNT @@ -54,9 +54,6 @@ if ($::SWITCH) my $cmd; -#default root/password and protcol for BNT switch -my $cmd = `chdef $switch protocol=telnet username=root password=admin`; - my $vlan; my $port; if ($::VLAN) diff --git a/xCAT-server/share/xcat/tools/configMellanox b/xCAT-server/share/xcat/tools/configMellanox index be79c17a4..647a3c2d6 100755 --- a/xCAT-server/share/xcat/tools/configMellanox +++ b/xCAT-server/share/xcat/tools/configMellanox @@ -76,19 +76,19 @@ print $cmd; #call rspconfig command to setup switch #enable ssh -$cmd=`rscpconfig $switch sshcfg=enable`; +$cmd=`rspconfig $switch sshcfg=enable`; print $cmd; #enable snmp function on the switch -$cmd=`rscpconfig $switch snmpcfg=enable`; +$cmd=`rspconfig $switch snmpcfg=enable`; print $cmd; #enable the snmp trap -$cmd=`rscpconfig $switch alert=enable`; +$cmd=`rspconfig $switch alert=enable`; print $cmd; #Logging destination: -$cmd=`rscpconfig $switch logdest=$ip`; +$cmd=`rspconfig $switch logdest=$ip`; print $cmd; #config ntp From 9589d1be590dc130ad757fc0d0b285318334aa8a Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Wed, 20 Jul 2016 14:50:14 -0400 Subject: [PATCH 03/21] more modification --- .../lib/xcat/plugins/switchdiscover.pm | 88 +++++++++++-------- 1 file changed, 53 insertions(+), 35 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index 2319bdc30..a0b6c28a0 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -1373,6 +1373,9 @@ sub switchsetup { my $switchInfo; my $output; my $dshcmd; + my $static_ip; + my $discover_switch; + my @rmnodes; #print Dumper($outhash); my $macmap = xCAT::MacMap->new(); @@ -1395,7 +1398,8 @@ sub switchsetup { my $node = $macmap->find_mac($mac,0); if (!$node) { - send_message($request, 0, "NO predefined switch matched this switch $dswitch with mac address $mac"); + send_msg($request, 0, "NO predefined switch matched this switch $dswitch with mac address $mac"); + $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$dswitch,"ip=$ip",'otherinterfaces=no predefined switch'] }, $sub_req, 0, 1); next; } @@ -1412,47 +1416,50 @@ sub switchsetup { # BNT switches if ( $stype =~ /BNT/ ) { - config_BNT($dswitch, $node, $ip, $request, $sub_req); + $ret = config_BNT($dswitch, $node, $static_ip, $request, $sub_req); + if ($ret == 1) { + next; + } } # Mellanox switches elsif ( $stype =~ /Mellanox/ ) { #set static ip address the mgmt0, we don't have EthSwitch yet, will use IBSwitch for now #NOTE: this expect routine will timeout after set up address - config_Mellanox($dswitch, $node, $ip, $request, $sub_req); + $ret = config_Mellanox($dswitch, $node, $static_ip, $request, $sub_req); + if ($ret == 1) { + next; + } } else { send_msg($request, 0, "the switch $dswitch type $stype is not support\n"); + $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$dswitch,"ip=$ip",'otherinterfaces=switch type is not supported'] }, $sub_req, 0, 1); + $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","switchtype=$stype",'otherinterfaces=switch type is not supported'] }, $sub_req, 0, 1); next; } - #after switch ip address is setup to static ip - #remove discover switch definition - if (exists($globalopt{verbose})) { - send_msg($request, 0, "remove discover switch $dswitch from xCAT"); - } - $output = xCAT::Utils->runxcmd({command => ["makehosts"], - node =>[$dswitch], - arg => ['-d'] }, $sub_req, 0, 1); - - my $ccmd = "rmdef $dswitch"; - $output = xCAT::Utils->runcmd($ccmd, 0); - #send_msg($request, 0, Dumper($output)); - - #add mac to predefine switch - if (exists($globalopt{verbose})) { - send_msg($request, 0, "Update Mac address for switch $node"); - } - - my $mactab = xCAT::Table->new('mac'); - my $upmac; - if ($mactab) { - $upmac->{$node}->{mac} = $mac; - $mactab->setNodesAttribs($upmac); - } - + # save for update mac address and remove node definition + $discovered_switch->{$node}->{mac}=$mac; + push (@rmnodes, $dswitch); } + #after switch ip address is setup to static ip + #remove discover switch definition + $output = xCAT::Utils->runxcmd({command => ["makehosts"], + node => \@rmnodes, + arg => ['-d'] }, $sub_req, 0, 1); + my $remove_nodes = join(",", @rmnodes); + my $ccmd = "rmdef $remove_nodes"; + $output = xCAT::Utils->runcmd($ccmd, 0); + #send_msg($request, 0, Dumper($output)); + + #update mac address + my $mactab = xCAT::Table->new('mac'); + if ($mactab) { + $mactab->setNodesAttribs($discovered_switch); + } + + return; } @@ -1474,10 +1481,11 @@ sub switchsetup { sub config_BNT { my $dswitch=shift; my $node = shift; - my $ip = shift; + my $static_ip = shift; my $request = shift; my $sub_req = shift; my $dshcmd; + my $ret; #xdsh switch-192-168-5-152 --devicetype EthSwitch::BNT # "enable;configure terminal;show interface ip;interface ip 1;ip address 192.168.5.22" @@ -1496,9 +1504,14 @@ sub config_BNT { $output = xCAT::Utils->runxcmd({command => ["xdsh"], node =>[$node], arg => ["--devicetype", "EthSwitch::BNT", "$dshcmd"] }, $sub_req, 0, 1); - #send_msg($request, 0, "hostname changed\n"); + if ($::RUNCMD_RC != 0) + { + send_msg($request, 0, "Failed to change hostname on $node"); + $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'otherinterfaces=Failed to change hostname'] }, $sub_req, 0, 1); + return 1; + } - return; + return 0; } #-------------------------------------------------------------------------------- @@ -1519,7 +1532,7 @@ sub config_BNT { sub config_Mellanox { my $dswitch=shift; my $node = shift; - my $ip = shift; + my $static_ip = shift; my $request = shift; my $sub_req = shift; my $dshcmd; @@ -1536,7 +1549,6 @@ sub config_Mellanox { } } - send_msg($request, 0, "setup Mellanox switch $node, $static_ip, $mask\n"); #set static ip address the mgmt0, we don't have EthSwitch yet, will use IBSwitch for now #NOTE: this expect routine will timeout after set up address @@ -1592,7 +1604,7 @@ sub config_Mellanox { #add default attribute for Mellanox switch $output = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=admin','switchtype=Mellanox'] }, $sub_req, 0, 1); - send_msg($request, 0, Dumper($output)); + #send_msg($request, 0, Dumper($output)); #set up hostname @@ -1600,8 +1612,14 @@ sub config_Mellanox { $output = xCAT::Utils->runxcmd({command => ["xdsh"], node =>[$node], arg => ["-l", "admin", "--devicetype", "IBSwitch::Mellanox", "$dshcmd"] }, $sub_req, 0, 1); + if ($::RUNCMD_RC != 0) + { + send_msg($request, 0, "Failed to change hostname on $node"); + $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'otherinterfaces=Failed to change hostname'] }, $sub_req, 0, 1); + return 1; + } - return; + return 0; } From cd10a95ff5310a7fad082b76b4bc29d0ad719505 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Thu, 21 Jul 2016 13:29:44 -0400 Subject: [PATCH 04/21] add otherinterfaces for error cases. --- xCAT-server/lib/xcat/plugins/switchdiscover.pm | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index a0b6c28a0..bc36b777e 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -1418,7 +1418,7 @@ sub switchsetup { if ( $stype =~ /BNT/ ) { $ret = config_BNT($dswitch, $node, $static_ip, $request, $sub_req); if ($ret == 1) { - next; + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'otherinterfaces=config failed, dhcp ip=$ip'] }, $sub_req, 0, 1); } } # Mellanox switches @@ -1427,15 +1427,13 @@ sub switchsetup { #NOTE: this expect routine will timeout after set up address $ret = config_Mellanox($dswitch, $node, $static_ip, $request, $sub_req); if ($ret == 1) { - next; + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'otherinterfaces=config failed, dhcp ip=$ip'] }, $sub_req, 0, 1); } } else { send_msg($request, 0, "the switch $dswitch type $stype is not support\n"); - $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$dswitch,"ip=$ip",'otherinterfaces=switch type is not supported'] }, $sub_req, 0, 1); - $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","switchtype=$stype",'otherinterfaces=switch type is not supported'] }, $sub_req, 0, 1); - next; + $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","switchtype=$stype",'otherinterfaces=switch type is not supported yet, dhcp ip=$ip'] }, $sub_req, 0, 1); } # save for update mac address and remove node definition @@ -1458,8 +1456,6 @@ sub switchsetup { if ($mactab) { $mactab->setNodesAttribs($discovered_switch); } - - return; } @@ -1496,7 +1492,7 @@ sub config_BNT { #send_msg($request, 0, Dumper($output)); #add default attribute for BNT switch - my $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=root','password=admin','protocol=telnet','switchtype=BNT'] }, $sub_req, 0, 1); + my $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=root','password=admin','protocol=telnet','switchtype=BNT','otherinterfaces='] }, $sub_req, 0, 1); #send_msg($request, 0, Dumper($ret)); #set up hostname @@ -1507,7 +1503,6 @@ sub config_BNT { if ($::RUNCMD_RC != 0) { send_msg($request, 0, "Failed to change hostname on $node"); - $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'otherinterfaces=Failed to change hostname'] }, $sub_req, 0, 1); return 1; } @@ -1603,7 +1598,7 @@ sub config_Mellanox { $myexp->soft_close(); #add default attribute for Mellanox switch - $output = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=admin','switchtype=Mellanox'] }, $sub_req, 0, 1); + $output = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=admin','switchtype=Mellanox','otherinterfaces='] }, $sub_req, 0, 1); #send_msg($request, 0, Dumper($output)); @@ -1615,7 +1610,6 @@ sub config_Mellanox { if ($::RUNCMD_RC != 0) { send_msg($request, 0, "Failed to change hostname on $node"); - $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'otherinterfaces=Failed to change hostname'] }, $sub_req, 0, 1); return 1; } From efec9f073cba3bc4bfe520bcdbd63bc2c42849d2 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Fri, 22 Jul 2016 09:54:30 -0400 Subject: [PATCH 05/21] modify otherinterfaces attribute and add status attribute --- xCAT-server/lib/xcat/plugins/switchdiscover.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index bc36b777e..cc91d76f4 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -1399,7 +1399,7 @@ sub switchsetup { my $node = $macmap->find_mac($mac,0); if (!$node) { send_msg($request, 0, "NO predefined switch matched this switch $dswitch with mac address $mac"); - $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$dswitch,"ip=$ip",'otherinterfaces=no predefined switch'] }, $sub_req, 0, 1); + $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$dswitch,"ip=$ip",'status=no predefined switch'] }, $sub_req, 0, 1); next; } @@ -1418,7 +1418,7 @@ sub switchsetup { if ( $stype =~ /BNT/ ) { $ret = config_BNT($dswitch, $node, $static_ip, $request, $sub_req); if ($ret == 1) { - xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'otherinterfaces=config failed, dhcp ip=$ip'] }, $sub_req, 0, 1); + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","otherinterfaces=dhcp:$ip",'status=config failed'] }, $sub_req, 0, 1); } } # Mellanox switches @@ -1427,13 +1427,13 @@ sub switchsetup { #NOTE: this expect routine will timeout after set up address $ret = config_Mellanox($dswitch, $node, $static_ip, $request, $sub_req); if ($ret == 1) { - xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'otherinterfaces=config failed, dhcp ip=$ip'] }, $sub_req, 0, 1); + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","otherinterfaces=dhcp:$ip",'status=config failed'] }, $sub_req, 0, 1); } } else { send_msg($request, 0, "the switch $dswitch type $stype is not support\n"); - $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","switchtype=$stype",'otherinterfaces=switch type is not supported yet, dhcp ip=$ip'] }, $sub_req, 0, 1); + $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","switchtype=$stype","otherinterfaces=dhcp:$ip",'status=switch type is not supported yet'] }, $sub_req, 0, 1); } # save for update mac address and remove node definition @@ -1492,7 +1492,7 @@ sub config_BNT { #send_msg($request, 0, Dumper($output)); #add default attribute for BNT switch - my $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=root','password=admin','protocol=telnet','switchtype=BNT','otherinterfaces='] }, $sub_req, 0, 1); + my $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=root','password=admin','protocol=telnet','switchtype=BNT','otherinterfaces=','status='] }, $sub_req, 0, 1); #send_msg($request, 0, Dumper($ret)); #set up hostname @@ -1598,7 +1598,7 @@ sub config_Mellanox { $myexp->soft_close(); #add default attribute for Mellanox switch - $output = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=admin','switchtype=Mellanox','otherinterfaces='] }, $sub_req, 0, 1); + $output = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=admin','switchtype=Mellanox','otherinterfaces=','status='] }, $sub_req, 0, 1); #send_msg($request, 0, Dumper($output)); From 843525e73b790c02aee8c280409f1eb6d099448c Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Fri, 29 Jul 2016 17:25:45 -0400 Subject: [PATCH 06/21] Restructure code flow for switch-based switch discovery --- .../lib/xcat/plugins/switchdiscover.pm | 224 +--------- xCAT-server/share/xcat/tools/configBNT | 403 ++++++++++++------ xCAT-server/share/xcat/tools/configMellanox | 230 ++++++++-- 3 files changed, 483 insertions(+), 374 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index cc91d76f4..e92612345 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -163,7 +163,7 @@ sub parse_args { ############################################# # Check for node range ############################################# - if ( scalar(@ARGV) eq 1 ) { + if ( scalar(@ARGV) == 1 ) { my @nodes = xCAT::NodeRange::noderange( @ARGV ); if (nodesmissed) { return (usage( "The following nodes are not defined in xCAT DB:\n " . join(',', nodesmissed))); @@ -456,7 +456,7 @@ sub process_request { if (exists($result->{$key}->{vendor})) { $vendor = $result->{$key}->{vendor}; } - if ($key != /nomac/) { + if ($key !~ /nomac/) { $mac = $key; } my $msg = sprintf $format, $ip, $name, $vendor, $key; @@ -472,11 +472,6 @@ sub process_request { } if (exists($globalopt{setup})) { - #discovered switches need to write to xcatdb before we can set them up - # It will be removed once we found predefine switch. - if (!exists($globalopt{w})) { - xCATdB($result, \%request, $sub_req); - } switchsetup($result, \%request, $sub_req); } @@ -1376,6 +1371,8 @@ sub switchsetup { my $static_ip; my $discover_switch; my @rmnodes; + my @BNTswitches; + my @MLNXswitches; #print Dumper($outhash); my $macmap = xCAT::MacMap->new(); @@ -1392,14 +1389,9 @@ sub switchsetup { # issue makehosts so we can use xdsh my $dswitch = get_hostname($outhash->{$mac}->{name}, $ip); - #add discovered switch to /etc/hosts - $output = xCAT::Utils->runxcmd({command => ["makehosts"], - node =>[$dswitch]}, $sub_req, 0, 1); - my $node = $macmap->find_mac($mac,0); if (!$node) { - send_msg($request, 0, "NO predefined switch matched this switch $dswitch with mac address $mac"); - $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$dswitch,"ip=$ip",'status=no predefined switch'] }, $sub_req, 0, 1); + send_msg($request, 0, "NO predefined switch matched this switch $dswitch with ip address $ip and mac address $mac"); next; } @@ -1416,209 +1408,35 @@ sub switchsetup { # BNT switches if ( $stype =~ /BNT/ ) { - $ret = config_BNT($dswitch, $node, $static_ip, $request, $sub_req); - if ($ret == 1) { - xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","otherinterfaces=dhcp:$ip",'status=config failed'] }, $sub_req, 0, 1); - } + push (@BNTswitches, $node); + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","otherinterfaces=$ip",'status=Matched',"mac=$mac",'switchtype=BNT','username=root','password=admin'] }, $sub_req, 0, 1); } # Mellanox switches elsif ( $stype =~ /Mellanox/ ) { - #set static ip address the mgmt0, we don't have EthSwitch yet, will use IBSwitch for now - #NOTE: this expect routine will timeout after set up address - $ret = config_Mellanox($dswitch, $node, $static_ip, $request, $sub_req); - if ($ret == 1) { - xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","otherinterfaces=dhcp:$ip",'status=config failed'] }, $sub_req, 0, 1); - } + push (@MLNXswitches, $node); + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","otherinterfaces=$ip",'status=Matched',"mac=$mac",'switchtype=Mellanox','username=admin'] }, $sub_req, 0, 1); } else { - send_msg($request, 0, "the switch $dswitch type $stype is not support\n"); - $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","switchtype=$stype","otherinterfaces=dhcp:$ip",'status=switch type is not supported yet'] }, $sub_req, 0, 1); + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","switchtype=$stype","otherinterfaces=$ip",'status=not supported',"mac=$mac"] }, $sub_req, 0, 1); } - - # save for update mac address and remove node definition - $discovered_switch->{$node}->{mac}=$mac; - push (@rmnodes, $dswitch); } - - #after switch ip address is setup to static ip - #remove discover switch definition - $output = xCAT::Utils->runxcmd({command => ["makehosts"], - node => \@rmnodes, - arg => ['-d'] }, $sub_req, 0, 1); - my $remove_nodes = join(",", @rmnodes); - my $ccmd = "rmdef $remove_nodes"; - $output = xCAT::Utils->runcmd($ccmd, 0); - #send_msg($request, 0, Dumper($output)); - #update mac address - my $mactab = xCAT::Table->new('mac'); - if ($mactab) { - $mactab->setNodesAttribs($discovered_switch); + if (@BNTswitches) { + my $bntsw = join(",",@BNTswitches); + send_msg($request, 0, "call to config BNT switches $bntsw\n"); + my $out = `/opt/xcat/share/xcat/tools/configBNT --range $bntsw --all`; + send_msg($request, 0, "output = $out\n"); + } + if (@MLNXswitches) { + my $mlnxsw = join(",",@MLNXswitches); + send_msg($request, 0, "call to config Mellanox switches $mlnxsw\n"); + my $out = `/opt/xcat/share/xcat/tools/configMellanox --range $mlnxsw --all`; + send_msg($request, 0, "output = $out\n"); } return; } -#-------------------------------------------------------------------------------- -=head3 config_BNT - config BNT switches - ---setup static ip address - ---setup hostname - ---set default user/password - Arguments: - dswitch: discovered switch - node: predefine switch - ip: static ip address - Returns: - result: -=cut -#-------------------------------------------------------------------------------- - -sub config_BNT { - my $dswitch=shift; - my $node = shift; - my $static_ip = shift; - my $request = shift; - my $sub_req = shift; - my $dshcmd; - my $ret; - - #xdsh switch-192-168-5-152 --devicetype EthSwitch::BNT - # "enable;configure terminal;show interface ip;interface ip 1;ip address 192.168.5.22" - $dshcmd="enable;configure terminal;show interface ip;interface ip 1;ip address $static_ip;exit;exit"; - $output = xCAT::Utils->runxcmd({command => ["xdsh"], - node =>[$dswitch], - arg => ["--devicetype", "EthSwitch::BNT", "$dshcmd"] }, $sub_req, 0, 1); - #send_msg($request, 0, Dumper($output)); - - #add default attribute for BNT switch - my $ret = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=root','password=admin','protocol=telnet','switchtype=BNT','otherinterfaces=','status='] }, $sub_req, 0, 1); - #send_msg($request, 0, Dumper($ret)); - - #set up hostname - $dshcmd="enable;configure terminal;hostname $node;write memory"; - $output = xCAT::Utils->runxcmd({command => ["xdsh"], - node =>[$node], - arg => ["--devicetype", "EthSwitch::BNT", "$dshcmd"] }, $sub_req, 0, 1); - if ($::RUNCMD_RC != 0) - { - send_msg($request, 0, "Failed to change hostname on $node"); - return 1; - } - - return 0; -} - -#-------------------------------------------------------------------------------- -=head3 config_Mellanox - config Mellanox switches - ---setup static ip address - ---setup hostname - ---set default user/password - Arguments: - dswitch: discovered switch - node: predefine switch - ip: static ip address - Returns: - result: -=cut -#-------------------------------------------------------------------------------- - -sub config_Mellanox { - my $dswitch=shift; - my $node = shift; - my $static_ip = shift; - my $request = shift; - my $sub_req = shift; - my $dshcmd; - my $mask; - - # get netmask from network table - my $nettab = xCAT::Table->new("networks"); - if ($nettab) { - my @nets = $nettab->getAllAttribs('net','mask'); - foreach my $net (@nets) { - if (xCAT::NetworkUtils::isInSameSubnet( $net->{'net'}, $ip, $net->{'mask'}, 0)) { - $mask=$net->{'mask'}; - } - } - } - - #set static ip address the mgmt0, we don't have EthSwitch yet, will use IBSwitch for now - #NOTE: this expect routine will timeout after set up address - - my $myexp = new Expect; - my $timeout = 10; - my $login_cmd = "ssh -ladmin $dswitch\r"; - my $first_prompt = "^.*>"; - my $config_prompt="^.*#"; - my $cfg_ip="no interface mgmt0 dhcp\r"; - my $cfg_ip1="interface mgmt0 ip address $static_ip $mask\r"; - - unless ($myexp->spawn($login_cmd)) - { - $myexp->soft_close(); - send_msg($request, 0, "Unable to run $login_cmd\n"); - next; - } - - my @result = $myexp->expect( - $timeout, - [ - "-re", $first_prompt, - sub { - $myexp->clear_accum(); - $myexp->send("enable\r"); - $myexp->clear_accum(); - $myexp->send("configure terminal\r"); - $myexp->clear_accum(); - $myexp->exp_continue(); - } - ], - [ - "-re", $config_prompt, - sub { - $myexp->clear_accum(); - $myexp->send($cfg_ip); - $myexp->send($cfg_ip1); - $myexp->clear_accum(); - $myexp->send("configuration write\r"); - $myexp->send("exit\r"); - $myexp->send("exit\r"); - } - ], - ); - if (defined($result[1])) - { - my $errmsg = $result[1]; - $myexp->soft_close(); - send_msg($request,0,"Failed expect command $errmsg\n"); - } - - $myexp->soft_close(); - - #add default attribute for Mellanox switch - $output = xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip",'username=admin','switchtype=Mellanox','otherinterfaces=','status='] }, $sub_req, 0, 1); - #send_msg($request, 0, Dumper($output)); - - - #set up hostname - $dshcmd="enable;configure terminal;hostname $node;configuration write"; - $output = xCAT::Utils->runxcmd({command => ["xdsh"], - node =>[$node], - arg => ["-l", "admin", "--devicetype", "IBSwitch::Mellanox", "$dshcmd"] }, $sub_req, 0, 1); - if ($::RUNCMD_RC != 0) - { - send_msg($request, 0, "Failed to change hostname on $node"); - return 1; - } - - return 0; -} - - - - 1; diff --git a/xCAT-server/share/xcat/tools/configBNT b/xCAT-server/share/xcat/tools/configBNT index 89e380103..c17271c52 100755 --- a/xCAT-server/share/xcat/tools/configBNT +++ b/xCAT-server/share/xcat/tools/configBNT @@ -4,9 +4,25 @@ # Configure Ethnet BNT switches #--------------------------------------------------------- +BEGIN +{ + $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; + $::XCATDIR = $ENV{'XCATDIR'} ? $ENV{'XCATDIR'} : '/etc/xcat'; +} +use lib "$::XCATROOT/lib/perl"; + + use strict; +use Socket; use Getopt::Long; use Expect; +use xCAT::Usage; +use xCAT::NodeRange; +use xCAT::NetworkUtils; +use xCAT::Utils; +use xCAT::Table; +use xCAT::MsgUtils; + my $args = join ' ', @ARGV; $::command = "$0 $args"; @@ -14,6 +30,10 @@ $::command = "$0 $args"; Getopt::Long::Configure("bundling"); $Getopt::Long::ignorecase = 0; +#global variables +my @nodes; +my @filternodes; + #--------------------------------------------------------- #Main @@ -22,13 +42,16 @@ $Getopt::Long::ignorecase = 0; if ( !GetOptions( 'h|help' => \$::HELP, - 'r|range=s' => \$::SWITCH, - 'p|port=s' => \$::PORT, - 'v|vlan=s' => \$::VLAN, - 'u|user=s' => \$::USER, - 'w|password=s' => \$::PASSWORD, - 'g|group=s' => \$::GROUP, + 'range=s' => \$::SWITCH, + 'port=s' => \$::PORT, + 'vlan=s' => \$::VLAN, + 'user=s' => \$::USER, + 'password=s' => \$::PASSWORD, + 'group=s' => \$::GROUP, 'snmp' => \$::SNMP, + 'ip' => \$::IP, + 'name' => \$::NAME, + 'all' => \$::ALL, ) ) { @@ -43,54 +66,146 @@ if ($::HELP) exit(0); } -my $switch; -if ($::SWITCH) -{ - $switch = $::SWITCH; +if ($::SWITCH) { + my @filternodes = xCAT::NodeRange::noderange( $::SWITCH ); + if (nodesmissed) { + my $nodenotdefined = join(',', nodesmissed); + xCAT::MsgUtils->message("I","The following nodes are not defined in xCAT DB: $nodenotdefined"); + } + foreach (@filternodes) { + push @nodes, $_; + } + unless (@nodes) { + xCAT::MsgUtils->message("E","No Valid Switch to process"); + exit(1); + } } else { + xCAT::MsgUtils->message("E","Invalid flag, please provide switches with --range"); &usage; exit(1); } +my $switches = join(",",@nodes); my $cmd; - my $vlan; my $port; -if ($::VLAN) -{ - if ($::PORT) { - $port = $::PORT; - } else { - print "Need port number to set up VLAN\n"; - &usage; - exit(1); - } - $vlan = $::VLAN; - print "Tagging VLAN=$vlan for $switch port $port\n"; - #create vlan - #tagged vlan - $cmd = `xdsh $switch --devicetype EthSwitch::BNT "enable;configure terminal;vlan $vlan;exit;interface port $port;switchport mode trunk;switchport trunk allowed vlan $vlan;write memory;exit;exit"`; +my $sub_req; +my $switch; +my $rc; + +if ($::ALL) { + config_ip(); + config_hostname(); + config_snmp(); } +if ($::IP) +{ + config_ip(); +} + +if ($::NAME) +{ + config_hostname(); +} +if ($::SNMP) +{ + config_snmp(); +} +if ($::VLAN) +{ + config_vlan(); +} + +sub config_ip { + + my $nodetab = xCAT::Table->new('hosts'); + my $nodehash = $nodetab->getNodesAttribs(\@nodes,['otherinterfaces']); + foreach my $switch (@nodes) { + print "change $switch to static ip address\n"; + my $dip= $nodehash->{$switch}->[0]->{otherinterfaces}; + + #get hostname + my $dswitch = xCAT::NetworkUtils->gethostname($dip); + + #if not defined, need to create one for xdsh to use + if (!$dswitch) { + my $ip_str = $dip; + $ip_str =~ s/\./\-/g; + $dswitch = "switch-$ip_str"; + #is there other way we can check if this node is defined in the xCATdb + $cmd = "lsdef $dswitch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) { + $cmd = "mkdef -t node -o $dswitch groups=switch ip=$dip switchtype=BNT username=root password=admin protocol=telnet nodetype=switch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + } + } + #check if it is in the /etc/hosts + my $output = `grep $dswitch /etc/hosts`; + if ( !$output ) { + $cmd = "makehosts $dswitch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + } + # verify if xdsh works + $cmd = "xdsh $dswitch --devicetype EthSwitch::BNT 'enable;configure terminal;exit' "; + $rc= xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) { + xCAT::MsgUtils->message("E","Couldn't communicate with $dswitch, $dip"); + next; + } + #change to static ip address + my $static_ip = xCAT::NetworkUtils->getipaddr($switch); + if (!$static_ip){ + xCAT::MsgUtils->message("E","static ip is not defined for $switch"); + next; + } + $cmd="xdsh $dswitch -t 10 --devicetype EthSwitch::BNT 'enable;configure terminal;show interface ip;interface ip 1;ip address $static_ip;exit;exit' "; + $rc= xCAT::Utils->runcmd($cmd, 0); + print "finish setup static ip address for $switch\n"; + + #update switch status + $cmd = "chdef $switch status=ip_configed otherinterface="; + $rc= xCAT::Utils->runcmd($cmd, 0); + + #remove discover switch from xCATdb and /etc/hosts + $cmd = "makehosts -d $dswitch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + $cmd = "rmdef $dswitch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + } +} + +sub config_hostname { + my $switchtab = xCAT::Table->new('switches'); + my $switchhash = $switchtab->getNodesAttribs(\@nodes,['sshusername','sshpassword']); + foreach my $switch (@nodes) { + my $user= $switchhash->{$switch}->[0]->{sshusername}; + my $pwd= $switchhash->{$switch}->[0]->{sshpassword}; + if ((!$user)||(!$pwd)) { + print "switch ssh username or password is not define, add default one\n"; + $cmd = "chdef $switch username=root password=admin"; + $rc= xCAT::Utils->runcmd($cmd, 0); + } + $cmd="xdsh $switch --devicetype EthSwitch::BNT 'enable;configure terminal;hostname $switch;write memory' "; + $rc= xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) { + xCAT::MsgUtils->message("E","Failed to setup hostname for $switch"); + next; + } + #update switch status + $cmd = "chdef $switch status=hostname_configed" ; + $rc= xCAT::Utils->runcmd($cmd, 0); + } +} + + #setup secure SNMP v3 -if ($::SNMP){ - my $mysw; - my $enable_cmd="enable\r"; - my $config_cmd="configure terminal\r"; - my $exit_cmd="exit\r"; - - my $pwd_prompt = "password: "; - my $sw_prompt = "$switch>"; - my $enable_prompt="$switch#"; - my $config_prompt="^.*\\\(config\\\)\#"; - - $mysw = new Expect; - my $timeout = 20; - my $login_cmd = "telnet $switch\r"; - my $passwd = "admin\r"; +sub config_snmp { my $snmp_user; my $snmp_passwd; my $snmp_group; + if ($::USER) { $snmp_user = $::USER; } else { @@ -107,99 +222,132 @@ if ($::SNMP){ } else { $snmp_group = "xcatgroup\r"; } - print "Setup SNMP server for user=$snmp_user, password=$snmp_passwd, group=$snmp_group\n"; - #create a SNMP user - my $cfg_user1="snmp-server user 5 name $snmp_user\r"; - my $cfg_user2="snmp-server user 5 authentication-protocol sha authentication-password\r"; - #create a SNMP group - my $cfg_group1="snmp-server group 5 group-name $snmp_group\r"; - my $cfg_group2="snmp-server group 5 user-name $snmp_user\r"; - my $cfg_group3="snmp-server group 5 security usm\r"; - #Add access permission - my $cfg_access1="snmp-server access 5 name $snmp_group\r"; - my $cfg_access2="snmp-server access 5 level authNoPriv\r"; - my $cfg_access3="snmp-server access 5 security usm\r"; - my $cfg_access4="snmp-server access 5 read-view iso\r"; - $mysw->slave->stty(qw(sane -echo)); + foreach my $switch (@nodes) { + my $mysw; + my $enable_cmd="enable\r"; + my $config_cmd="configure terminal\r"; + my $exit_cmd="exit\r"; - unless ($mysw->spawn($login_cmd)) - { + my $pwd_prompt = "password: "; + my $sw_prompt = "$switch>"; + my $enable_prompt="$switch#"; + my $config_prompt="^.*\\\(config\\\)\#"; + + $mysw = new Expect; + my $timeout = 20; + my $login_cmd = "telnet $switch\r"; + my $passwd = "admin\r"; + + print "Setup SNMP server for $switch\n"; + #create a SNMP user + my $cfg_user1="snmp-server user 5 name $snmp_user\r"; + my $cfg_user2="snmp-server user 5 authentication-protocol sha authentication-password\r"; + #create a SNMP group + my $cfg_group1="snmp-server group 5 group-name $snmp_group\r"; + my $cfg_group2="snmp-server group 5 user-name $snmp_user\r"; + my $cfg_group3="snmp-server group 5 security usm\r"; + #Add access permission + my $cfg_access1="snmp-server access 5 name $snmp_group\r"; + my $cfg_access2="snmp-server access 5 level authNoPriv\r"; + my $cfg_access3="snmp-server access 5 security usm\r"; + my $cfg_access4="snmp-server access 5 read-view iso\r"; + + $mysw->slave->stty(qw(sane -echo)); + + unless ($mysw->spawn($login_cmd)) + { + $mysw->soft_close(); + print "Unable to run $login_cmd\n"; + next; + } + my @result = $mysw->expect( + $timeout, + [ + $pwd_prompt, + sub { + $mysw->clear_accum(); + $mysw->send("$passwd\r"); + $mysw->clear_accum(); + $mysw->exp_continue(); + } + ], + [ + "-re", $sw_prompt, + sub { + $mysw->clear_accum(); + $mysw->send($enable_cmd); + $mysw->exp_continue(); + } + ], + [ + "-re", $enable_prompt, + sub { + $mysw->clear_accum(); + $mysw->send($config_cmd); + $mysw->exp_continue(); + } + ], + [ + "-re", $config_prompt, + sub { + $mysw->clear_accum(); + $mysw->send($cfg_user1); + $mysw->send($cfg_user2); + $mysw->send($passwd); + $mysw->send($snmp_passwd); + $mysw->send($snmp_passwd); + sleep 1; + $mysw->clear_accum(); + # create snmp group + $mysw->send($cfg_group1); + $mysw->send($cfg_group2); + $mysw->send($cfg_group3); + $mysw->clear_accum(); + $mysw->send($cfg_access1); + $mysw->send($cfg_access2); + $mysw->send($cfg_access3); + $mysw->send($cfg_access4); + $mysw->clear_accum(); + $mysw->send("write memory\r"); + $mysw->send($exit_cmd); + $mysw->send($exit_cmd); + } + ], + ); + ########################################## + # Expect error - report and quit + ########################################## + if (defined($result[1])) + { + my $errmsg = $result[1]; + $mysw->soft_close(); + print "Failed expect command $errmsg\n"; + exit(1); + } $mysw->soft_close(); - print "Unable to run $login_cmd\n"; - next; + + #update switch status + $cmd = "chdef $switch status=switch_configed" ; + $rc= xCAT::Utils->runcmd($cmd, 0); } - my @result = $mysw->expect( - $timeout, - [ - $pwd_prompt, - sub { - $mysw->clear_accum(); - $mysw->send("$passwd\r"); - $mysw->clear_accum(); - $mysw->exp_continue(); - } - ], - [ - "-re", $sw_prompt, - sub { - #print "$switch: sending enable command: $enable_cmd\n"; - $mysw->clear_accum(); - $mysw->send($enable_cmd); - $mysw->exp_continue(); - } - ], - [ - "-re", $enable_prompt, - sub { - #print "$switch: sending config command: $config_cmd\n"; - $mysw->clear_accum(); - $mysw->send($config_cmd); - $mysw->exp_continue(); - } - ], - [ - "-re", $config_prompt, - sub { - $mysw->clear_accum(); - $mysw->send($cfg_user1); - $mysw->send($cfg_user2); - $mysw->send($passwd); - $mysw->send($snmp_passwd); - $mysw->send($snmp_passwd); - sleep 1; - $mysw->clear_accum(); - # create snmp group - $mysw->send($cfg_group1); - $mysw->send($cfg_group2); - $mysw->send($cfg_group3); - $mysw->clear_accum(); - $mysw->send($cfg_access1); - $mysw->send($cfg_access2); - $mysw->send($cfg_access3); - $mysw->send($cfg_access4); - $mysw->clear_accum(); - $mysw->send("write memory\r"); - $mysw->send($exit_cmd); - $mysw->send($exit_cmd); - } - ], - ); - ########################################## - # Expect error - report and quit - ########################################## - if (defined($result[1])) - { - my $errmsg = $result[1]; - $mysw->soft_close(); - print "Failed expect command $errmsg\n"; +} + +sub config_vlan { + if ($::PORT) { + $port = $::PORT; + } else { + &usage; exit(1); } - $mysw->soft_close(); + $vlan = $::VLAN; + print "Tagging VLAN=$vlan for $switches port $port\n"; + #create vlan, tagged vlan + $cmd = `xdsh $switches --devicetype EthSwitch::BNT "enable;configure terminal;vlan $vlan;exit;interface port $port;switchport mode trunk;switchport trunk allowed vlan $vlan;write memory;exit;exit"`; - } + #--------------------------------------------------------- =head3 usage @@ -213,8 +361,11 @@ sub usage { print "Usage: configBNT [-?│-h│--help] - configBNT [--range switchnames] [-p|--port port] [-v|--vlan vlan] - configBNT [--range switchnames] [--snmp] [-u|--user snmp_user] [-w|--password snmp_password] [-g|--group snmp_group] + configBNT [--range switchnames] [--all] + configBNT [--range switchnames] [--ip] + configBNT [--range switchnames] [--name ] + configBNT [--range switchnames] [--snmp] [--user snmp_user] [--password snmp_password] [--group snmp_group] + configBNT [--range switchnames] [--port port] [--vlan vlan] \n"; } diff --git a/xCAT-server/share/xcat/tools/configMellanox b/xCAT-server/share/xcat/tools/configMellanox index 647a3c2d6..ebf8db8f5 100755 --- a/xCAT-server/share/xcat/tools/configMellanox +++ b/xCAT-server/share/xcat/tools/configMellanox @@ -4,9 +4,24 @@ # Configure Ethnet Mellonax switches #--------------------------------------------------------- +BEGIN +{ + $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; + $::XCATDIR = $ENV{'XCATDIR'} ? $ENV{'XCATDIR'} : '/etc/xcat'; +} +use lib "$::XCATROOT/lib/perl"; + + use strict; use Getopt::Long; use Expect; +use xCAT::Usage; +use xCAT::NodeRange; +use xCAT::NetworkUtils; +use xCAT::Utils; +use xCAT::Table; +use xCAT::MsgUtils; + my $args = join ' ', @ARGV; $::command = "$0 $args"; @@ -14,6 +29,10 @@ $::command = "$0 $args"; Getopt::Long::Configure("bundling"); $Getopt::Long::ignorecase = 0; +#global variables +my @nodes; +my @filternodes; + #--------------------------------------------------------- #Main @@ -21,10 +40,12 @@ $Getopt::Long::ignorecase = 0; # parse the options if ( !GetOptions( - 'h|help' => \$::HELP, - 'r|range=s' => \$::SWITCH, - 'u|user=s' => \$::USER, - 'i|ip=s' => \$::IP, + 'h|help' => \$::HELP, + 'range=s' => \$::SWITCH, + 'config' => \$::CONFIG, + 'ip' => \$::IP, + 'name' => \$::NAME, + 'all' => \$::ALL, ) ) { @@ -39,61 +60,177 @@ if ($::HELP) exit(0); } -my $switch; if ($::SWITCH) { - $switch = $::SWITCH; + my @filternodes = xCAT::NodeRange::noderange( $::SWITCH ); + if (nodesmissed) { + my $nodenotdefined = join(',', nodesmissed); + xCAT::MsgUtils->message("I","The following nodes are not defined in xCAT DB: $nodenotdefined"); + } + foreach (@filternodes) { + push @nodes, $_; + } + unless (@nodes) { + xCAT::MsgUtils->message("E","No Valid Switch to process"); + exit(1); + } } else { + xCAT::MsgUtils->message("E","Invalid flag, please provide switches with --range"); &usage; exit(1); } +my $switches = join(",",@nodes); my $user; - -if ($::USER) -{ - $user = $::USER; -} else { - &usage; - exit(1); -} - -my $ip; -if ($::IP) -{ - $ip = $::IP; -} else { - &usage; - exit(1); -} - - my $cmd; +my $switch; +my $rc; +my $master; -#default root/password and protcol for Mellonax switch -$cmd = `chtab switch=$switch switches.sshusername=$user`; -print $cmd; +if ($::ALL) { + config_ip(); + config_hostname(); + run_rspconfig(); +} +if ($::IP) { + config_ip(); +} -#call rspconfig command to setup switch -#enable ssh -$cmd=`rspconfig $switch sshcfg=enable`; -print $cmd; +if ($::NAME) { + config_hostname(); +} -#enable snmp function on the switch -$cmd=`rspconfig $switch snmpcfg=enable`; -print $cmd; -#enable the snmp trap -$cmd=`rspconfig $switch alert=enable`; -print $cmd; +if ($::CONFIG) +{ + run_rspconfig(); +} -#Logging destination: -$cmd=`rspconfig $switch logdest=$ip`; -print $cmd; -#config ntp -$cmd = `xdsh $switch -l $user --devicetype IBSwitch::Mellanox "enable;configure terminal;ntp enable;ntpdate $ip; ntp server $ip;configuration write;show ntp" `; -print $cmd; +sub config_ip { + # get host table for otherinterfaces + my $nodetab = xCAT::Table->new('hosts'); + my $nodehash = $nodetab->getNodesAttribs(\@nodes,['otherinterfaces']); + # get netmask from network table + my $nettab = xCAT::Table->new("networks"); + my @nets; + if ($nettab) { + @nets = $nettab->getAllAttribs('net','mask'); + } + foreach my $switch (@nodes) { + print "change $switch to static ip address\n"; + my $dip= $nodehash->{$switch}->[0]->{otherinterfaces}; + + #get hostname + my $dswitch = xCAT::NetworkUtils->gethostname($dip); + + #if not defined, need to create one for xdsh to use + if (!$dswitch) { + my $ip_str = $dip; + $ip_str =~ s/\./\-/g; + $dswitch = "switch-$ip_str"; + #is there other way we can check if this node is defined in the xCATdb + $cmd = "lsdef $dswitch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) { + $cmd = "mkdef -t node -o $dswitch groups=switch ip=$dip switchtype=Mellanox username=admin nodetype=switch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + } + } + #check if it is in the /etc/hosts + my $output = `grep $dswitch /etc/hosts`; + if ( !$output ) { + $cmd = "makehosts $dswitch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + } + # verify if xdsh works + $cmd = "xdsh $dswitch -l admin --devicetype IBSwitch::Mellanox 'enable;configure terminal;exit' "; + $rc= xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) { + xCAT::MsgUtils->message("E","Couldn't communicate with $dswitch, $dip"); + next; + } + #change to static ip address + my $static_ip = xCAT::NetworkUtils->getipaddr($switch); + if (!$static_ip){ + xCAT::MsgUtils->message("E","static ip is not defined for $switch"); + next; + } + #get netmask + my $mask; + foreach my $net (@nets) { + if (xCAT::NetworkUtils::isInSameSubnet( $net->{'net'}, $static_ip, $net->{'mask'}, 0)) { + $mask=$net->{'mask'}; + } + } + + $cmd="xdsh $dswitch -t 10 -l admin --devicetype IBSwitch::Mellanox 'enable;configure terminal;no interface mgmt0 dhcp;interface mgmt0 ip address $static_ip $mask;configuration write;exit;exit' "; + $rc= xCAT::Utils->runcmd($cmd, 0); + + #update switch status + $cmd = "chdef $switch status=ip_configed otherinterface="; + $rc= xCAT::Utils->runcmd($cmd, 0); + + #remove discover switch from xCATdb and /etc/hosts + $cmd = "makehosts -d $dswitch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + $cmd = "rmdef $dswitch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + } +} + +sub config_hostname { + my $switchtab = xCAT::Table->new('switches'); + my $switchhash = $switchtab->getNodesAttribs(\@nodes,['sshusername']); + foreach my $switch (@nodes) { + my $user= $switchhash->{$switch}->[0]->{sshusername}; + if (!$user) { + print "switch ssh username is not defined, add default one\n"; + $cmd = "chdef $switch username=admin"; + $rc= xCAT::Utils->runcmd($cmd, 0); + $user="admin"; + } + $cmd="xdsh $switch -l $user --devicetype IBSwitch::Mellanox 'enable;configure terminal;hostname $switch;configuration write' "; + $rc= xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) { + xCAT::MsgUtils->message("E","Failed to setup hostname for $switch"); + next; + } + #update switch status + $cmd = "chdef $switch status=hostname_configed" ; + $rc= xCAT::Utils->runcmd($cmd, 0); + } +} + +sub run_rspconfig { + my $switchtab = xCAT::Table->new('switches'); + my $switchhash = $switchtab->getNodesAttribs(\@nodes,['sshusername']); + $master = `hostname -i`; + print "master=$master\n"; + foreach my $switch (@nodes) { + my $user= $switchhash->{$switch}->[0]->{sshusername}; + #call rspconfig command to setup switch + #enable ssh + $cmd=`rspconfig $switch sshcfg=enable`; + + #enable snmp function on the switch + $cmd=`rspconfig $switch snmpcfg=enable`; + + #enable the snmp trap + $cmd=`rspconfig $switch alert=enable`; + + #Logging destination: + $cmd=`rspconfig $switch logdest=$master`; + + #config ntp + $cmd = `xdsh $switch -l $user --devicetype IBSwitch::Mellanox "enable;configure terminal;ntp enable;ntpdate $master; ntp server $master;configuration write;show ntp" `; + + #update switch status + $cmd = "chdef $switch status=switch_configed" ; + $rc= xCAT::Utils->runcmd($cmd, 0); + } + +} #--------------------------------------------------------- @@ -108,7 +245,10 @@ sub usage { print "Usage: configMellonax [-?│-h│--help] - configMellonax [--range switchnames] [-u|--user sshusername] [-i|--ip xcatMN_ip_address] + configMellonax [--range switchnames] [--all] + configMellonax [--range switchnames] [--ip] + configMellonax [--range switchnames] [--name] + configMellonax [--range switchnames] [--config] \n"; } From 5d4d0d169e1bf1dc17b402e2d73444cfbbf7ddab Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Tue, 2 Aug 2016 22:10:45 -0400 Subject: [PATCH 07/21] Modify code from code review --- .../lib/xcat/plugins/switchdiscover.pm | 50 +++----- xCAT-server/share/xcat/tools/configBNT | 115 +++++++++--------- xCAT-server/share/xcat/tools/configMellanox | 91 +++++++------- 3 files changed, 122 insertions(+), 134 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index e92612345..8d90f8024 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -1133,14 +1133,14 @@ sub get_hostname { #-------------------------------------------------------------------------------- sub get_switchtype { my $vendor = shift; - my $key; + my $key = "Not support"; my $search_string = join '|', keys(%global_switch_type); if ($vendor =~ /($search_string)/) { $key = $1; return $global_switch_type{$key}; } else { - return $vendor; + return $key; } } @@ -1370,9 +1370,7 @@ sub switchsetup { my $dshcmd; my $static_ip; my $discover_switch; - my @rmnodes; - my @BNTswitches; - my @MLNXswitches; + my $nodes_to_config; #print Dumper($outhash); my $macmap = xCAT::MacMap->new(); @@ -1402,39 +1400,25 @@ sub switchsetup { if (exists($globalopt{verbose})) { send_msg($request, 0, "Found Discovery switch $dswitch, $ip, $mac with predefine switch $node, $static_ip $stype switch\n" ); } + xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"otherinterfaces=$ip",'status=Matched',"mac=$mac","switchtype=$stype","usercomment=$vendor"] }, $sub_req, 0, 1); - #run xdsh command to set discover ip address to static ip address - #each switch type has different CLI for setup ip address + push (@{$nodes_to_config->{$stype}}, $node); + } - # BNT switches - if ( $stype =~ /BNT/ ) { - push (@BNTswitches, $node); - xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","otherinterfaces=$ip",'status=Matched',"mac=$mac",'switchtype=BNT','username=root','password=admin'] }, $sub_req, 0, 1); - } - # Mellanox switches - elsif ( $stype =~ /Mellanox/ ) { - push (@MLNXswitches, $node); - xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","otherinterfaces=$ip",'status=Matched',"mac=$mac",'switchtype=Mellanox','username=admin'] }, $sub_req, 0, 1); - - } - else { - xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"ip=$static_ip","switchtype=$stype","otherinterfaces=$ip",'status=not supported',"mac=$mac"] }, $sub_req, 0, 1); + foreach my $mytype (keys %$nodes_to_config) { + my $config_script = "$::XCATROOT/shart/xcat/tools/config".$mytype; + if (-r -x $config_script) { + my $switches = join(",",@{${nodes_to_config}->{$mytype}}); + send_msg($request, 0, "call to config $mytype switches $switches\n"); + my $out = `$config_script --switches $switches --all`; + send_msg($request, 0, "output = $out\n"); + } else { + send_msg($request, 0, "the switch type $mytype is not support yet\n"); } } - - if (@BNTswitches) { - my $bntsw = join(",",@BNTswitches); - send_msg($request, 0, "call to config BNT switches $bntsw\n"); - my $out = `/opt/xcat/share/xcat/tools/configBNT --range $bntsw --all`; - send_msg($request, 0, "output = $out\n"); - } - if (@MLNXswitches) { - my $mlnxsw = join(",",@MLNXswitches); - send_msg($request, 0, "call to config Mellanox switches $mlnxsw\n"); - my $out = `/opt/xcat/share/xcat/tools/configMellanox --range $mlnxsw --all`; - send_msg($request, 0, "output = $out\n"); - } + return; + } diff --git a/xCAT-server/share/xcat/tools/configBNT b/xCAT-server/share/xcat/tools/configBNT index c17271c52..e3b3d62cc 100755 --- a/xCAT-server/share/xcat/tools/configBNT +++ b/xCAT-server/share/xcat/tools/configBNT @@ -23,10 +23,6 @@ use xCAT::Utils; use xCAT::Table; use xCAT::MsgUtils; - -my $args = join ' ', @ARGV; -$::command = "$0 $args"; - Getopt::Long::Configure("bundling"); $Getopt::Long::ignorecase = 0; @@ -41,17 +37,17 @@ my @filternodes; # parse the options if ( !GetOptions( - 'h|help' => \$::HELP, - 'range=s' => \$::SWITCH, + 'h|help' => \$::HELP, + 'switches=s' => \$::SWITCH, 'port=s' => \$::PORT, 'vlan=s' => \$::VLAN, 'user=s' => \$::USER, 'password=s' => \$::PASSWORD, 'group=s' => \$::GROUP, - 'snmp' => \$::SNMP, - 'ip' => \$::IP, - 'name' => \$::NAME, - 'all' => \$::ALL, + 'snmp' => \$::SNMP, + 'ip' => \$::IP, + 'name' => \$::NAME, + 'all' => \$::ALL, ) ) { @@ -72,15 +68,22 @@ if ($::SWITCH) { my $nodenotdefined = join(',', nodesmissed); xCAT::MsgUtils->message("I","The following nodes are not defined in xCAT DB: $nodenotdefined"); } - foreach (@filternodes) { - push @nodes, $_; + # check switch type + my $switchestab = xCAT::Table->new('switches'); + my $switches_hash = $switchestab->getNodesAttribs(\@filternodes,['switchtype']); + foreach my $fsw (@filternodes) { + if (($switches_hash->{$fsw}->[0]->{switchtype}) =~ /BNT/) { + push @nodes, $fsw; + } else { + xCAT::MsgUtils->message("E","The $fsw is not BNT switch, will not config"); + } } unless (@nodes) { xCAT::MsgUtils->message("E","No Valid Switch to process"); exit(1); } } else { - xCAT::MsgUtils->message("E","Invalid flag, please provide switches with --range"); + xCAT::MsgUtils->message("E","Invalid flag, please provide switches with --switches"); &usage; exit(1); } @@ -90,25 +93,18 @@ my $cmd; my $vlan; my $port; my $sub_req; -my $switch; my $rc; -if ($::ALL) { - config_ip(); - config_hostname(); - config_snmp(); -} - -if ($::IP) +if (($::IP) || ($::ALL)) { config_ip(); } -if ($::NAME) +if (($::NAME) || ($::ALL)) { config_hostname(); } -if ($::SNMP) +if (($::SNMP) || ($::ALL)) { config_snmp(); } @@ -118,12 +114,14 @@ if ($::VLAN) } sub config_ip { - + my @config_switches; + my @discover_switches; my $nodetab = xCAT::Table->new('hosts'); - my $nodehash = $nodetab->getNodesAttribs(\@nodes,['otherinterfaces']); + my $nodehash = $nodetab->getNodesAttribs(\@nodes,['ip','otherinterfaces']); foreach my $switch (@nodes) { print "change $switch to static ip address\n"; my $dip= $nodehash->{$switch}->[0]->{otherinterfaces}; + my $static_ip= $nodehash->{$switch}->[0]->{ip}; #get hostname my $dswitch = xCAT::NetworkUtils->gethostname($dip); @@ -133,20 +131,12 @@ sub config_ip { my $ip_str = $dip; $ip_str =~ s/\./\-/g; $dswitch = "switch-$ip_str"; - #is there other way we can check if this node is defined in the xCATdb - $cmd = "lsdef $dswitch"; - $rc= xCAT::Utils->runcmd($cmd, 0); - if ($::RUNCMD_RC != 0) { - $cmd = "mkdef -t node -o $dswitch groups=switch ip=$dip switchtype=BNT username=root password=admin protocol=telnet nodetype=switch"; - $rc= xCAT::Utils->runcmd($cmd, 0); - } - } - #check if it is in the /etc/hosts - my $output = `grep $dswitch /etc/hosts`; - if ( !$output ) { - $cmd = "makehosts $dswitch"; - $rc= xCAT::Utils->runcmd($cmd, 0); } + $cmd = "chdef -t node -o $dswitch groups=switch ip=$dip switchtype=BNT username=root password=admin protocol=telnet nodetype=switch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + $cmd = "makehosts $dswitch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + # verify if xdsh works $cmd = "xdsh $dswitch --devicetype EthSwitch::BNT 'enable;configure terminal;exit' "; $rc= xCAT::Utils->runcmd($cmd, 0); @@ -154,29 +144,30 @@ sub config_ip { xCAT::MsgUtils->message("E","Couldn't communicate with $dswitch, $dip"); next; } - #change to static ip address - my $static_ip = xCAT::NetworkUtils->getipaddr($switch); - if (!$static_ip){ - xCAT::MsgUtils->message("E","static ip is not defined for $switch"); - next; - } $cmd="xdsh $dswitch -t 10 --devicetype EthSwitch::BNT 'enable;configure terminal;show interface ip;interface ip 1;ip address $static_ip;exit;exit' "; $rc= xCAT::Utils->runcmd($cmd, 0); print "finish setup static ip address for $switch\n"; - + push (@discover_switches, $dswitch); + push (@config_switches, $switch); + } + if (@config_switches) { #update switch status - $cmd = "chdef $switch status=ip_configed otherinterface="; + my $csw = join(",",@config_switches); + $cmd = "chdef $csw status=ip_configed otherinterfaces="; $rc= xCAT::Utils->runcmd($cmd, 0); - + } + if (@discover_switches) { + my $dsw = join(",",@discover_switches); #remove discover switch from xCATdb and /etc/hosts - $cmd = "makehosts -d $dswitch"; + $cmd = "makehosts -d $dsw"; $rc= xCAT::Utils->runcmd($cmd, 0); - $cmd = "rmdef $dswitch"; + $cmd = "rmdef $dsw"; $rc= xCAT::Utils->runcmd($cmd, 0); } } sub config_hostname { + my @config_switches; my $switchtab = xCAT::Table->new('switches'); my $switchhash = $switchtab->getNodesAttribs(\@nodes,['sshusername','sshpassword']); foreach my $switch (@nodes) { @@ -193,8 +184,12 @@ sub config_hostname { xCAT::MsgUtils->message("E","Failed to setup hostname for $switch"); next; } + push (@config_switches, $switch); + } + if (@config_switches) { #update switch status - $cmd = "chdef $switch status=hostname_configed" ; + my $csw = join(",",@config_switches); + $cmd = "chdef $csw status=hostname_configed" ; $rc= xCAT::Utils->runcmd($cmd, 0); } } @@ -205,6 +200,7 @@ sub config_snmp { my $snmp_user; my $snmp_passwd; my $snmp_group; + my @config_switches; if ($::USER) { $snmp_user = $::USER; @@ -326,9 +322,14 @@ sub config_snmp { exit(1); } $mysw->soft_close(); - + push (@config_switches, $switch); + } + if (@config_switches) { #update switch status - $cmd = "chdef $switch status=switch_configed" ; + my $csw = join(",",@config_switches); + $cmd = "chdef $csw status=switch_configed" ; + $rc= xCAT::Utils->runcmd($cmd, 0); + $cmd = "chtab switch=$csw switches.snmpversion=3 switches.auth=sha switches.username=$snmp_user switches.password=$snmp_passwd" ; $rc= xCAT::Utils->runcmd($cmd, 0); } } @@ -361,11 +362,11 @@ sub usage { print "Usage: configBNT [-?│-h│--help] - configBNT [--range switchnames] [--all] - configBNT [--range switchnames] [--ip] - configBNT [--range switchnames] [--name ] - configBNT [--range switchnames] [--snmp] [--user snmp_user] [--password snmp_password] [--group snmp_group] - configBNT [--range switchnames] [--port port] [--vlan vlan] + configBNT [--switches switchnames] [--all] + configBNT [--switches switchnames] [--ip] + configBNT [--switches switchnames] [--name ] + configBNT [--switches switchnames] [--snmp] [--user snmp_user] [--password snmp_password] [--group snmp_group] + configBNT [--switches switchnames] [--port port] [--vlan vlan] \n"; } diff --git a/xCAT-server/share/xcat/tools/configMellanox b/xCAT-server/share/xcat/tools/configMellanox index ebf8db8f5..bc3bfc7c2 100755 --- a/xCAT-server/share/xcat/tools/configMellanox +++ b/xCAT-server/share/xcat/tools/configMellanox @@ -22,10 +22,6 @@ use xCAT::Utils; use xCAT::Table; use xCAT::MsgUtils; - -my $args = join ' ', @ARGV; -$::command = "$0 $args"; - Getopt::Long::Configure("bundling"); $Getopt::Long::ignorecase = 0; @@ -41,7 +37,7 @@ my @filternodes; if ( !GetOptions( 'h|help' => \$::HELP, - 'range=s' => \$::SWITCH, + 'switches=s' => \$::SWITCH, 'config' => \$::CONFIG, 'ip' => \$::IP, 'name' => \$::NAME, @@ -67,8 +63,15 @@ if ($::SWITCH) my $nodenotdefined = join(',', nodesmissed); xCAT::MsgUtils->message("I","The following nodes are not defined in xCAT DB: $nodenotdefined"); } - foreach (@filternodes) { - push @nodes, $_; + # check switch type + my $switchestab = xCAT::Table->new('switches'); + my $switches_hash = $switchestab->getNodesAttribs(\@filternodes,['switchtype']); + foreach my $fsw (@filternodes) { + if (($switches_hash->{$fsw}->[0]->{switchtype}) =~ /Mellanox/) { + push @nodes, $fsw; + } else { + xCAT::MsgUtils->message("E","The $fsw is not BNT switch, will not config"); + } } unless (@nodes) { xCAT::MsgUtils->message("E","No Valid Switch to process"); @@ -83,34 +86,29 @@ if ($::SWITCH) my $switches = join(",",@nodes); my $user; my $cmd; -my $switch; my $rc; my $master; -if ($::ALL) { - config_ip(); - config_hostname(); - run_rspconfig(); -} -if ($::IP) { +if (($::IP) || ($::ALL)) { config_ip(); } -if ($::NAME) { +if (($::NAME) || ($::ALL)) { config_hostname(); } -if ($::CONFIG) -{ +if (($::CONFIG) || ($::ALL)) { run_rspconfig(); } sub config_ip { + my @config_switches; + my @discover_switches; # get host table for otherinterfaces my $nodetab = xCAT::Table->new('hosts'); - my $nodehash = $nodetab->getNodesAttribs(\@nodes,['otherinterfaces']); + my $nodehash = $nodetab->getNodesAttribs(\@nodes,['ip','otherinterfaces']); # get netmask from network table my $nettab = xCAT::Table->new("networks"); my @nets; @@ -120,29 +118,23 @@ sub config_ip { foreach my $switch (@nodes) { print "change $switch to static ip address\n"; my $dip= $nodehash->{$switch}->[0]->{otherinterfaces}; + my $static_ip= $nodehash->{$switch}->[0]->{ip}; #get hostname my $dswitch = xCAT::NetworkUtils->gethostname($dip); + print "dip=$dip, static=$static_ip, dsw=$dswitch\n"; #if not defined, need to create one for xdsh to use if (!$dswitch) { my $ip_str = $dip; $ip_str =~ s/\./\-/g; $dswitch = "switch-$ip_str"; - #is there other way we can check if this node is defined in the xCATdb - $cmd = "lsdef $dswitch"; - $rc= xCAT::Utils->runcmd($cmd, 0); - if ($::RUNCMD_RC != 0) { - $cmd = "mkdef -t node -o $dswitch groups=switch ip=$dip switchtype=Mellanox username=admin nodetype=switch"; - $rc= xCAT::Utils->runcmd($cmd, 0); - } - } - #check if it is in the /etc/hosts - my $output = `grep $dswitch /etc/hosts`; - if ( !$output ) { - $cmd = "makehosts $dswitch"; - $rc= xCAT::Utils->runcmd($cmd, 0); } + $cmd = "chdef -t node -o $dswitch groups=switch ip=$dip switchtype=Mellanox username=admin nodetype=switch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + $cmd = "makehosts $dswitch"; + $rc= xCAT::Utils->runcmd($cmd, 0); + # verify if xdsh works $cmd = "xdsh $dswitch -l admin --devicetype IBSwitch::Mellanox 'enable;configure terminal;exit' "; $rc= xCAT::Utils->runcmd($cmd, 0); @@ -150,12 +142,6 @@ sub config_ip { xCAT::MsgUtils->message("E","Couldn't communicate with $dswitch, $dip"); next; } - #change to static ip address - my $static_ip = xCAT::NetworkUtils->getipaddr($switch); - if (!$static_ip){ - xCAT::MsgUtils->message("E","static ip is not defined for $switch"); - next; - } #get netmask my $mask; foreach my $net (@nets) { @@ -166,20 +152,29 @@ sub config_ip { $cmd="xdsh $dswitch -t 10 -l admin --devicetype IBSwitch::Mellanox 'enable;configure terminal;no interface mgmt0 dhcp;interface mgmt0 ip address $static_ip $mask;configuration write;exit;exit' "; $rc= xCAT::Utils->runcmd($cmd, 0); + push (@discover_switches, $dswitch); + push (@config_switches, $switch); + } + if (@config_switches) { #update switch status - $cmd = "chdef $switch status=ip_configed otherinterface="; + my $csw = join(",",@config_switches); + $cmd = "chdef $csw status=ip_configed otherinterfaces="; $rc= xCAT::Utils->runcmd($cmd, 0); - + } + + if (@discover_switches) { + my $dsw = join(",",@discover_switches); #remove discover switch from xCATdb and /etc/hosts - $cmd = "makehosts -d $dswitch"; + $cmd = "makehosts -d $dsw"; $rc= xCAT::Utils->runcmd($cmd, 0); - $cmd = "rmdef $dswitch"; + $cmd = "rmdef $dsw"; $rc= xCAT::Utils->runcmd($cmd, 0); } } sub config_hostname { + my @config_switches; my $switchtab = xCAT::Table->new('switches'); my $switchhash = $switchtab->getNodesAttribs(\@nodes,['sshusername']); foreach my $switch (@nodes) { @@ -196,13 +191,18 @@ sub config_hostname { xCAT::MsgUtils->message("E","Failed to setup hostname for $switch"); next; } + push (@config_switches, $switch); + } + if (@config_switches) { #update switch status - $cmd = "chdef $switch status=hostname_configed" ; + my $csw = join(",",@config_switches); + $cmd = "chdef $csw status=hostname_configed" ; $rc= xCAT::Utils->runcmd($cmd, 0); } } sub run_rspconfig { + my @config_switches; my $switchtab = xCAT::Table->new('switches'); my $switchhash = $switchtab->getNodesAttribs(\@nodes,['sshusername']); $master = `hostname -i`; @@ -224,9 +224,12 @@ sub run_rspconfig { #config ntp $cmd = `xdsh $switch -l $user --devicetype IBSwitch::Mellanox "enable;configure terminal;ntp enable;ntpdate $master; ntp server $master;configuration write;show ntp" `; - + push (@config_switches, $switch); + } + if (@config_switches) { #update switch status - $cmd = "chdef $switch status=switch_configed" ; + my $csw = join(",",@config_switches); + $cmd = "chdef $csw status=switch_configed" ; $rc= xCAT::Utils->runcmd($cmd, 0); } From c72abd740991008e427712797e7a15c9d9acebaf Mon Sep 17 00:00:00 2001 From: caomengmeng Date: Wed, 3 Aug 2016 04:57:30 -0400 Subject: [PATCH 08/21] completed --- .../guides/admin-guides/references/man1/xcattest.1.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/guides/admin-guides/references/man1/xcattest.1.rst b/docs/source/guides/admin-guides/references/man1/xcattest.1.rst index e09fd2e9e..eaa39e7e3 100644 --- a/docs/source/guides/admin-guides/references/man1/xcattest.1.rst +++ b/docs/source/guides/admin-guides/references/man1/xcattest.1.rst @@ -58,7 +58,7 @@ OPTIONS \ **-b**\ \ *case bundle list*\ - Comma separated list of test cases bundle files, each test cases bundle can contain multiple lines and each line for one test case name. + Comma separated list of test cases bundle files, each test cases bundle can contain multiple lines and each line for one test case name.The bundle files should be listed in: /opt/xcat/share/xcat/tools/autotest/bundle. @@ -136,7 +136,7 @@ EXAMPLES .. code-block:: perl - xcattest -c /tmp/config -c rpower + xcattest -f /tmp/config -c rpower @@ -148,7 +148,7 @@ EXAMPLES .. code-block:: perl - xcattest -l > /tmp/custom.bundle + xcattest -l > /opt/xcat/share/xcat/tools/autotest/bundle/custom.bundle Modify custom.bundle xcattest -b custom.bundle From 4b859aea8a04a355f7a797d2d56aa9db8be2d3f3 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Wed, 3 Aug 2016 09:25:28 -0400 Subject: [PATCH 09/21] more modification... --- xCAT-server/lib/xcat/plugins/switchdiscover.pm | 6 +----- xCAT-server/share/xcat/tools/configBNT | 4 +--- xCAT-server/share/xcat/tools/configMellanox | 10 +++++----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index 8d90f8024..12e552556 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -459,7 +459,7 @@ sub process_request { if ($key !~ /nomac/) { $mac = $key; } - my $msg = sprintf $format, $ip, $name, $vendor, $key; + my $msg = sprintf $format, $ip, $name, $vendor, $mac; send_msg(\%request, 0, $msg); } } @@ -1363,11 +1363,7 @@ sub switchsetup { my $outhash = shift; my $request = shift; my $sub_req = shift; - my $ret; my @switchnode = (); - my $switchInfo; - my $output; - my $dshcmd; my $static_ip; my $discover_switch; my $nodes_to_config; diff --git a/xCAT-server/share/xcat/tools/configBNT b/xCAT-server/share/xcat/tools/configBNT index e3b3d62cc..13b8f67f5 100755 --- a/xCAT-server/share/xcat/tools/configBNT +++ b/xCAT-server/share/xcat/tools/configBNT @@ -327,9 +327,7 @@ sub config_snmp { if (@config_switches) { #update switch status my $csw = join(",",@config_switches); - $cmd = "chdef $csw status=switch_configed" ; - $rc= xCAT::Utils->runcmd($cmd, 0); - $cmd = "chtab switch=$csw switches.snmpversion=3 switches.auth=sha switches.username=$snmp_user switches.password=$snmp_passwd" ; + $cmd = "chdef $csw status=switch_configed snmpversion=3 snmpauth=sha snmpusername=$snmp_user snmppassword=$snmp_passwd"; $rc= xCAT::Utils->runcmd($cmd, 0); } } diff --git a/xCAT-server/share/xcat/tools/configMellanox b/xCAT-server/share/xcat/tools/configMellanox index bc3bfc7c2..2af72ec18 100755 --- a/xCAT-server/share/xcat/tools/configMellanox +++ b/xCAT-server/share/xcat/tools/configMellanox @@ -78,7 +78,7 @@ if ($::SWITCH) exit(1); } } else { - xCAT::MsgUtils->message("E","Invalid flag, please provide switches with --range"); + xCAT::MsgUtils->message("E","Invalid flag, please provide switches with --switches"); &usage; exit(1); } @@ -248,10 +248,10 @@ sub usage { print "Usage: configMellonax [-?│-h│--help] - configMellonax [--range switchnames] [--all] - configMellonax [--range switchnames] [--ip] - configMellonax [--range switchnames] [--name] - configMellonax [--range switchnames] [--config] + configMellonax [--switches switchnames] [--all] + configMellonax [--switches switchnames] [--ip] + configMellonax [--switches switchnames] [--name] + configMellonax [--switches switchnames] [--config] \n"; } From c5121bce0f7299e3a54f3115e878c27b8177d3c6 Mon Sep 17 00:00:00 2001 From: Jesse Hanley Date: Wed, 3 Aug 2016 23:08:04 -0400 Subject: [PATCH 10/21] Added support for remote repos in pkgdir (#1614) This allows for remote repositories to be used for image creation. --- xCAT-server/share/xcat/netboot/rh/genimage | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index 9174f59a4..0879cabb9 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -265,12 +265,17 @@ unless ($onlyinitrd) { @yumdirs = (); my @pkgdirs = split(",", $srcdir); + my @pkgdir_internet; #Put all of the http mirrors in this array my $dir; foreach $dir (@pkgdirs) { + if ($dir =~ /^http.*/) { + push @pkgdir_internet, $dir; + } else { find(\&isyumdir, <$dir/>); if (!grep /$dir/, @yumdirs) { print "The repository for $dir should be created before running the genimge. Try to run [createrepo $dir].\n"; } + } } # Add the dir for kernel rpm to be installed @@ -280,8 +285,8 @@ unless ($onlyinitrd) { print "The repository for $kerneldir should be created before running the genimge. Try to run [createrepo $kerneldir].\n"; } } - unless (scalar(@yumdirs)) { - print "Need $installroot/$osver/$arch/ available from a system that has ran copycds on $osver $arch\n"; + unless (scalar(@yumdirs) || scalar(@pkgdir_internet)) { + print "Need $installroot/$osver/$arch/ available from a system that has ran copycds on $osver $arch or correct web repo\n"; exit 1; } @@ -300,6 +305,10 @@ unless ($onlyinitrd) { print $yumconfig "[$osver-$arch-$repnum]\nname=$osver-$arch-$repnum\nbaseurl=file://$srcdir\ngpgpcheck=0\n\n"; $repnum += 1; } + foreach $srcdir (@pkgdir_internet) { + print $yumconfig "[$osver-$arch-$repnum]\nname=$osver-$arch-$repnum\nbaseurl=$srcdir\ngpgpcheck=0\n\n"; + $repnum += 1; + } $repnum -= 1; close($yumconfig); mkpath "$rootimg_dir/etc"; From 9ff2f2b50a2c357faaee81f40118f78ded7370a7 Mon Sep 17 00:00:00 2001 From: chenglch Date: Thu, 4 Aug 2016 02:20:14 -0400 Subject: [PATCH 11/21] Revert "Propagate signal via ssh even though pipe broken can not be detected" --- perl-xCAT/xCAT/SSH.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/perl-xCAT/xCAT/SSH.pm b/perl-xCAT/xCAT/SSH.pm index c1de602af..182671abb 100644 --- a/perl-xCAT/xCAT/SSH.pm +++ b/perl-xCAT/xCAT/SSH.pm @@ -75,7 +75,6 @@ sub remote_shell_command { if ($ssh_version eq 'OpenSSH') { push @command, '-o'; push @command, 'BatchMode=yes'; - push @command, '-tt'; ($$config{'options'} !~ /-X/) && push @command, '-x'; } From c672699571a1d8b2af2cf28eb46fcfbcf4c2fe54 Mon Sep 17 00:00:00 2001 From: penguhyang Date: Thu, 4 Aug 2016 14:35:45 +0800 Subject: [PATCH 12/21] fix genimage failed on rh6.8 (#1631) --- xCAT-server/share/xcat/netboot/rh/dracut/install.statelite | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT-server/share/xcat/netboot/rh/dracut/install.statelite b/xCAT-server/share/xcat/netboot/rh/dracut/install.statelite index 61b3797f4..b8bf69a46 100755 --- a/xCAT-server/share/xcat/netboot/rh/dracut/install.statelite +++ b/xCAT-server/share/xcat/netboot/rh/dracut/install.statelite @@ -1,6 +1,6 @@ #!/bin/sh echo $drivers -dracut_install wget tar xz cpio gzip dash modprobe wc touch echo cut +dracut_install wget tar cpio gzip dash modprobe wc touch echo cut dracut_install -o ctorrent dracut_install grep ifconfig hostname awk egrep grep dirname expr dracut_install parted mke2fs bc mkswap swapon chmod From 560d01ab84fe34e35be73573a7570456c5d50110 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Tue, 2 Aug 2016 14:46:04 -0400 Subject: [PATCH 13/21] Cleanup boot configuration files when processing rmdef --- xCAT-server/lib/xcat/plugins/DBobjectdefs.pm | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm index 6e55d0944..23a96e853 100755 --- a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm +++ b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm @@ -55,6 +55,8 @@ $Getopt::Long::ignorecase = 0; #@::objfilelist; # list of object names from the "-f" option #@::allobjnames; # combined list +my $doreq; + #@::noderange; # list of nodes derived from command line #------------------------------------------------------------------------------ @@ -137,6 +139,7 @@ sub process_request $::request = shift; $::callback = shift; + $doreq = shift; my $ret; my $msg; @@ -4239,6 +4242,26 @@ sub defrm } } + # Call nodeset offline on each node to cleanup its boot configuration files from /tftpboot directory + if ($doreq) { + # Go through each object and make sure it is a node type + my @allnodes; + foreach my $single_object (keys %objhash) { + if ($objhash{$single_object} eq "node") { + # build a list of nodes to offline + push @allnodes, $single_object; + } + } + # Run nodeset offline and capture output. + # But the output can be ignored since we do not want to prevent user from doing rmdef if + # nodeset returns some error. + my @output = xCAT::Utils->runxcmd({ + command => ['nodeset'], + node => [@allnodes], + arg => ['offline'], + }, $doreq, 0 ,1); + } + # remove the objects if (xCAT::DBobjUtils->rmobjdefs(\%objhash) != 0) { From f9d532b0094b4cb2349f107425386fdc806e5e8b Mon Sep 17 00:00:00 2001 From: ertaozh Date: Fri, 5 Aug 2016 03:02:21 -0400 Subject: [PATCH 14/21] Fix issue 1638: Genesis not wait long enough time to have NICs get IP address --- xCAT-genesis-scripts/bin/doxcat | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xCAT-genesis-scripts/bin/doxcat b/xCAT-genesis-scripts/bin/doxcat index f8fc3ac22..73f16b081 100755 --- a/xCAT-genesis-scripts/bin/doxcat +++ b/xCAT-genesis-scripts/bin/doxcat @@ -217,15 +217,16 @@ else fi fi done - sleep 2 + sleep 3 tries=$(($tries+1)) - if [ $tries -ge 10 ]; then + # Wait for 60 seconds to make sure the STP is done for at least one port + if [ $tries -ge 20 ]; then break fi done if [ -z "$bootnic" ]; then + logger -s -t $log_label -p local4.info "still can not get bootnic, go into /bin/bash" /bin/bash - logger -s -t $log_label -p local4.info "still can not get $bootnic, go into /bin/bash" fi else dhclient -cf /etc/dhclient.conf -pf /var/run/dhclient.$bootnic.pid $bootnic & From ab3448ca9f2ce2af0cb7a76d7cadad15b8d3b3c1 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Tue, 2 Aug 2016 14:34:43 -0400 Subject: [PATCH 15/21] Change the summary message for go-xcat --- xCAT-server/share/xcat/tools/go-xcat | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/xCAT-server/share/xcat/tools/go-xcat b/xCAT-server/share/xcat/tools/go-xcat index 0f17c7aa5..f3af5d556 100755 --- a/xCAT-server/share/xcat/tools/go-xcat +++ b/xCAT-server/share/xcat/tools/go-xcat @@ -1502,18 +1502,11 @@ case "${GO_XCAT_ACTION}" in while read -r ; do echo "${REPLY}" ; done <<-EOF + xCAT has been installed! + ======================== - Congratulations - =============== - - The fact that you got this far is a strong indication that xCAT bas been - installed correctly. - - Please notice if this is the first time you install xCAT. You need to do one - of the following. - - 1. Log out and then log in again, or - 2. run the following command to set the environment variables. + If this is the very first time xCAT has been installed, run the following + commands to set environment variables into your PATH: for sh, \`source /etc/profile.d/xcat.sh\` From 9b96ee24e6d8c0768c8dc40ff0f4265bd15c2822 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Fri, 5 Aug 2016 12:40:41 -0400 Subject: [PATCH 16/21] Display a different summary message on install vs update --- xCAT-server/share/xcat/tools/go-xcat | 30 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/xCAT-server/share/xcat/tools/go-xcat b/xCAT-server/share/xcat/tools/go-xcat index f3af5d556..f13e6e321 100755 --- a/xCAT-server/share/xcat/tools/go-xcat +++ b/xCAT-server/share/xcat/tools/go-xcat @@ -1500,19 +1500,29 @@ case "${GO_XCAT_ACTION}" in exit "${RET}" fi - while read -r ; do echo "${REPLY}" ; done <<-EOF + if [ ${GO_XCAT_ACTION} == 'install' ]; then + # only print out this message on install + while read -r ; do echo "${REPLY}" ; done <<-EOF - xCAT has been installed! - ======================== + xCAT has been installed! + ======================== - If this is the very first time xCAT has been installed, run the following - commands to set environment variables into your PATH: + If this is the very first time xCAT has been installed, run the following + commands to set environment variables into your PATH: - for sh, - \`source /etc/profile.d/xcat.sh\` - or csh, - \`source /etc/profile.d/xcat.csh\` - EOF + for sh, + \`source /etc/profile.d/xcat.sh\` + or csh, + \`source /etc/profile.d/xcat.csh\` + EOF + else + while read -r ; do echo "${REPLY}" ; done <<-EOF + + xCAT has been updated! + ====================== + + EOF + fi ;; *) list_xcat_packages From 9d0f0fb67753f96eda5c1b24f893ada48a45144b Mon Sep 17 00:00:00 2001 From: caomengmeng Date: Mon, 8 Aug 2016 11:34:51 +0800 Subject: [PATCH 17/21] Delete invalid statelite test case Delete invalid statelite test case --- xCAT-test/autotest/bundle/sles12.1_x86_64.bundle | 1 - 1 file changed, 1 deletion(-) diff --git a/xCAT-test/autotest/bundle/sles12.1_x86_64.bundle b/xCAT-test/autotest/bundle/sles12.1_x86_64.bundle index be3eb8b85..cedd4f898 100644 --- a/xCAT-test/autotest/bundle/sles12.1_x86_64.bundle +++ b/xCAT-test/autotest/bundle/sles12.1_x86_64.bundle @@ -220,4 +220,3 @@ assign_certain_command_permission_systemd sles_migration1 sles_migration2 reg_linux_diskless_installation_flat -reg_linux_statelite_installation_flat From 878d43addc1a32a904a3112de6b5f4677e5fdd43 Mon Sep 17 00:00:00 2001 From: Victor Hu Date: Mon, 8 Aug 2016 00:21:06 -0400 Subject: [PATCH 18/21] Add a section to attempt to autodetect the RHEL OS to bypass (#1644) the need to update the discinfo database --- xCAT-server/lib/xcat/plugins/anaconda.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index bf8c45f7f..a0e9f768d 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -2239,17 +2239,27 @@ sub copycd } } - unless ($distname) { + print "INFO - Could not find ID=$did in the discinfo database for OS=$desc ARCH=$darch NUM=$dno, attempt to auto-detect...\n"; if ($desc =~ /IBM_PowerKVM/) { # check for PowerKVM support my @pkvm_version = split / /, $desc; $distname = "pkvm" . $pkvm_version[1]; } + elsif ($desc =~ /Red Hat Enterprise Linux/) + { + # + # Attempt to auto-detect for RHEL OS. + # RHEL 7.3 description is: Red Hat Enterprise Linux 7.3 + # + my @rhel_version = split / /, $desc; + $distname = "rhels" . $rhel_version[4]; + } else { + print "INFO - Could not auto-detect operating system.\n"; return; #Do nothing, not ours.. } } From 1646d8bed2cc39d783db6f2aa2946c8eedce2586 Mon Sep 17 00:00:00 2001 From: XuWei Date: Mon, 8 Aug 2016 01:37:27 -0400 Subject: [PATCH 19/21] Modify usage, some probe commands do not support hierarchy --- xCAT-probe/subcmds/detect_dhcpd | 1 - xCAT-probe/subcmds/discovery | 5 ++--- xCAT-probe/subcmds/image | 2 -- xCAT-probe/subcmds/switch-macmap | 5 ++--- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/xCAT-probe/subcmds/detect_dhcpd b/xCAT-probe/subcmds/detect_dhcpd index 8c8759132..f1a2947b8 100755 --- a/xCAT-probe/subcmds/detect_dhcpd +++ b/xCAT-probe/subcmds/detect_dhcpd @@ -30,7 +30,6 @@ Options: -m macaddress: The mac that will be used to detect dhcp server. Recommend to use the real mac of the node that will be netboot. If no specified, the mac of interface which specified by -i will be used. -d duration: The time to wait to detect the dhcp messages. The default value is 10s. -V verbose: To print additional debug information. - -T : To verify if $program_name can work, reserve option for probe framework. "; #--------------------------- diff --git a/xCAT-probe/subcmds/discovery b/xCAT-probe/subcmds/discovery index a89626981..bfcec74f4 100755 --- a/xCAT-probe/subcmds/discovery +++ b/xCAT-probe/subcmds/discovery @@ -32,17 +32,16 @@ my %monitor_nodes; $::USAGE = "Usage: $program_name -h - $program_name -T $program_name [-V] [-m -n ] [--noprecheck] Description: Do probe for discovery process, including pre-check for required configuration and realtime monitor of discovery process. If all pre-check items pass, $program_name will go to monitor directly, otherwise $program_name exit for error. In order to do realtime monitor, $program_name probe program must be run along with the node discovery procedure. Plese trigger this command before trigger node discovery procedure. + Currently, this command does not support hierarchy. Options: -h : Get usage information of $program_name. - -T : To verify if $program_name can work, reserve option for probe framework. -V : Output more information for debug. -m : The method of discovery, the valid values are $valid_discovery_type_str. -n : The range of predefined node, must used with option -m. @@ -1137,7 +1136,7 @@ if ($help) { } if ($test) { - probe_utils->send_msg("$output", "o", "Do probe for discovery process, including pre-check for required configuration and realtime monitor of discovery process.Before using this command, please install nslookup command ahead."); + probe_utils->send_msg("$output", "o", "Do probe for discovery process, including pre-check for required configuration and realtime monitor of discovery process.Before using this command, please install nslookup command ahead. Currently, this command does not support hierarchy."); exit 0; } diff --git a/xCAT-probe/subcmds/image b/xCAT-probe/subcmds/image index 2dc104ab9..a79f16ab6 100755 --- a/xCAT-probe/subcmds/image +++ b/xCAT-probe/subcmds/image @@ -22,7 +22,6 @@ my $rst = 0; $::USAGE = "Usage: $program_name -h - $program_name -T $program_name {-c|-d} [-n noderange] [-V] Description: @@ -31,7 +30,6 @@ Description: Options: -h : Get usage information of $program_name - -T : To verify if $program_name can work, reserve option for probe framework -n : Range of nodes to check -d : To verify diskless, pingable compute nodes have the same images installed as defines in xCAT DB. -c : To verify all diskless, pingable compute nodes have the identical images installed. diff --git a/xCAT-probe/subcmds/switch-macmap b/xCAT-probe/subcmds/switch-macmap index a92b0e886..ca567a26e 100755 --- a/xCAT-probe/subcmds/switch-macmap +++ b/xCAT-probe/subcmds/switch-macmap @@ -16,14 +16,13 @@ my $output = "stdout"; $::USAGE = "Usage: $proname -h - $proname -T $proname [-c] [-V] Description: To retrieve MAC address mapping for the specified switch, or all the switches defined in switches table in xCAT db. + Currently, this command does not support hierarchy. Options: - -T: Check whether this script is OK to run. -c: To check whether the switch is OK to retrieve MAC address mapping. -V: Output verbose information when accessing switch "; @@ -67,7 +66,7 @@ if ($test) { probe_utils->send_msg("$output", "f", "No switchprobe tool is available at $currdir/bin/"); exit 1; } else { - probe_utils->send_msg("$output", "o", "To retrieve MAC address mapping for the specified switch, or all the switches defined in switches table in xCAT db."); + probe_utils->send_msg("$output", "o", "To retrieve MAC address mapping for the specified switch, or all the switches defined in switches table in xCAT db. Currently, this command does not support hierarchy."); exit 0; } } From 2ab944ea652f29bb786cca7d44b020550205d15b Mon Sep 17 00:00:00 2001 From: immarvin Date: Thu, 4 Aug 2016 05:40:01 -0400 Subject: [PATCH 20/21] add ubuntu16.04.1 netboot pkglist;modify the precedence of SvrUtils::get_file_name --- xCAT-server/lib/perl/xCAT/SvrUtils.pm | 18 +++++++++--------- .../ubuntu/compute.ubuntu16.04.1.pkglist | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 xCAT-server/share/xcat/netboot/ubuntu/compute.ubuntu16.04.1.pkglist diff --git a/xCAT-server/lib/perl/xCAT/SvrUtils.pm b/xCAT-server/lib/perl/xCAT/SvrUtils.pm index 4319eae82..3c813ca45 100755 --- a/xCAT-server/lib/perl/xCAT/SvrUtils.pm +++ b/xCAT-server/lib/perl/xCAT/SvrUtils.pm @@ -460,21 +460,21 @@ sub get_file_name { if (-r "$searchpath/$profile.$os.$arch.$extension") { return "$searchpath/$profile.$os.$arch.$extension"; } - elsif (-r "$searchpath/$profile.$osbase.$arch.$extension") { - return "$searchpath/$profile.$osbase.$arch.$extension"; - } - elsif (-r "$searchpath/$profile.$genos.$arch.$extension") { - return "$searchpath/$profile.$genos.$arch.$extension"; - } elsif (-r "$searchpath/$profile.$os.$extension") { return "$searchpath/$profile.$os.$extension"; } + elsif (($genos) && (-r "$searchpath/$profile.$genos.$arch.$extension")) { + return "$searchpath/$profile.$genos.$arch.$extension"; + } + elsif (($genos) && (-r "$searchpath/$profile.$genos.$extension")) { + return "$searchpath/$profile.$genos.$extension"; + } + elsif (-r "$searchpath/$profile.$osbase.$arch.$extension") { + return "$searchpath/$profile.$osbase.$arch.$extension"; + } elsif (-r "$searchpath/$profile.$osbase.$extension") { return "$searchpath/$profile.$osbase.$extension"; } - elsif (-r "$searchpath/$profile.$genos.$extension") { - return "$searchpath/$profile.$genos.$extension"; - } elsif (-r "$searchpath/$profile.$arch.$extension") { return "$searchpath/$profile.$arch.$extension"; } diff --git a/xCAT-server/share/xcat/netboot/ubuntu/compute.ubuntu16.04.1.pkglist b/xCAT-server/share/xcat/netboot/ubuntu/compute.ubuntu16.04.1.pkglist new file mode 100644 index 000000000..a5861a9e0 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/ubuntu/compute.ubuntu16.04.1.pkglist @@ -0,0 +1,17 @@ +bash +nfs-common +openssl +isc-dhcp-client +libc-bin +linux-image-generic +openssh-server +openssh-client +wget +ntp +ntpdate +rsync +busybox-static +gawk +dnsutils +tar +gzip From 769ba844c835fe77235307625c45522262d903f4 Mon Sep 17 00:00:00 2001 From: GONG Jie Date: Tue, 9 Aug 2016 15:11:00 +0800 Subject: [PATCH 21/21] [go-xcat] Remove all the complicated examples --- xCAT-server/share/xcat/tools/go-xcat | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/xCAT-server/share/xcat/tools/go-xcat b/xCAT-server/share/xcat/tools/go-xcat index f13e6e321..775c87ae3 100755 --- a/xCAT-server/share/xcat/tools/go-xcat +++ b/xCAT-server/share/xcat/tools/go-xcat @@ -49,26 +49,8 @@ function usage() ${script} --yes install ${script} -x 2.12 -y install ${script} --xcat-version=devel install - ${script} --xcat-core=/path/to/xcat-core.repo install - ${script} --xcat-core=/path/to/xcat-core install - ${script} --xcat-core=/path/to/xcat-core.tar install - ${script} --xcat-core=/path/to/xcat-core.tar.Z install - ${script} --xcat-core=/path/to/xcat-core.tar.gz install - ${script} --xcat-core=/path/to/xcat-core.tar.bz2 install - ${script} --xcat-core=/path/to/xcat-core.tar.xz install - ${script} --xcat-core=http://xcat.org/path/to/xcat-core.repo install - ${script} --xcat-core=http://xcat.org/path/to/xcat-core install - ${script} --xcat-core=http://xcat.org/path/to/xcat-core.tar.bz2 install - ${script} --xcat-core=/path/to/xcat-core.repo \\ - --xcat-dep=/path/to/xcat-dep.repo install - ${script} --xcat-core=/path/to/xcat-core \\ - --xcat-dep=/path/to/xcat-dep install ${script} --xcat-core=/path/to/xcat-core.tar.bz2 \\ --xcat-dep=/path/to/xcat-dep.tar.bz2 install - ${script} --xcat-core=http://xcat.org/path/to/xcat-core.repo \\ - --xcat-dep=http://xcat.org/path/to/xcat-dep.repo install - ${script} --xcat-core=http://xcat.org/path/to/xcat-core \\ - --xcat-dep=http://xcat.org/path/to/xcat-dep install ${script} --xcat-core=http://xcat.org/path/to/xcat-core.tar.bz2 \\ --xcat-dep=http://xcat.org/path/to/xcat-dep.tar.bz2 install