cancel
Showing results for 
Search instead for 
Did you mean: 

Remove port from vlan

Remove port from vlan

cslayton
New Contributor

I’m using a python script to configure a switchport, but I need to find the current untagged vlan, then use the value of the untagged vlan to remove the associated port.

 get_port_info = emc_cli.send("show port " + ports + " info detail | grep Internal")


The above command generates this output:

Name: Auth-RSTP-VLAN, Internal Tag = 4090, MAC-limit = No-limit, Virtual router:   VR-Default

So, in this case, I want to create a variable for “4090” 
configure vlan 4090 delete port <oort number>

 

Can someone point me in the right direction?

1 ACCEPTED SOLUTION

StephanH
Valued Contributor III

Hello Chuck,

maybe it’t easiert to use “show port <port number> vid”. Here the output is smaller.

Yes the result from cli in the variable port_info is a string.

 

You can do the following. Please be aware that “Untagged” matches two times. First in the header of the cli output and second in the line where the vlan is shown. But that’s not a problem because of the for loop overwrites the first output.

 

import re

cli_result = emc_cli.send("show port <port number> vid")
vlanInfo = cli_result.getOutput()

vlanInfoLines = vlanInfo.split("\n")  #receive a list containing the lines from output

for line in vlanInfoLines:  #loop through the lines
    print line
    if "Untagged" in line: #check if you can see the word Untagged
        vlanId = line.split() #split the line  by white spaces
print ("Untagged vlan id is: " + vlanId[1]) #take the second element from the list
 

#If you more like regex (maybe more flexible)

for line in vlanInfoLines:
    untaggedLine = re.search("Untagged\s*(\d*)", line)
    if untaggedLine:
        vlanByReg = untaggedLine.group(1)
    
print ("Untagged vlan id is: " + vlanByReg)
 

Regards

Stephan

 

 

Regards Stephan

View solution in original post

3 REPLIES 3

StephanH
Valued Contributor III

Hello Chuck,

maybe it’t easiert to use “show port <port number> vid”. Here the output is smaller.

Yes the result from cli in the variable port_info is a string.

 

You can do the following. Please be aware that “Untagged” matches two times. First in the header of the cli output and second in the line where the vlan is shown. But that’s not a problem because of the for loop overwrites the first output.

 

import re

cli_result = emc_cli.send("show port <port number> vid")
vlanInfo = cli_result.getOutput()

vlanInfoLines = vlanInfo.split("\n")  #receive a list containing the lines from output

for line in vlanInfoLines:  #loop through the lines
    print line
    if "Untagged" in line: #check if you can see the word Untagged
        vlanId = line.split() #split the line  by white spaces
print ("Untagged vlan id is: " + vlanId[1]) #take the second element from the list
 

#If you more like regex (maybe more flexible)

for line in vlanInfoLines:
    untaggedLine = re.search("Untagged\s*(\d*)", line)
    if untaggedLine:
        vlanByReg = untaggedLine.group(1)
    
print ("Untagged vlan id is: " + vlanByReg)
 

Regards

Stephan

 

 

Regards Stephan

cslayton
New Contributor

Thanks StephanH!  I’m almost there.  I need to search the output (maybe using regex?) to get the Vlan ID (4090) so that I can send this command:

get_port_change= emc_cli.send("configure vlan <vlan id var> delete port <oort number>" )

 

Is port_info a string?

Chuck

StephanH
Valued Contributor III

Hello Cslayton,

I am not sure where exactly you get stuck. But below you can see how to get the output into a variable

    get_port_info= emc_cli.send("show port " + ports + " info detailconfigure vlan 4090 delete port <oort number> | grep Internal" )

   port_info = get_port_info.getOutput()

 

get_port_change= emc_cli.send("configure vlan 4090 delete port <oort number>" )
  

Regards

Stephan

 

Regards Stephan
GTM-P2G8KFN