Script to get list of EDP links

  • 0
  • 1
  • Problem
  • Updated 4 years ago
  • (Edited)
Hello,

I am currently moving one of our VLANs over to a new subnet range.  Since we've got over a hundred switches in production now, this is not something I want to do manually on each one.

I've successfully written a script that looks at the old VLAN, grabs the last octet of the IP, and gives the new VLAN an IP address using that same last octet.  (IE, 10.10.10.152 would become 10.11.11.152, or whatever).  Ran that successfully, not a problem.

The difficulty I'm having now is making sure that the new VLAN is added to all trunk ports between switches.  I'm attempting to do a "show edp all" and in the end, I would like to end up with a list of all ports that show up in EDP.  I think most of my problem is that I'm unsure of exactly how the TCL syntax interacts with the extreme scripting language.  Here's what I've gotten so far:


----------

# Get the table of EDP links and break it into a list, and get a count of the number of elements
set var CLI.OUT " "
show edp port all
set var len $TCL(llength ${CLI.OUT})
set var edp_list $TCL(split ${CLI.OUT} "\n")

show var edp_list
show var len

# Find the position of the borders (looking for at least 5 ='s in a row)
set var count 0
set var regex ={5,}

while ($count < $len) do
set var current $TCL(lindex $edp_list $count)

[[Here's where I get confused with syntax]]

------

So, I've successfully pulled out the show EDP ports command and split it up.  My idea was to try to find the index of the borders (===========) and use that as a way to define which index numbers hold actual port descriptions.  So if the borders are at index 3 and 10, I'd spit out indexes 4-9.  From there, I would need to pull the first two characters, and add them to a new list ( $TCL(lappend) I believe).  Finally, I could do a while statement to add each of the ports in the list to the VLAN I want.

Anyone have any ideas as to syntax?  I fully admit my coding skills are not up to my networking skills.  :)
Photo of Jason Place

Jason Place

  • 90 Points 75 badge 2x thumb

Posted 4 years ago

  • 0
  • 1
Photo of Jason Place

Jason Place

  • 90 Points 75 badge 2x thumb
Okay, I've managed to get a bit further.  This bit successfully gives you the indices of the borders.  Ignore the extraneous shows, just using them to keep tabs on the script as it runs.

# Find the position of the borders (looking for at least 5 ='s in a row)

set var count 0
set var regex ={5,}

WHILE ($count < $len) do set var curr $TCL(lindex $edp_list $count)
set var RegCompare $TCL(lsearch -regexp $curr $regex)
IF ($RegCompare == 0) THEN
show var count
set var portrange $TCL(lappend portrange $count)
ELSE
ENDIF
set var count ($count+1)
ENDWHILE
show var portrange
(Edited)
Photo of Jason Place

Jason Place

  • 90 Points 75 badge 2x thumb
Okay, apparently, I got into code-brain today.  I've got it working, so here's a reference for anyone that needs it.  This will return the variable portlist which will give you all the EDP ports in a single numerical list.  Do as you will with the variable once you have it.

# Get the list of EDP links and break it into a list, and get a count of the number of elements
set var CLI.OUT " "
show edp port all
set var len $TCL(llength ${CLI.OUT})
set var edp_list $TCL(split ${CLI.OUT} "\n")

# Find the position of the borders (looking for at least 5 ='s in a row)
set var count 0
set var regex ={5,}
WHILE ($count < $len) do
	set var curr $TCL(lindex $edp_list $count)
	set var RegCompare $TCL(lsearch -regexp $curr $regex)
	IF ($RegCompare == 0) THEN
		set var portrange $TCL(lappend portrange $count)
	ELSE
	ENDIF
	set var count ($count+1)
ENDWHILE


#Break each port information line into another list, then grab the first item in the list, which is the port

set var count $TCL(lindex $portrange 0)
set var count ($count+1)
set var end $TCL(lindex $portrange 1)

WHILE ($count < $end) do
	set var curr $TCL(lindex $edp_list $count)
	set var curr $TCL(split $curr " ")
	set var curr $TCL(lindex $curr 0)
	set var portlist $TCL(lappend portlist $curr)
	set var count ($count+1)
ENDWHILE
show var portlist


#Cleanup
delete var edp_list
delete var len
delete var count
delete var curr
delete var RegCompare
delete var regex
delete var portrange
delete var end
delete var portlist