Question

Does anyone have a script to get the ports in a VLAN and then create a new VLAN and add those ports to it?

  • 2 May 2019
  • 4 replies
  • 370 views

Userlevel 2
We routinely create new VLANs that have the same ports as our "golden" VLAN. I was curious if a) it's possible and b) if anyone has a script that would prompt for the name of the new VLAN and tag, and then create a new VLAN that containing the same ports as the ones in our reference VLAN?

4 replies

Userlevel 3
What switch ? XOS ?
And where would you run the script from ? XMC or XOS ?
Userlevel 2
Currently we would be running it on a X460-48t running 16.2.4.5, but that will eventually be replaced by an X440-G2. We do have XMC, so preferable using that but we could also run it via XOS.
Userlevel 5
Hi Stephen,

Never tried such script yet, but it would be a nice challenge to create one that could 'clone' a VLAN of specific tag, based on a reference VLAN.
Pseudocode could be as follows:
  1. Show vlan [reference VID from user form in XMC or XOS prompt] | begin "Tag:"
  2. Parse the output string to get a 1-dimensional table with ports
  3. Loop for each port (or for i = 0:length(table)-1): configure vlan [target VID from user form in XMC or XOS prompt] add port [port from the table] tagged
XMC Python script could be the most robust option for that I believe.
If you wanted, you could also create a workflow with XMC 8.2 to determine a switch OS type and run a script for that which is OS-relevant, so you would have such workflow flexible to configure a group of mixed-OS devices.

Hope that helps,
Tomasz

P.S. After a while I see no sense in my "loop for each port". They can rather be merged and comma separated from the table (or spaces removed from the original CLI output without even playing with a table) and one shot to add them all is enough then.
Userlevel 3
What if your seed VLAN has untagged ports ?

Reply