From a17edd7080107375e41f7e36258302569e5928b0 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Fri, 5 May 2017 09:53:28 -0400 Subject: [PATCH 1/7] Support vlan configration for Mellanox Ethernet switch --- xCAT-server/share/xcat/scripts/configMellanox | 100 +++++++++++++++++- 1 file changed, 96 insertions(+), 4 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/configMellanox b/xCAT-server/share/xcat/scripts/configMellanox index 2e6f1db34..6ae339bf2 100755 --- a/xCAT-server/share/xcat/scripts/configMellanox +++ b/xCAT-server/share/xcat/scripts/configMellanox @@ -46,6 +46,9 @@ if ( 'user=s' => \$::USER, 'password=s' => \$::PASSWORD, 'auth=s' => \$::AUTH, + 'vlan=s' => \$::VLAN, + 'port=s' => \$::PORT, + 'mode=s' => \$::MODE, 'all' => \$::ALL, ) ) @@ -93,6 +96,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(); @@ -111,6 +124,9 @@ if (($::CONFIG) || ($::ALL)) { run_rspconfig(); } +if ($::VLAN) { + config_vlan(); +} sub config_ip { my @config_switches; @@ -125,7 +141,6 @@ 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"; @@ -150,6 +165,7 @@ sub config_ip { #get hostname my $dswitch = xCAT::NetworkUtils->gethostname($dip); + # if hostnames are same, created different one for discovery name if ($dswitch eq $switch) { $dswitch=""; @@ -161,6 +177,7 @@ sub config_ip { $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"; @@ -193,6 +210,8 @@ sub config_ip { 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) { @@ -212,7 +231,6 @@ sub config_hostname { 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"; @@ -244,7 +262,6 @@ sub config_snmp { 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"; @@ -288,7 +305,6 @@ 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 @@ -317,6 +333,71 @@ sub run_rspconfig { } +sub config_vlan { + # checking for port number, switches is checked earlier + if ($::PORT) { + $port = $::PORT; + } else { + xCAT::MsgUtils->message("E","Error - When setting 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","Error - 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; + } + + my $cmd_prefix = "xdsh $switch --devicetype $devicetype"; + my $cmd; + + # Build up the commands for easier readability + $cmd = $cmd . "enable\;"; + $cmd = $cmd . "configure terminal\;"; + $cmd = $cmd . "vlan $vlan\;"; + $cmd = $cmd . "exit\;"; + $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 @@ -339,6 +420,17 @@ sub usage To run rspconfig command: configMellanox --switches switchnames --config + + To set Vlan for interface commmand (only for Mellanox Ethernet switch) : + 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"; } From e9b8a3bbbf96b068ec7add801c747487dc1e3169 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Wed, 10 May 2017 13:48:18 -0400 Subject: [PATCH 2/7] modification for configMellanox scripts --- xCAT-server/lib/perl/xCAT/MellanoxIB.pm | 11 ++ .../lib/xcat/plugins/switchdiscover.pm | 2 +- xCAT-server/share/xcat/scripts/configMellanox | 101 ++++++++++-------- 3 files changed, 68 insertions(+), 46 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/MellanoxIB.pm b/xCAT-server/lib/perl/xCAT/MellanoxIB.pm index dbfec4b69..c26f18c9f 100644 --- a/xCAT-server/lib/perl/xCAT/MellanoxIB.pm +++ b/xCAT-server/lib/perl/xCAT/MellanoxIB.pm @@ -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,15 @@ sub setSSHcfg { $mysw->exp_continue(); } ], + [ + "-re", $init_prompt, + sub { + #print "$node: sending command: $init_cmd\n"; + $mysw->clear_accum(); + $mysw->send($init_cmd); + $mysw->exp_continue(); + } + ], [ "-re", $sw_prompt, sub { diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index ebc6cb61b..12b3dc03c 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -37,7 +37,7 @@ 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", "8c:ea:1b" => "Edgecore Networks Switch" ); diff --git a/xCAT-server/share/xcat/scripts/configMellanox b/xCAT-server/share/xcat/scripts/configMellanox index 6ae339bf2..397ac58e8 100755 --- a/xCAT-server/share/xcat/scripts/configMellanox +++ b/xCAT-server/share/xcat/scripts/configMellanox @@ -43,9 +43,6 @@ 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, @@ -115,8 +112,7 @@ if (($::NAME) || ($::ALL)) { config_hostname(); } -if (($::SNMP) || ($::ALL)) -{ +if (($::SNMP) || ($::ALL)) { config_snmp(); } @@ -165,7 +161,6 @@ sub config_ip { #get hostname my $dswitch = xCAT::NetworkUtils->gethostname($dip); - # if hostnames are same, created different one for discovery name if ($dswitch eq $switch) { $dswitch=""; @@ -177,17 +172,29 @@ sub config_ip { $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 @@ -203,6 +210,7 @@ sub config_ip { push (@discover_switches, $dswitch); push (@config_switches, $switch); + print "changed $switch ip address to static ip $static_ip\n"; } if (@config_switches) { @@ -217,6 +225,8 @@ sub config_ip { if (@discover_switches) { my $dsw = join(",",@discover_switches); #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"; @@ -231,6 +241,7 @@ sub config_hostname { 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"; @@ -241,7 +252,8 @@ sub config_hostname { xCAT::MsgUtils->message("E","Failed to setup hostname for $switch"); next; } - push (@config_switches, $switch); + push (@config_switches, $switch); + print "switch host name changed to $switch\n"; } if (@config_switches) { #update switch status @@ -258,45 +270,42 @@ sub config_snmp { 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); $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 is defined for this switch $switch, not going to set up 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 "snmpv3 configured for switch $switch\n"; + + $cmd = $cmd . "configuration write\;exit\;"; + my $final_cmd = $cmd_prefix . " \"" . $cmd . "\""; + + `$final_cmd` } } @@ -342,7 +351,7 @@ sub config_vlan { &usage; exit(1); } - + #will default to trunk mode if ($::MODE) { $mode = $::MODE; @@ -373,10 +382,12 @@ sub config_vlan { $devicetype = "IBSwitch::Mellanox"; next; } - + my $cmd_prefix = "xdsh $switch --devicetype $devicetype"; my $cmd; + print "Tagging VLAN=$vlan for $switch port $port\n"; + # Build up the commands for easier readability $cmd = $cmd . "enable\;"; $cmd = $cmd . "configure terminal\;"; @@ -390,10 +401,10 @@ sub config_vlan { $cmd = $cmd . "switchport $mode allowed-vlan $vlan\;"; } $cmd = $cmd . "exit\;exit\;exit\;"; - my $final_cmd = $cmd_prefix . " \"" . $cmd . "\""; `$final_cmd` + } } @@ -413,7 +424,7 @@ 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 @@ -422,14 +433,14 @@ sub usage configMellanox --switches switchnames --config To set Vlan for interface commmand (only for Mellanox Ethernet switch) : - configMellanox --switches switchnames --port port --vlan vlan --mode mode + configMellanox --switches switchnames --port port --vlan vlan --mode mode - The following mode are supported for switchport: + 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 + * dot1q-tunnel Both tagged and untagged ingress Ethernet packets are allowed. Egress packets are tagged with a second VLAN (802.1Q) header \n"; } From d4383de06daef49f719fc9c7336a0daa309fcf42 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Fri, 12 May 2017 09:54:14 -0400 Subject: [PATCH 3/7] modified from reviews --- xCAT-server/lib/perl/xCAT/MellanoxIB.pm | 1 - xCAT-server/share/xcat/scripts/configMellanox | 30 +++++++++---------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/MellanoxIB.pm b/xCAT-server/lib/perl/xCAT/MellanoxIB.pm index c26f18c9f..3d9b395a6 100644 --- a/xCAT-server/lib/perl/xCAT/MellanoxIB.pm +++ b/xCAT-server/lib/perl/xCAT/MellanoxIB.pm @@ -669,7 +669,6 @@ sub setSSHcfg { [ "-re", $init_prompt, sub { - #print "$node: sending command: $init_cmd\n"; $mysw->clear_accum(); $mysw->send($init_cmd); $mysw->exp_continue(); diff --git a/xCAT-server/share/xcat/scripts/configMellanox b/xCAT-server/share/xcat/scripts/configMellanox index 397ac58e8..8538eb5b9 100755 --- a/xCAT-server/share/xcat/scripts/configMellanox +++ b/xCAT-server/share/xcat/scripts/configMellanox @@ -210,7 +210,7 @@ sub config_ip { push (@discover_switches, $dswitch); push (@config_switches, $switch); - print "changed $switch ip address to static ip $static_ip\n"; + print "$switch: Changing IP address to static IP $static_ip\n"; } if (@config_switches) { @@ -253,7 +253,7 @@ sub config_hostname { next; } push (@config_switches, $switch); - print "switch host name changed to $switch\n"; + print "$switch: Changing host name to $switch\n"; } if (@config_switches) { #update switch status @@ -274,14 +274,12 @@ sub config_snmp { 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"; } $snmp_user = $switchhash->{$switch}->[0]->{username}; if (!$snmp_user) { - print "no snmp user is defined for this switch $switch, not going to set up snmpv3\n"; + print "No snmp user defined for switch $switch. Will not configure snmpv3\n"; next; } $snmp_passwd = $switchhash->{$switch}->[0]->{password}; @@ -300,7 +298,7 @@ sub config_snmp { $cmd = $cmd . "snmp-server user $snmp_user v3 auth $snmp_auth $snmp_passwd\; no snmp-server user $snmp_user v3 require-privacy\;"; } - print "snmpv3 configured for switch $switch\n"; + print "$switch: snmpv3 configured\n"; $cmd = $cmd . "configuration write\;exit\;"; my $final_cmd = $cmd_prefix . " \"" . $cmd . "\""; @@ -347,7 +345,7 @@ sub config_vlan { if ($::PORT) { $port = $::PORT; } else { - xCAT::MsgUtils->message("E","Error - When setting vlan, a port must be provided."); + xCAT::MsgUtils->message("E","Error - When configuring VLAN, a port must be provided."); &usage; exit(1); } @@ -378,7 +376,7 @@ sub config_vlan { if ( $result =~ /MSX14/ ) { $devicetype = "EthSwitch::Mellanox"; }else { - xCAT::MsgUtils->message("E","Config IB switch vlan is not support yet"); + xCAT::MsgUtils->message("E","Config IB switch VLAN is not support yet"); $devicetype = "IBSwitch::Mellanox"; next; } @@ -432,15 +430,15 @@ sub usage To run rspconfig command: configMellanox --switches switchnames --config - To set Vlan for interface commmand (only for Mellanox Ethernet switch) : + 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 + 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"; } From d7c78132ee115468bb5a040b2672c4ea134d6cb6 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Thu, 18 May 2017 09:54:27 -0400 Subject: [PATCH 4/7] Supports range of ports for tagging vlan command --- xCAT-server/share/xcat/scripts/configMellanox | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/configMellanox b/xCAT-server/share/xcat/scripts/configMellanox index 8538eb5b9..ab2e798cc 100755 --- a/xCAT-server/share/xcat/scripts/configMellanox +++ b/xCAT-server/share/xcat/scripts/configMellanox @@ -341,9 +341,22 @@ sub run_rspconfig { } sub config_vlan { + my @ports; + my $port_input; # checking for port number, switches is checked earlier if ($::PORT) { - $port = $::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","Error - When configuring VLAN, a port must be provided."); &usage; @@ -381,28 +394,29 @@ sub config_vlan { 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"; - my $cmd; + 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 . "\""; - print "Tagging VLAN=$vlan for $switch port $port\n"; - - # Build up the commands for easier readability - $cmd = $cmd . "enable\;"; - $cmd = $cmd . "configure terminal\;"; - $cmd = $cmd . "vlan $vlan\;"; - $cmd = $cmd . "exit\;"; - $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\;"; + `$final_cmd` } - $cmd = $cmd . "exit\;exit\;exit\;"; - my $final_cmd = $cmd_prefix . " \"" . $cmd . "\""; - - `$final_cmd` - } } From 56fe5f42393dc6f76e87763a4bb0d17c8341d4e1 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Thu, 18 May 2017 11:27:59 -0400 Subject: [PATCH 5/7] change to < to <= --- xCAT-server/share/xcat/scripts/configMellanox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT-server/share/xcat/scripts/configMellanox b/xCAT-server/share/xcat/scripts/configMellanox index ab2e798cc..8095d3bc6 100755 --- a/xCAT-server/share/xcat/scripts/configMellanox +++ b/xCAT-server/share/xcat/scripts/configMellanox @@ -349,7 +349,7 @@ sub config_vlan { foreach my $num_str (split /,/, $port_input) { if ($num_str =~ /-/) { my ($min, $max) = split (/-/,$num_str); - while ($min < $max) { + while ($min <= $max) { push (@ports,$min); $min++; } From dbf52b4be79aa77e3d3757ef3bdac4f4b2db0ee1 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Tue, 6 Jun 2017 15:37:31 -0400 Subject: [PATCH 6/7] Add global mac address for mallanox switches --- xCAT-server/lib/xcat/plugins/switchdiscover.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/switchdiscover.pm b/xCAT-server/lib/xcat/plugins/switchdiscover.pm index 12b3dc03c..168cf6ea8 100644 --- a/xCAT-server/lib/xcat/plugins/switchdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/switchdiscover.pm @@ -38,6 +38,15 @@ my %global_mac_identity = ( "6c:ae:8b" => "BNT G8264-T switch", "fc:cf:62" => "BNT G8124 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" ); @@ -54,6 +63,8 @@ my %global_switch_type = ( mellanox => "Mellanox", MLNX => "Mellanox", MELLAN => "Mellanox", + Cumulus => "onie", + cumulus => "onie", Edgecore => "onie" ); From d90eafb453448901767f26a6477eb5676c2404d8 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Wed, 7 Jun 2017 14:30:30 -0400 Subject: [PATCH 7/7] modify from code review --- xCAT-server/share/xcat/scripts/configMellanox | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/configMellanox b/xCAT-server/share/xcat/scripts/configMellanox index 8095d3bc6..43dc783b7 100755 --- a/xCAT-server/share/xcat/scripts/configMellanox +++ b/xCAT-server/share/xcat/scripts/configMellanox @@ -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 ( @@ -97,7 +97,7 @@ my $vlan; my $port; my $mode; -#set community string for switch +# set community string for switch my $community = "public"; my @snmpcs = xCAT::TableUtils->get_site_attribute("snmpc"); my $tmp = $snmpcs[0]; @@ -143,7 +143,7 @@ sub config_ip { 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"; @@ -158,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 @@ -166,7 +166,7 @@ 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; @@ -197,7 +197,7 @@ sub config_ip { 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)) { @@ -214,7 +214,7 @@ sub config_ip { } 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); @@ -224,7 +224,7 @@ sub config_ip { 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"; @@ -256,14 +256,14 @@ sub config_hostname { 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; @@ -314,25 +314,25 @@ sub run_rspconfig { $master = `hostname -i`; 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); @@ -358,17 +358,17 @@ sub config_vlan { } } } else { - xCAT::MsgUtils->message("E","Error - When configuring VLAN, a port must be provided."); + xCAT::MsgUtils->message("E"," When configuring VLAN, a port must be provided."); &usage; exit(1); } - #will default to trunk mode + # will default to trunk mode if ($::MODE) { $mode = $::MODE; if (!($mode =~ m/(access|trunk|hybrid|access-dcb|dot1q-tunnel)/) ) { - xCAT::MsgUtils->message("E","Error - Please provided supported mode"); + xCAT::MsgUtils->message("E"," Please provided supported mode"); &usage; exit(1); } @@ -396,7 +396,7 @@ sub config_vlan { print "Tagging VLAN=$vlan for $switch port $port_input\n"; - #create vlan + # create vlan my $vlan_cmd = `xdsh $switch --devicetype $devicetype "enable;configure terminal;vlan $vlan;exit;exit" `; my $cmd_prefix = "xdsh $switch --devicetype $devicetype";