VRFSearchAndBackup.py v1.0.3 (2015-02-16)

February 20, 2015 — Leave a comment

As you might have noticed form this week’s blog posts, I enjoy writing code to automate tedious or time consuming tasks.  Well, maybe it might be a stretch to say I enjoy it — but I certainly reap the benefit of putting in the hard work to automate tasks that I otherwise hate performing.  I do, however, enjoy publishing much of this code on the Internet in hopes that others will find it useful and I occasionally hear from them stating such.

In a past life, as a Network Engineer, I wrote a small application which automates the ability to search a Cisco router for a VRF VPN profile and back it up to disk.  (If you’re making changes to your Cisco routers and you don’t back up your configurations before you change them, then you obviously haven’t broken one yet.)  I received a lot of feedback from other people who found this tool to be useful and use it regularly.  I also recently received word that it doesn’t work under Cisco IOS 15.4.

That sucks.

Specifically, it blows up right about here:

[code language=”text”]

VRFSearchAndBackup.py v1.0.1 (2014-03-17)

–> Index found and appears up to date.

Enter the VRF Name or IP Address you are searching for: USG-10195

| ABC-12345 | | |
| ABC-12345 | | |

Do you want to back up this configuration now? [Y/n]

–> Logging into…
–> Backing up ABC-12345 …
Traceback (most recent call last):
File "<string>", line 534, in <module>
File "<string>", line 413, in searchIndex
File "<string>", line 176, in backupVRF
AttributeError: ‘NoneType’ object has no attribute ‘group’


I had to back-track through the code to discover what was causing this error.  It seems that my application was not stripping any whitespace from the input when the user provided the search search string to the program.  Therefore, the program was passing “show running-config | section ABC-12345 ” (with a trailing space) to the router.  Older versions of Cisco IOS were either not as picky about the trailing space or ignored it all together — I’m not sure.

Either way, this trailing space caused the function to fail because the output returned by the router failed to include the Route Descriptor REGEX was searching for thereby causing the whole thing to bomb.

I found the offending piece of code in the searchIndex function and changed it from:

[code language=”python”]vrfName = word[0][/code]


[code language=”python”]vrfName = word[0].strip[/code]

That corrected the error reported by the user who was happy, by the way, that I resolved the issue.

You can find the most recent version of code for this project on it’s GitHub repository.

Aaron Melton


No Comments

Be the first to start the conversation.

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>