INTRO
=====
ciscoconfparse is a module for parsing through Cisco IOS-style configurations
and retrieving portions of the config based on a variety of query methods.

The package will process an IOS-style config and break it into a set of
linked parent / child relationships.  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 criteria.  This means it is 
easy to find the interface names of all layer2 trunks in a Catalyst 6500,
or retrieve a list of all interfaces with cdp disabled.  Until this package,
I know of no simple config-parsing APIs to do the same; it has traditionally 
been considered the domain of screen-scraping.  In conjunction with python's
sophisticated set-manipulation capabilities, your imagination is the limit.

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

Examples of config family relationships are shown below...

Line01:policy-map QOS_1
Line02: class GOLD
Line03:  priority percent 10
Line04: class SILVER
Line05:  bandwidth 30
Line06:  random-detect
Line07: class default
Line08:!
Line09:interface Serial 1/0
Line10: encapsulation ppp
Line11: ip address 1.1.1.1 255.255.255.252
Line12:!
Line13:access-list 101 deny tcp any any eq 25 log
Line14:access-list 101 permit ip any any

 parents: 01, 02, 04, 09
 children: of 01 = 02, 04, 07
           of 02 = 03
           of 04 = 05, 06
           of 09 = 10, 11
 siblings: 02, 04, 07
           05, 06
           10, 11
 oldest_ancestors: 01, 09
 families: 01, 02, 03, 04, 05, 06, 07
           09, 10, 11
 family_endpoints: 07, 11

Note that 01, 09, 13 and 14 are not considered siblings, nor are they part 
of the same family.  In fact, 13 and 14 do not belong to a family at all; they
have no children.


BASIC USAGE
===========
#!/usr/bin/env python
from ciscoconfparse import *

parse = CiscoConfParse("/tftpboot/bucksnort.conf")

# Return a list of all ATM interfaces and subinterfaces
#
atm_intfs = parse.find_lines("^interface\sATM")

# Return a list of all interfaces with a certain QOS policy
#
qos_intfs = parse.find_parents_w_child( "^interf", "service-policy QOS_01" )

# Return a list of all active interfaces (i.e. not shutdown)
#
active_intfs = parse.find_parents_wo_child( "^interf", "shutdown" )

# Find all interfaces that have voice configured, if they are trusting dscp
# build a new config to trust cos
#
newcfg = []
voice_intfs = parse.find_parents_w_child("^interface", "switchport voice")
for intf in voice_intfs:
   famobj = CiscoConfParse( parse.find_children( intf, True ) )
   if( famobj.find_lines("mls qos trust dscp") ):
      newcfg.append(intf)
      newcfg.append(" mls qos trust cos")


The examples/ directory in the distribution contains more usage cases, 
including sample configs to parse.  When enforcing configuration standards,
the req_cfgspec_excl_diff() method is very useful; examples of its usage are
included.

I have moved all hosting to sourceforge... and I'm using the sourceforge
wiki for detailed documentation.
http://ciscoconfparse.wiki.sourceforge.net/


AUTHOR
======
David Michael Pennington, mike /|at|\ pennington.net


THANKS
======
Thanks to David Muir Sharnoff for his suggestion about making a special
case for IOS banners.  Thanks to everyone in advance for their bug reports 
and patience.  Sola Dei Gloria.


COPYRIGHT, LICENSE, and WARRANTY
================================
GNU General Public License, v3

ciscoconfparse.py - Parse & Query IOS-style configurations
Copyright (C) 2007 David Michael Pennington

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see http://www.gnu.org/licenses/.

If you need to contact the author, you can do so by emailing:
mike [~at~] pennington [/dot\] net

