mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-29 09:13:08 +00:00
Merge pull request #2994 from cxhong/mvlan
Add configration support for Mellanox Ethernet switch
This commit is contained in:
commit
ae1cd00f4f
@ -568,11 +568,13 @@ sub setSSHcfg {
|
||||
my $enable_cmd = "enable\r";
|
||||
my $config_cmd = "configure terminal\r";
|
||||
my $exit_cmd = "exit\r";
|
||||
my $init_cmd = "no\r";
|
||||
|
||||
my $pwd_prompt = "Password: ";
|
||||
my $sw_prompt = "^.*\] > ";
|
||||
my $enable_prompt = "^.*\] \#";
|
||||
my $config_prompt = "^.*\\\(config\\\) \#";
|
||||
my $init_prompt = "Do you want to use the wizard for initial configuration?";
|
||||
|
||||
|
||||
my $debug = 0;
|
||||
@ -664,6 +666,14 @@ sub setSSHcfg {
|
||||
$mysw->exp_continue();
|
||||
}
|
||||
],
|
||||
[
|
||||
"-re", $init_prompt,
|
||||
sub {
|
||||
$mysw->clear_accum();
|
||||
$mysw->send($init_cmd);
|
||||
$mysw->exp_continue();
|
||||
}
|
||||
],
|
||||
[
|
||||
"-re", $sw_prompt,
|
||||
sub {
|
||||
|
@ -37,8 +37,16 @@ my %global_mac_identity = (
|
||||
"a8:97:dc" => "BNT G8052 switch",
|
||||
"6c:ae:8b" => "BNT G8264-T switch",
|
||||
"fc:cf:62" => "BNT G8124 switch",
|
||||
"7c:fe:90" => "Mellanox IB switch",
|
||||
"7c:fe:90" => "Mellanox switch",
|
||||
"e4:1d:2d" => "Mellanox switch",
|
||||
"24:8a:07" => "Mellanox switch",
|
||||
"00:25:8b" => "Mellanox switch",
|
||||
"00:02:c9" => "Mellanox switch",
|
||||
"f4:52:14" => "Mellanox switch",
|
||||
"ec:0d:9a" => "Mellanox switch",
|
||||
"cc:37:ab" => "Edgecore Networks Switch",
|
||||
"a8:2b:b5" => "Edgecore Networks Switch",
|
||||
"70:72:cf" => "Edgecore Networks Switch",
|
||||
"8c:ea:1b" => "Edgecore Networks Switch"
|
||||
);
|
||||
|
||||
|
@ -26,13 +26,13 @@ use xCAT::MsgUtils;
|
||||
Getopt::Long::Configure("bundling");
|
||||
$Getopt::Long::ignorecase = 0;
|
||||
|
||||
#global variables
|
||||
# global variables
|
||||
my @nodes;
|
||||
my @filternodes;
|
||||
|
||||
|
||||
#---------------------------------------------------------
|
||||
#Main
|
||||
# Main
|
||||
|
||||
# parse the options
|
||||
if (
|
||||
@ -43,9 +43,9 @@ if (
|
||||
'ip' => \$::IP,
|
||||
'name' => \$::NAME,
|
||||
'snmp' => \$::SNMP,
|
||||
'user=s' => \$::USER,
|
||||
'password=s' => \$::PASSWORD,
|
||||
'auth=s' => \$::AUTH,
|
||||
'vlan=s' => \$::VLAN,
|
||||
'port=s' => \$::PORT,
|
||||
'mode=s' => \$::MODE,
|
||||
'all' => \$::ALL,
|
||||
)
|
||||
)
|
||||
@ -93,6 +93,16 @@ my $user;
|
||||
my $cmd;
|
||||
my $rc;
|
||||
my $master;
|
||||
my $vlan;
|
||||
my $port;
|
||||
my $mode;
|
||||
|
||||
# set community string for switch
|
||||
my $community = "public";
|
||||
my @snmpcs = xCAT::TableUtils->get_site_attribute("snmpc");
|
||||
my $tmp = $snmpcs[0];
|
||||
if (defined($tmp)) { $community = $tmp }
|
||||
|
||||
|
||||
if (($::IP) || ($::ALL)) {
|
||||
config_ip();
|
||||
@ -102,8 +112,7 @@ if (($::NAME) || ($::ALL)) {
|
||||
config_hostname();
|
||||
}
|
||||
|
||||
if (($::SNMP) || ($::ALL))
|
||||
{
|
||||
if (($::SNMP) || ($::ALL)) {
|
||||
config_snmp();
|
||||
}
|
||||
|
||||
@ -111,6 +120,9 @@ if (($::CONFIG) || ($::ALL)) {
|
||||
run_rspconfig();
|
||||
}
|
||||
|
||||
if ($::VLAN) {
|
||||
config_vlan();
|
||||
}
|
||||
|
||||
sub config_ip {
|
||||
my @config_switches;
|
||||
@ -125,14 +137,13 @@ sub config_ip {
|
||||
@nets = $nettab->getAllAttribs('net','mask');
|
||||
}
|
||||
foreach my $switch (@nodes) {
|
||||
print "change $switch to static ip address\n";
|
||||
my $dip= $nodehash->{$switch}->[0]->{otherinterfaces};
|
||||
if (!$dip) {
|
||||
print "Add otherinterfaces attribute for discover ip: chdef $switch otherinterfaces=x.x.x.x\n";
|
||||
next;
|
||||
}
|
||||
|
||||
#Validate if this IP is reachable
|
||||
# Validate if this IP is reachable
|
||||
my $p = Net::Ping->new();
|
||||
if (!$p->ping($dip)) {
|
||||
print "$dip is not reachable\n";
|
||||
@ -147,7 +158,7 @@ sub config_ip {
|
||||
next;
|
||||
}
|
||||
|
||||
#get hostname
|
||||
# get hostname
|
||||
my $dswitch = xCAT::NetworkUtils->gethostname($dip);
|
||||
|
||||
# if hostnames are same, created different one for discovery name
|
||||
@ -155,25 +166,38 @@ sub config_ip {
|
||||
$dswitch="";
|
||||
}
|
||||
|
||||
#if not defined, need to create one for xdsh to use
|
||||
# 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";
|
||||
$cmd = "chdef -t node -o $dswitch groups=switch ip=$dip switchtype=Mellanox username=admin password=admin mgt=switch nodetype=switch";
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
$cmd = "makehosts $dswitch";
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
$cmd = "makedns $dswitch";
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
|
||||
$cmd="rspconfig $dswitch sshcfg=enable";
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
if ($::RUNCMD_RC != 0) {
|
||||
xCAT::MsgUtils->message("E"," Failed to config ssh passwordless for $dip");
|
||||
print "Failed to config ssh passwordless for $dswitch, $dip\n";
|
||||
push (@discover_switches, $dswitch);
|
||||
next;
|
||||
}
|
||||
|
||||
# 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");
|
||||
xCAT::MsgUtils->message("E","Couldn't communicate with $dip");
|
||||
print "$cmd failed, Couldn't communicate with $dswitch, $dip\n";
|
||||
push (@discover_switches, $dswitch);
|
||||
next;
|
||||
}
|
||||
#get netmask
|
||||
# get netmask
|
||||
my $mask;
|
||||
foreach my $net (@nets) {
|
||||
if (xCAT::NetworkUtils::isInSameSubnet( $net->{'net'}, $static_ip, $net->{'mask'}, 0)) {
|
||||
@ -186,18 +210,23 @@ sub config_ip {
|
||||
|
||||
push (@discover_switches, $dswitch);
|
||||
push (@config_switches, $switch);
|
||||
print "$switch: Changing IP address to static IP $static_ip\n";
|
||||
}
|
||||
|
||||
if (@config_switches) {
|
||||
#update switch status
|
||||
# update switch status
|
||||
my $csw = join(",",@config_switches);
|
||||
$cmd = "chdef $csw status=ip_configed otherinterfaces=";
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
$cmd = "makehosts $csw";
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
}
|
||||
|
||||
if (@discover_switches) {
|
||||
my $dsw = join(",",@discover_switches);
|
||||
#remove discover switch from xCATdb and /etc/hosts
|
||||
# remove discover switch from xCATdb and /etc/hosts
|
||||
$cmd = "makedns -d $dsw";
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
$cmd = "makehosts -d $dsw";
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
$cmd = "rmdef $dsw";
|
||||
@ -223,63 +252,58 @@ sub config_hostname {
|
||||
xCAT::MsgUtils->message("E","Failed to setup hostname for $switch");
|
||||
next;
|
||||
}
|
||||
push (@config_switches, $switch);
|
||||
push (@config_switches, $switch);
|
||||
print "$switch: Changing host name to $switch\n";
|
||||
}
|
||||
if (@config_switches) {
|
||||
#update switch status
|
||||
# update switch status
|
||||
my $csw = join(",",@config_switches);
|
||||
$cmd = "chdef $csw status=hostname_configed" ;
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#setup secure SNMP v3
|
||||
# setup secure SNMP v3
|
||||
sub config_snmp {
|
||||
my $snmp_user;
|
||||
my $snmp_passwd;
|
||||
my $snmp_auth;
|
||||
|
||||
my $switchtab = xCAT::Table->new('switches');
|
||||
my $switchhash = $switchtab->getNodesAttribs(\@nodes,['sshusername','username','password','auth']);
|
||||
my $switchhash = $switchtab->getNodesAttribs(\@nodes,['sshusername','username','password','auth','privacy']);
|
||||
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);
|
||||
print "switch ssh username is not defined, use default one\n";
|
||||
$user="admin";
|
||||
}
|
||||
if ($::USER) {
|
||||
$snmp_user = $::USER;
|
||||
} elsif ($switchhash->{$switch}->[0]->{username}) {
|
||||
$snmp_user = $switchhash->{$switch}->[0]->{username};
|
||||
} else {
|
||||
$snmp_user = "xcatadmin\r";
|
||||
$snmp_user = $switchhash->{$switch}->[0]->{username};
|
||||
if (!$snmp_user) {
|
||||
print "No snmp user defined for switch $switch. Will not configure snmpv3\n";
|
||||
next;
|
||||
}
|
||||
if ($::PASSWORD) {
|
||||
$snmp_passwd = $::PASSWORD;
|
||||
} elsif ($switchhash->{$switch}->[0]->{password}) {
|
||||
$snmp_passwd = $switchhash->{$switch}->[0]->{password};
|
||||
$snmp_passwd = $switchhash->{$switch}->[0]->{password};
|
||||
$snmp_auth = $switchhash->{$switch}->[0]->{auth};
|
||||
my $snmp_privacy = $switchhash->{$switch}->[0]->{privacy};
|
||||
|
||||
my $cmd_prefix = "xdsh $switch -l $user --devicetype IBSwitch::Mellanox";
|
||||
my $cmd;
|
||||
# Build up the commands for easier readability
|
||||
$cmd = $cmd . "enable\;";
|
||||
$cmd = $cmd . "configure terminal\;";
|
||||
$cmd = $cmd . "snmp-server user $snmp_user v3 enable\;";
|
||||
if ($snmp_privacy) {
|
||||
$cmd = $cmd . "snmp-server user $snmp_user v3 auth $snmp_auth $snmp_passwd priv $snmp_privacy $snmp_passwd\;";
|
||||
} else {
|
||||
# Need a special character
|
||||
$snmp_passwd = "passw0rd\r";
|
||||
}
|
||||
if ($::AUTH) {
|
||||
$snmp_auth = $::AUTH;
|
||||
} elsif ($switchhash->{$switch}->[0]->{auth}) {
|
||||
$snmp_auth = $switchhash->{$switch}->[0]->{auth};
|
||||
} else {
|
||||
$snmp_auth = "sha\r";
|
||||
$cmd = $cmd . "snmp-server user $snmp_user v3 auth $snmp_auth $snmp_passwd\; no snmp-server user $snmp_user v3 require-privacy\;";
|
||||
}
|
||||
|
||||
$cmd = "xdsh $switch -l $user --devicetype IBSwitch::Mellanox 'enable;configure terminal;snmp-server user $snmp_user v3 enable;snmp-server user $snmp_user v3 auth $snmp_auth $snmp_passwd;no snmp-server user $snmp_user v3 require-privacy;configuration write;exit' ";
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
if ($::RUNCMD_RC != 0) {
|
||||
xCAT::MsgUtils->message("E","Failed to set snmpv3 for $switch");
|
||||
} else {
|
||||
$cmd = "chdef $switch status=snmp_configed snmpversion=3 snmpauth=$snmp_auth snmpusername=$snmp_user snmppassword=$snmp_passwd";
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
}
|
||||
print "$switch: snmpv3 configured\n";
|
||||
|
||||
$cmd = $cmd . "configuration write\;exit\;";
|
||||
my $final_cmd = $cmd_prefix . " \"" . $cmd . "\"";
|
||||
|
||||
`$final_cmd`
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,28 +312,27 @@ 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
|
||||
# call rspconfig command to setup switch
|
||||
# enable ssh
|
||||
$cmd=`rspconfig $switch sshcfg=enable`;
|
||||
|
||||
#enable snmp function on the switch
|
||||
# enable snmp function on the switch
|
||||
$cmd=`rspconfig $switch snmpcfg=enable`;
|
||||
|
||||
#enable the snmp trap
|
||||
# enable the snmp trap
|
||||
$cmd=`rspconfig $switch alert=enable`;
|
||||
|
||||
#Logging destination:
|
||||
# Logging destination:
|
||||
$cmd=`rspconfig $switch logdest=$master`;
|
||||
|
||||
#config ntp
|
||||
# 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
|
||||
# update switch status
|
||||
my $csw = join(",",@config_switches);
|
||||
$cmd = "chdef $csw status=switch_configed" ;
|
||||
$rc= xCAT::Utils->runcmd($cmd, 0);
|
||||
@ -317,6 +340,87 @@ sub run_rspconfig {
|
||||
|
||||
}
|
||||
|
||||
sub config_vlan {
|
||||
my @ports;
|
||||
my $port_input;
|
||||
# checking for port number, switches is checked earlier
|
||||
if ($::PORT) {
|
||||
$port_input = $::PORT;
|
||||
foreach my $num_str (split /,/, $port_input) {
|
||||
if ($num_str =~ /-/) {
|
||||
my ($min, $max) = split (/-/,$num_str);
|
||||
while ($min <= $max) {
|
||||
push (@ports,$min);
|
||||
$min++;
|
||||
}
|
||||
} else {
|
||||
push (@ports,$num_str);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
xCAT::MsgUtils->message("E"," When configuring VLAN, a port must be provided.");
|
||||
&usage;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
# will default to trunk mode
|
||||
if ($::MODE) {
|
||||
$mode = $::MODE;
|
||||
if (!($mode =~ m/(access|trunk|hybrid|access-dcb|dot1q-tunnel)/) )
|
||||
{
|
||||
xCAT::MsgUtils->message("E"," Please provided supported mode");
|
||||
&usage;
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
$mode = "access";
|
||||
}
|
||||
|
||||
$vlan = $::VLAN;
|
||||
|
||||
foreach my $switch (@nodes) {
|
||||
my $devicetype;
|
||||
|
||||
# check if it is ethernet switch or ib switch
|
||||
my $ccmd = "snmpwalk -Os -v1 -c $community $switch 1.3.6.1.2.1.1.1";
|
||||
my $result = xCAT::Utils->runcmd($ccmd, 0);
|
||||
|
||||
# only supports MSX1410 and MSX1400 for Mellanox Ethernet switch now
|
||||
if ( $result =~ /MSX14/ ) {
|
||||
$devicetype = "EthSwitch::Mellanox";
|
||||
}else {
|
||||
xCAT::MsgUtils->message("E","Config IB switch VLAN is not support yet");
|
||||
$devicetype = "IBSwitch::Mellanox";
|
||||
next;
|
||||
}
|
||||
|
||||
print "Tagging VLAN=$vlan for $switch port $port_input\n";
|
||||
|
||||
# create vlan
|
||||
my $vlan_cmd = `xdsh $switch --devicetype $devicetype "enable;configure terminal;vlan $vlan;exit;exit" `;
|
||||
|
||||
my $cmd_prefix = "xdsh $switch --devicetype $devicetype";
|
||||
foreach my $port (@ports) {
|
||||
my $cmd;
|
||||
# Build up the commands for easier readability
|
||||
$cmd = $cmd . "enable\;";
|
||||
$cmd = $cmd . "configure terminal\;";
|
||||
$cmd = $cmd . "interface ethernet 1/$port\;";
|
||||
$cmd = $cmd . "switchport mode $mode\;";
|
||||
if ($mode =~ /access/) {
|
||||
$cmd = $cmd . "switchport access vlan $vlan\;";
|
||||
} else {
|
||||
$cmd = $cmd . "switchport $mode allowed-vlan $vlan\;";
|
||||
}
|
||||
$cmd = $cmd . "exit\;exit\;exit\;";
|
||||
my $final_cmd = $cmd_prefix . " \"" . $cmd . "\"";
|
||||
|
||||
`$final_cmd`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#---------------------------------------------------------
|
||||
|
||||
=head3 usage
|
||||
@ -332,13 +436,24 @@ sub usage
|
||||
configMellanox -h│--help
|
||||
configMellanox --switches switchnames --ip
|
||||
configMellanox --switches switchnames --name
|
||||
configMellanox --switches switchnames --snmp [--user snmp_user] [--password snmp_password] [--auth snmp_auth]
|
||||
configMellanox --switches switchnames --snmp
|
||||
|
||||
To set the ip address, hostname, config snmp and run rspconfig command:
|
||||
configMellanox --switches switchnames --all
|
||||
|
||||
To run rspconfig command:
|
||||
configMellanox --switches switchnames --config
|
||||
|
||||
To configure VLAN on a specified port (Mellanox Ethernet switch ONLY):
|
||||
configMellanox --switches switchnames --port port --vlan vlan --mode mode
|
||||
|
||||
The following mode are supported for switchport:
|
||||
* access Only untagged ingress Ethernet packets are allowed
|
||||
* trunk Only tagged ingress Ethernet packets are allowed
|
||||
* hybrid Both tagged and untagged ingress Ethernet packets are allowed
|
||||
* access-dcb Only untagged ingress Ethernet packets are allowed. Egress packets will be priority tagged
|
||||
* dot1q-tunnel Both tagged and untagged ingress Ethernet packets are allowed. Egress packets are tagged with a second VLAN (802.1Q) header
|
||||
|
||||
\n";
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user