Python cisco config parser

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

License

mapcollab/python-ciscoconfparse

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.rst

Travis CI Status

  • Introduction: What is ciscoconfparse?
  • User Testimony
  • What if we don’t use Cisco?
  • Docs
  • Pre-requisites
  • Installation and Downloads
  • FAQ
  • Other Resources
  • Bug Tracker and Support
  • Unit-Tests
  • License and Copyright
  • Author and Thanks

ciscoconfparse is a Python library, which parses through Cisco IOS-style (and other vendor) configurations. It can:

  • Audit existing router / switch / firewall / wlc configurations
  • Retrieve portions of the configuration
  • Modify existing configurations
  • Build new configurations

The library examines an IOS-style config and breaks it into a set of linked parent / child relationships. You can perform complex queries about these relationships.

CiscoConfParse Parent / Child relationships

These are a few selected public mentions about CiscoConfParse; I usually try not to share private emails without asking, thus the quotes aren’t long at this time.

CiscoConfParse Github Issue #17 Reddit comment Netnea testimony Twitter mentions

As of CiscoConfParse 1.2.4, you can parse brace-delimited configurations into a Cisco IOS style (see Github Issue #17), which means that CiscoConfParse understands these configurations:

«>» CiscoConfParse also handles anything that has a Cisco IOS style of configuration, which includes:

  • Cisco IOS, Cisco Nexus, Cisco IOS-XR, Cisco IOS-XE, Aironet OS, Cisco ASA, Cisco CatOS
  • Arista EOS
  • Brocade
  • HP Switches
  • Force 10 Switches
  • Dell PowerConnect Switches
  • Extreme Networks
  • Enterasys

ciscoconfparse requires Python versions 2.6, 2.7 or 3.2+; the OS should not matter. If you want to run it under a Python virtualenv, it’s been heavily tested in that environment as well.

The best way to get ciscoconfparse is with setuptools or pip. If you already have setuptools, you can install as usual:

# Substitute whatever ciscoconfparse version you like. easy_install -U ciscoconfparse==1.2.47

Alternatively you can install into Python2.x with pip:

pip install --upgrade ciscoconfparse
pip3 install --upgrade ciscoconfparse

Otherwise download it from PyPi, extract it and run the setup.py script:

If you’re interested in the source, you can always pull from the github repo or bitbucket repo:

git clone git://github.com//mpenning/ciscoconfparse
hg init hg clone https://bitbucket.org/mpenning/ciscoconfparse
  1. QUESTION: I want to use ciscoconfparse with Python3; is that safe? ANSWER: As long as you’re using Python 3.3 or higher, it’s safe. I test every release against Python 3.2+; however, Python 3.2 is currently exposed to a small bug for some configurations (see Github Issue #14).
  2. QUESTION: Some of the code in the documentation looks different than what I’m used to seeing. Did you change something? ANSWER: Yes, starting around ciscoconfparse v0.9.10 I introducted more methods directly on IOSConfigLine() objects; going forward, these methods are the preferred way to use ciscoconfparse. Please start using the new methods shown in the example, since they’re faster, and you type much less code this way.
  3. QUESTION: ciscoconfparse saved me a lot of time, I want to give money. Do you have a donation link? ANSWER: I love getting emails like this; helping people get their jobs done is why I wrote the module. However, I’m not accepting donations.
  4. QUESTION: Is there a way to use this module with perl? ANSWER: Yes, I do this myself. Install the python package as you normally would and import it into perl with Inline.pm and Inline::Python from CPAN.
  5. QUESTION: When I use find_children(«interface GigabitEthernet3/2») , I’m getting all interfaces beginning with 3/2, including 3/21, 3/22, 3/23 and 3/24. How can I limit my results? ANSWER: There are two ways. the simplest is to use the ‘exactmatch’ option. find_children(«interface GigabitEthernet3/2», exactmatch=True) . Another way is to utilize regex expansion that is native to many methods. find_children(«interface GigabitEthernet3/2$»)
  • Dive into Python3 is a good way to learn Python
  • Team CYMRU has a Secure IOS Template, which is especially useful for external-facing routers / switches
  • Cisco’s Guide to hardening IOS devices
  • Center for Internet Security Benchmarks (An email address, cookies, and javascript are required)
  • Please report any suggestions, bug reports, or annoyances with ciscoconfparse through the github bug tracker.
  • If you’re having problems with general python issues, consider searching for a solution on Stack Overflow. If you can’t find a solution for your problem or need more help, you can ask a question.
  • If you’re having problems with your Cisco devices, you can open a case with Cisco TAC; if you prefer crowd-sourcing, you can ask on the Stack Exchange Network Engineering site.

Travis CI project tests ciscoconfparse on Python versions 2.6 through 3.5, as well as a pypy JIT executable.

Click the image below for details; the current build status is:

Travis CI Status

ciscoconfparse was written by David Michael Pennington (mike [~at~] pennington [/dot] net).

  • Thanks to David Muir Sharnoff for his suggestion about making a special case for IOS banners.
  • Thanks to Alan Cownie for his API suggestions.
  • Thanks to CrackerJackMack for reporting Github Issue #13
  • Soli Deo Gloria

Источник

cisco-config-parser 1.3.4

This Package Will Parse Cisco IOS, IOS-XE, IOS-XR and NXOS Configuration File.

Ссылки проекта

Статистика

Метаданные

Лицензия: MIT License

Сопровождающие

Описание проекта

Cisco Configuration Parser

This Package Will Parse Cisco IOS, IOS-XE, IOS-XR, and NXOS Configuration File.

There are two ways to parse the config, 1, SSH which is not recommended, and 2, feeding the running-config file

           device types that are accepted are:
pass the kwargs then it will login to your device and does the show running-config and will parse it.

Install the package

interface TenGigE0/3/0/29.3240 10.10.1.1 255.255.255.248 10.10.1.0/29 description Connected to device_A vrf vrf_A no shutdown ! interface TenGigE0/3/0/29.3340 10.244.10.1 255.255.255.252 10.244.10.0/30 description Connected to device_A vrf vrf_B no shutdown 
  • Getting Switchport: there are two different mode on switchport, access and trunk . you should specify the mode mode=trunk or mode=access . this way you will be able to access all the access-ports or trunk-ports by accessing the methods (get_access or get_trunk)
 interface GigabitEthernet10/38 Access Port Vlan 200 Voice vlan 700 description ent-user ! interface GigabitEthernet10/38 Access Port Vlan 200 Voice vlan 700 description ent-user 
router eigrp 252 ! address-family ipv4 vrf vrf_A autonomous-system 252 network 10.10.10.0 0.0.0.63 passive-interface default no passive-interface Vlan3123 no passive-interface Vlan3124 eigrp stub connected summary exit-address-family ! address-family ipv4 vrf vrf_B autonomous-system 252 network 10.20.10.0 0.0.0.3 network 10.20.11.0 0.0.0.3 passive-interface default no passive-interface Vlan3223 no passive-interface Vlan3224 eigrp stub connected summary exit-address-family ! 
interface Vlan200 ip helper-address 192.168.1.10 ip helper-address 172.31.10.10 
interface Vlan200 ip address 10.20.80.1 255.255.254.0 description USER VLAN- ip vrf forwarding vrf_A no shutdown [' ip helper-address 10.10.1.10 ', ' ip helper-address 10.20.1.10'] ! 

Источник

Introduction¶

ciscoconfparse is a Python library, which parses through Cisco IOS-style configurations. It can:

  • Audit existing router / switch / firewall / wlc configurations against a text configuration template
  • Retrieve portions of the configuration
  • Modify existing configurations
  • Build new configurations

The library examines an IOS-style config and breaks it into a set of linked parent / child relationships; each configuration line is stored in a different IOSCfgLine object.

ciscoconfparse overview

Then you issue queries against these relationships using a familiar family syntax model. Queries can either be in the form of a simple string, or you can use regular expressions. The API provides powerful query tools, including the ability to find all parents that have or do not have children matching a certain template.

The package also provides a set of methods to query and manipulate the IOSCfgLine objects themselves. This gives you a flexible mechanism to build your own custom queries, because the IOSCfgLine objects store all the parent / child hierarchy in them.

What is ciscoconfparse good for?¶

After several network evolutions, you may have a tangled mess of conflicting or misconfigured network devices. Misconfigurations of proxy-arp, static routes, FHRP timers, routing protocols, duplicated subnets, cdp, console passwords, or aaa schemes have a measurable affect on up time and beg for a tool to audit them. However, manually scrubbing configurations is a long and error-prone process.

Audits aren’t the only use for ciscoconfparse. Let’s suppose you are working on a design and need a list of dot1q trunks on a switch with more than 400 interfaces. You can’t grep for them because you need the interface names of layer2 trunks; the interface name is stored on one line, and the trunk configuration is stored somewhere below the interface name. With ciscoconfparse, it’s really this easy…

>>> from ciscoconfparse import CiscoConfParse >>> parse = CiscoConfParse(‘/tftpboot/largeConfig.conf’) >>> trunks = parse.find_parents_w_child(«^interface», «switchport trunk») >>> for intf in trunks: . print(intf) interface GigabitEthernet 1/7 interface GigabitEthernet 1/23 interface GigabitEthernet 1/24 interface GigabitEthernet 1/30 interface GigabitEthernet 3/2 interface GigabitEthernet 5/10

So you may be saying, that all sounds great, but I have no idea what you did with that code up there. If so, don’t worry… There is a tutorial following this intro. For more depth, I highly recommend Dive into Python3.

We don’t have Ciscos¶

Don’t let that stop you. CiscoConfParse parses anything that has a Cisco IOS style of configuration, which includes:

  • Cisco IOS, Cisco Nexus, Cisco IOS-XR, Cisco IOS-XE, Aironet OS, Cisco ASA, Cisco CatOS
  • Arista EOS
  • Brocade
  • HP Switches
  • Force 10 Switches
  • Dell PowerConnect Switches
  • Extreme Networks
  • Enterasys

As of CiscoConfParse 1.2.4, you can parse brace-delimited configurations into a Cisco IOS style (see Github Issue #17), which means that CiscoConfParse understands these configurations too:

  • Juniper Networks Junos, and Screenos
  • Palo Alto Networks Firewall configurations
  • F5 Networks configurations
  • Terraform .tf files

Quotes¶

These are a few selected public mentions about CiscoConfParse; I usually try not to share private emails without asking, thus the quotes aren’t long at this time.

CiscoConfParse Github issue #13

Reddit comment - 20150328

What’s new in version 1.0.0¶

I wrote ciscoconfparse in 2007 as literally my first Python project; through the years, my understanding of Python improved, and I also found many missing features along the way. Some of these features, like changing a configuration after it was parsed, required non-trivial changes to the whole project.

Starting in version 0.9, I initiated a major rewrite; several important changes were made:

  • Python3.x compatibility; Python2.4 deprecation
  • Major improvement in config parsing speed
  • Much better unit-test coverage
  • Too many bug fixes to count
  • New feature — ciscoconfparse inserts, deletes and appends config lines
  • Rearchitected the library, with an eye towards more future improvements
  • Revisions in scripting flow. All users are encouraged to use IOSCfgLine() objects whenever possible. Typically, you’ll start by matching them with find_objects() . Working directly with IOSCfgLine() objects makes your scripts less complicated and it also makes them faster than using legacy ciscoconfparse syntax.

Table of Contents

Источник

Читайте также:  Vim run python code
Оцените статью