2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-08-20 02:00:24 +00:00

Merge branch 'master' of github.com:xcat2/xcat-core

This commit is contained in:
caomengmeng
2016-08-09 04:52:09 -04:00
18 changed files with 826 additions and 69 deletions

View File

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

View File

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

View File

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

View File

@@ -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.
";
#---------------------------

View File

@@ -32,17 +32,16 @@ my %monitor_nodes;
$::USAGE = "Usage:
$program_name -h
$program_name -T
$program_name [-V] [-m <discovery_type> -n <node_range>] [--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;
}

View File

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

View File

@@ -16,14 +16,13 @@ my $output = "stdout";
$::USAGE = "Usage:
$proname -h
$proname -T
$proname <noderange> [-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;
}
}

View File

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

View File

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

View File

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

View File

@@ -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,14 +156,14 @@ 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() );
}
#############################################
# 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)));
@@ -261,6 +264,14 @@ sub parse_args {
$globalopt{n} = 1;
}
#########################################################
# setup discover switch
#########################################################
if ( exists( $opt{setup} )) {
$globalopt{setup} = 1;
}
return;
}
@@ -445,10 +456,10 @@ 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;
my $msg = sprintf $format, $ip, $name, $vendor, $mac;
send_msg(\%request, 0, $msg);
}
}
@@ -460,6 +471,11 @@ sub process_request {
xCATdB($result, \%request, $sub_req);
}
if (exists($globalopt{setup})) {
switchsetup($result, \%request, $sub_req);
}
return;
}
@@ -1117,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;
}
}
@@ -1328,5 +1344,79 @@ sub format_xml {
return ($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:
result:
=cut
#--------------------------------------------------------------------------------
sub switchsetup {
my $outhash = shift;
my $request = shift;
my $sub_req = shift;
my @switchnode = ();
my $static_ip;
my $discover_switch;
my $nodes_to_config;
#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};
# issue makehosts so we can use xdsh
my $dswitch = get_hostname($outhash->{$mac}->{name}, $ip);
my $node = $macmap->find_mac($mac,0);
if (!$node) {
send_msg($request, 0, "NO predefined switch matched this switch $dswitch with ip address $ip and 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" );
}
xCAT::Utils->runxcmd({ command => ['chdef'], arg => ['-t','node','-o',$node,"otherinterfaces=$ip",'status=Matched',"mac=$mac","switchtype=$stype","usercomment=$vendor"] }, $sub_req, 0, 1);
push (@{$nodes_to_config->{$stype}}, $node);
}
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");
}
}
return;
}
1;

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,371 @@
#!/usr/bin/env perl
#---------------------------------------------------------
# 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;
Getopt::Long::Configure("bundling");
$Getopt::Long::ignorecase = 0;
#global variables
my @nodes;
my @filternodes;
#---------------------------------------------------------
#Main
# parse the options
if (
!GetOptions(
'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,
)
)
{
&usage;
exit(1);
}
# display the usage if -h or --help is specified
if ($::HELP)
{
&usage;
exit(0);
}
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");
}
# 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 --switches");
&usage;
exit(1);
}
my $switches = join(",",@nodes);
my $cmd;
my $vlan;
my $port;
my $sub_req;
my $rc;
if (($::IP) || ($::ALL))
{
config_ip();
}
if (($::NAME) || ($::ALL))
{
config_hostname();
}
if (($::SNMP) || ($::ALL))
{
config_snmp();
}
if ($::VLAN)
{
config_vlan();
}
sub config_ip {
my @config_switches;
my @discover_switches;
my $nodetab = xCAT::Table->new('hosts');
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);
#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";
}
$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);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","Couldn't communicate with $dswitch, $dip");
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
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 $dsw";
$rc= xCAT::Utils->runcmd($cmd, 0);
$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) {
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;
}
push (@config_switches, $switch);
}
if (@config_switches) {
#update switch status
my $csw = join(",",@config_switches);
$cmd = "chdef $csw status=hostname_configed" ;
$rc= xCAT::Utils->runcmd($cmd, 0);
}
}
#setup secure SNMP v3
sub config_snmp {
my $snmp_user;
my $snmp_passwd;
my $snmp_group;
my @config_switches;
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";
}
foreach my $switch (@nodes) {
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";
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();
push (@config_switches, $switch);
}
if (@config_switches) {
#update switch status
my $csw = join(",",@config_switches);
$cmd = "chdef $csw status=switch_configed snmpversion=3 snmpauth=sha snmpusername=$snmp_user snmppassword=$snmp_passwd";
$rc= xCAT::Utils->runcmd($cmd, 0);
}
}
sub config_vlan {
if ($::PORT) {
$port = $::PORT;
} else {
&usage;
exit(1);
}
$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
Displays message for -h option
=cut
#---------------------------------------------------------
sub usage
{
print "Usage:
configBNT [-?│-h│--help]
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";
}

View File

@@ -0,0 +1,258 @@
#!/usr/bin/env perl
#---------------------------------------------------------
# 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;
Getopt::Long::Configure("bundling");
$Getopt::Long::ignorecase = 0;
#global variables
my @nodes;
my @filternodes;
#---------------------------------------------------------
#Main
# parse the options
if (
!GetOptions(
'h|help' => \$::HELP,
'switches=s' => \$::SWITCH,
'config' => \$::CONFIG,
'ip' => \$::IP,
'name' => \$::NAME,
'all' => \$::ALL,
)
)
{
&usage;
exit(1);
}
# display the usage if -h or --help is specified
if ($::HELP)
{
&usage;
exit(0);
}
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");
}
# 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");
exit(1);
}
} else {
xCAT::MsgUtils->message("E","Invalid flag, please provide switches with --switches");
&usage;
exit(1);
}
my $switches = join(",",@nodes);
my $user;
my $cmd;
my $rc;
my $master;
if (($::IP) || ($::ALL)) {
config_ip();
}
if (($::NAME) || ($::ALL)) {
config_hostname();
}
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,['ip','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};
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";
}
$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);
if ($::RUNCMD_RC != 0) {
xCAT::MsgUtils->message("E","Couldn't communicate with $dswitch, $dip");
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);
push (@discover_switches, $dswitch);
push (@config_switches, $switch);
}
if (@config_switches) {
#update switch status
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 $dsw";
$rc= xCAT::Utils->runcmd($cmd, 0);
$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) {
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;
}
push (@config_switches, $switch);
}
if (@config_switches) {
#update switch status
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`;
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" `;
push (@config_switches, $switch);
}
if (@config_switches) {
#update switch status
my $csw = join(",",@config_switches);
$cmd = "chdef $csw status=switch_configed" ;
$rc= xCAT::Utils->runcmd($cmd, 0);
}
}
#---------------------------------------------------------
=head3 usage
Displays message for -h option
=cut
#---------------------------------------------------------
sub usage
{
print "Usage:
configMellonax [-?│-h│--help]
configMellonax [--switches switchnames] [--all]
configMellonax [--switches switchnames] [--ip]
configMellonax [--switches switchnames] [--name]
configMellonax [--switches switchnames] [--config]
\n";
}

View File

@@ -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
@@ -1500,26 +1482,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!
========================
Congratulations
===============
If this is the very first time xCAT has been installed, run the following
commands to set environment variables into your PATH:
The fact that you got this far is a strong indication that xCAT bas been
installed correctly.
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
Please notice if this is the first time you install xCAT. You need to do one
of the following.
xCAT has been updated!
======================
1. Log out and then log in again, or
2. run the following command to set the environment variables.
for sh,
\`source /etc/profile.d/xcat.sh\`
or csh,
\`source /etc/profile.d/xcat.csh\`
EOF
EOF
fi
;;
*)
list_xcat_packages

View File

@@ -220,4 +220,3 @@ assign_certain_command_permission_systemd
sles_migration1
sles_migration2
reg_linux_diskless_installation_flat
reg_linux_statelite_installation_flat