Monday, June 12, 2017

Create Interface Descriptions from CDP Neighbor Output

Most customers want interface descriptions on core switch ports that are connected to edge switches and edge switch ports that are connected to access points or other critical devices. When you are doing a green field design this is usually pretty easy and you can include the descriptions in your spreadsheet data and they are automatically inserted when you run the template.

But there are times when you are in the field and need to create a lot of descriptions. Doing this manually is tedious, time-consuming and error-prone. To work around this I wrote a simple Python script to create the interface descriptions. Here are the instructions to use it.

Quick Steps

Download the script from my Github page 
Log onto the switch and run
sh cdp ne det | i  Dev|Interface
This will display the device name and interface for each neighbor
Copy the output and save it in a text file called interface.txt in the same folder as the script
Run the script. This will output the code needed on the screen.
Note: this isn't a double click to run script, you need to run the script from the terminal or command line. If you want to double click to run it add
input('Press <ENTER> to continue') to the very end. Make sure the statement isn't indented, it should start at column 1. 
Copy the code and paste it into the switches 

Detailed Steps

If you haven’t used Github before don’t worry. It’s simple to download the script, just click the “Clone or download” button once you are on the page. 
Click the “Download Zip” link. If you have Git installed you can also copy the link and use git clone to download the file.

Log onto the switch you want to update.
Type sh cdp ne det | i Dev|Interface to display the neighbors and their interfaces
Copy from the first Device ID to the last interface


Paste this into a text editor and save it as interface.txt in the same folder as the script. If you don’t want DNS suffixes included do a search and replace before saving the file.

Run the script using python3 interface.txt. This will display the code needed to update the descriptions. Copy from the screen and paste into the switch.
mhubbard@1S1K-SYS76:~/Dropbox/Python/Scripts$ python3 interface.py 

Interface GigabitEthernet1/0/1
des < ISHS-IDFG-GDAT-G1 >
exit

Interface GigabitEthernet1/0/3
des < ISHS-IDFG-GDAT-G3 >
exit

Interface GigabitEthernet1/0/2
des < ISHS-IDFG-GDAT-G2 >
exit

Interface GigabitEthernet1/0/4
des < ISHS-IDFG-GDAT-G4 >
exit

Interface GigabitEthernet1/0/49
des < ISHS-6880X.sbc-district.local >
exit

That does it for this simple script, I hope you find it useful!

Remember - Automate or perish!



No comments:

Post a Comment