cancel
Showing results for 
Search instead for 
Did you mean: 

B-Series with multiple ports

B-Series with multiple ports

cslayton
New Contributor

I have a python script that I’m using for B-series switches to configure multiple ports at the same time.

 

#@METADATASTART
#@ScriptDescription "Change port from static to NAC".
#@DetailDescriptionStart
##############################################################################
#
#Purpose: "Change port from static to NAC".
#
# Version : 1.0
#
# This script deletes selected ports from all vlans, sets "display-string" and
# "description-string" to "NAC_Port".  Finally, the configuration is saved.
##############################################################################
#@DetailDescriptionEnd
#
#@MetaDataEnd
import re
import commands

def main():
    
    if "port" in emc_vars:
        ports = emc_vars["port"]
    else:
        print "Please select at least one PORT if you start the script"
        return 0
    
    cli_result = emc_cli.send("clear port vlan " + ports)  

main()

However, I get the following output:

deerl1sw006(su)->clear port vlan ge.1.7,ge.1.8
Invalid Port in [port-string]. 

The B-Series switch needs to use ; instead of , to separate interfaces.  Is there anyway to fix this?

Chuck

 

1 ACCEPTED SOLUTION

StephanH
Valued Contributor III

Hello Chuck,

 

try this:

 

#@METADATASTART
#@ScriptDescription "Change port from static to NAC".
#@DetailDescriptionStart
##############################################################################
#
#Purpose: "Change port from static to NAC".
#
# Version : 1.0
#
# This script deletes selected ports from all vlans, sets "display-string" and
# "description-string" to "NAC_Port". Finally, the configuration is saved.
##############################################################################
#@DetailDescriptionEnd
#
#@MetaDataEnd
import re
import commands

def main():

if "port" in emc_vars:
ports = emc_vars["port"].split(",") #create a list with all ports
else:
print "Please select at least one PORT if you start the script"
return 0

portcounter = 0
for port in ports: #walk through the list
if portcounter == 0:
portstring = port
else:
portstring = portstring + ";" + port #fill in the separator you need
portcounter += 1

cli_result = emc_cli.send("clear port vlan " + portstring)

main()

 

Regards Stephan

View solution in original post

15 REPLIES 15

cslayton
New Contributor

The code you posted is working fine.  I am trying to create a function out of the section that creates a list of all ports and then call that function.

 

Error:  SyntaxError: ("no viable alternative at input '('", ('<string>', 19, 3, 'def(port_list):\n'))

StephanH
Valued Contributor III

Hello Cuck,

what isn’t working?

Error message?

 

Regards Stephan

cslayton
New Contributor

Trying to further refine this by creating functions, but the below doesn’t work.

 

import re
import commands

def(port_list):
    if "port" in emc_vars:
        ports = emc_vars["port"].split(",") #create a list with all ports
    else:
        print "Please select at least one PORT if you start the script"
        return 0
    
    portcounter = 0
    for port in ports: #walk through the list
        if portcounter == 0:
            portstring = port
        else:
            portstring = portstring + ";" + port #fill in the separator you need
        portcounter += 1
    
def main():

    cli_result = emc_cli.send("clear port vlan " + portstring)  
    cli_result = emc_cli.send("set port alias " + portstring + " NAC")
    cli_result = emc_cli.send("set macauthentication port enable " + portstring)
    cli_result = emc_cli.send("set multiauth port mode auth-reqd " + portstring)
    cli_result = emc_cli.send("set multiauth port numusers 4 " + portstring)
    cli_result = emc_cli.send("set pwa portcontrol enable " + portstring)
    cli_result = emc_cli.send("save config")

port_list() 
main()

cslayton
New Contributor

Thanks so Much!

StephanH
Valued Contributor III

Hello Chuck,

 

try this:

 

#@METADATASTART
#@ScriptDescription "Change port from static to NAC".
#@DetailDescriptionStart
##############################################################################
#
#Purpose: "Change port from static to NAC".
#
# Version : 1.0
#
# This script deletes selected ports from all vlans, sets "display-string" and
# "description-string" to "NAC_Port". Finally, the configuration is saved.
##############################################################################
#@DetailDescriptionEnd
#
#@MetaDataEnd
import re
import commands

def main():

if "port" in emc_vars:
ports = emc_vars["port"].split(",") #create a list with all ports
else:
print "Please select at least one PORT if you start the script"
return 0

portcounter = 0
for port in ports: #walk through the list
if portcounter == 0:
portstring = port
else:
portstring = portstring + ";" + port #fill in the separator you need
portcounter += 1

cli_result = emc_cli.send("clear port vlan " + portstring)

main()

 

Regards Stephan
GTM-P2G8KFN