views:

375

answers:

1

Is there either:

A freely available program that can convert the output of a Cisco's "show conf" to some sensible XML, like this (probably not very sensible) block form: Is there either:

A freely available program that can convert the output of a Cisco's "show conf" to some sensible XML, like this (probably not very sensible) block form:

<aaa>
  <new-model/>
  <authentication>
    <login>
      <default>
        <group id="tacacs+">enable</group>
      </defult>
    </login>

    <!-- ...etc... -->

  </authentication>
</aaa>

...or, if not, at an XML schema that I could look to implement? Without a deep understanding of the IOS syntax, building up the schema is proving to be tricky.

A: 

Cisco provides no schema for IOS configurations. However, you may have two options:

  • Cisco's IOS XR has built-in XML support. Depending on the model of your router you may be able to upgrade. You'll have to enable the "xml-agent" feature for this to work. Be aware that this feature is not always deemed reliable yet (last we checked there were some bugs that prevented us from using it), but it should be good enough for many people.

  • If upgrading is not an option, there is this horrible ugly hack (that's my fault):

http://code.google.com/p/text2xml/

It comes with a syntax for IOS (syntax/ios.def in the repository) that supports translating a significant number of commands to XML, but is in no way complete. Still, it works for a large number of very complex configurations here, and extending it to support new IOS commands should merely be a matter of adding the new commands to the (painfully unreadable and hard to understand) syntax definition.

You'll still want to convert the resulting XML to something more stable, but XML transformations are way easier than parsing IOS (which is a royal PITA).

[edit] The above answer is now largely obsolete: I have written Gelatin, which lets you convert IOS and IOS XR configurations to XML, JSON, or YAML - whichever you prefer. This is essentially a replacement for afore mentioned ugly hack, with the following differences:

  • I no longer call it an ugly hack. I am actually pretty proud of it, so don't disillusion me! More seriously, if you find any problem with it, please let me know and I will fix it.
  • Written in pure Python, and it no longer compiles to C, which makes it a lot easier to use and install. (Also, the performance gain from generating C code wasn't essential anyway.)
  • The syntax is way easier to understand. There is also some documentation.
  • The parser is much more stable.

A short how-to:

  • Download and install Gelatin:

    git clone git://github.com/knipknap/Gelatin.git
    cd Gelatin
    sudo python setup.py install
    
  • The package contains a syntax for IOS (syntax/ios/show_running_config/syntax.gel) and another one for IOS XR (syntax/ios_xr/show_running_config/syntax.gel).

  • Transform a config to XML using the following command:

    gel -s syntax.gel config.txt
    

If that fails, please file a bug with the configuration that does not work. (Or better yet, attach a patch for the syntax.) I fully expect that a lot of IOS commands are still missing, so don't be shy.

Gelatin may be used to transform pretty much anything to XML, and if you happen to create your own syntax files (further instructions are here), please send them in. I'll gladly accept any feedback.

knipknap