jamiecaesar / securecrt-tools

SecureCRT scripts, written in Python, for doing various tasks when connected to Cisco equipment.
Apache License 2.0
252 stars 77 forks source link

Support for Cisco IOS XR devices #34

Closed joshniec closed 5 years ago

joshniec commented 6 years ago

Hey, great addition to SecureCRT, makes a lot of things very easy to gather. I haven't had time myself and just played around with the code a little bit, but do you already have plans to add support for Cisco IOS XR software?

jamiecaesar commented 6 years ago

That is something that would be great to have added to the scripts. I haven't had hands-on time with IOS XR yet, which is the main reason why it hasn't been added. A quick search makes it seem like it is possible to get a virtual device going (GNS3, possibly), so if I find some extra time (the hardest part) to get it set up I could at least get it detecting the OS and making sure the basic scripts work (save running, save output, etc). Any of the scripts that need to parse the output would need to be re-worked individually because we'd need new TextFSM templates that can parse the XR outputs.

joshniec commented 6 years ago

I actually had some time to play around with the code and modify it to work with IOS XR. I haven’t fully validated all of the premade scripts you created, and I plan on doing some more minor changes to the code to support IOS XR. I can submit a pr maybe this weekend with some of the changes I made so that you can take a look at them. TextFSM actually has templates for IOS XR, though I know for the interface stats template there is a regex error where it doesn’t capture the IP address that I had to manually fix.

I had also changed the print statements so that the code runs with python3.

jamiecaesar commented 6 years ago

Sounds good. I created a branch called "ios-xr" that you can make to pull request to. That way I can try out the updated code on existing devices to make sure nothing else broke before merging it into the master branch. Thanks for taking some time to work on adding it!

joshniec commented 6 years ago

Cool, I’ll check it out - I have access to work lab equipment, IOS, XR and ASAs just not NXOS to test out any changes on.

tylersiemers commented 5 years ago

Was this every added for support? If not can I just modify the definition:

def __get_network_os(self)

to include:

elif "IOS XR" in raw_version or "Cisco Internetwork Operating System" in raw_version: version = "IOS"

Then call a custom command list of "XR" from the setting.ini that has a list of show commands.

jamiecaesar commented 5 years ago

No, this hasn't been done yet. I don't have access to any IOS XR devices (I assume I could probably use something to simulate one, like EVE or VIRL, but I haven't had the time to really dig into that).

I've updated the ios-xr branch to the latest code from the master branch a minute ago, so feel free to pull the updated version, make changes to support IOS XR and push it back to that branch.

You are right that you should only need to modify that one method (__get_network_os) to recognize when it is an IOS XR device and saves the OS to the self.version variable. I've never seen the XR CLI is, so some of the other methods that detect the prompt, etc might need some updates also to interact properly.

Most of the other scripts have OS checks that will either issue a different command, and/or select a different TextFSM template that will parse the IOS XR output, so once it can recognize an XR device we can just update individual scripts to support XR as needed. By default those would exit without doing anything and pop an unsupported OS message until we add support for XR to them.

tylersiemers commented 5 years ago

Thanks. That works fine just need to work on the hostname for XR. If I get time I will upload. XR has the current RSP before the hostname.

RP/0/RP0/CPU0:LAB-NCS540-2

It creates a directory with the following:

\ScriptOutput\RP\0\RP0

and a file name CPU0. Which has none of the script output in it.

jamiecaesar commented 5 years ago

I put some code into the sessions.create_output_filename() method to strip out all the characters you can't use in filenames, but that code wouldn't be used when trying to create a directory. Maybe I need to pull that bit of code into a separate function that can be called from a few different places (probably put it in the utilities file). That way you don't have to muck with the hostname that is stored -- it only gets changed when generated file/directory names.

jamiecaesar commented 5 years ago

Closing this now that the base module can recognize IOS XR. Some scripts still need to be updated to support XR, but those can be done via pull request.