Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Config files To XML

by LiNuXaDDiKt (Initiate)
on Mar 13, 2009 at 18:32 UTC ( #750491=perlquestion: print w/ replies, xml ) Need Help??
LiNuXaDDiKt has asked for the wisdom of the Perl Monks concerning the following question:

First of all, I need to mention that my knowledge of XML is very poor...

That said, I'm a Networking IT guy that work with Cisco, Acatel, Juniper and other vendor equipment on a daily basis. I regularly build perl scripts to interract with configuration files of those vendors and I wonder if XML would be of any help regarding this.

Cisco IOS config files don't really have a real structure that is easily convertible to a XML logical structure. Still, I'm giving it a try in case any one have ever did something intelligent with this type of config.

On the other hand, Alcatel and Juniper configs does have a very well structured output that can easily be converted to an XML format (see examples below).

Here are the questions (well for now...) :

- Is there any existing module that can convert Cisco configs to XML?
- Is there existing module that can convert structure similar to Alcatel or Juniper (again see below) to XML?
- If no sutch module exists, how hard would it be to adapt one to recognize this kind of hierarchy?

My goal here is to try see if any benefits could be acheived by using XML to work with config files instead of doing legacy code all the time.

Alcatel TiMOS example
#-------------------------------------------------- echo "System Configuration" #-------------------------------------------------- system name "HOSTNAME" location "Some location" power-supply 1 dc power-supply 2 dc snmp packet-size 8000 exit login-control ftp inbound-max-sessions 2 exit pre-login-message "Some Message\n" motd url "motd.txt" exit time sntp server-address x.x.x.x no shutdown exit exit thresholds rmon exit exit exit #-------------------------------------------------- ...
Juniper JUNOS Example
system { time-zone America/xxxxxxxx; no-redirects; root-authentication { encrypted-password "Encripted Password"; } tacplus-server { x.x.x.x { secret "password"; timeout 2; source-address x.x.x.x; } } accounting { events [ login change-log ]; destination { tacplus { server { x.x.x.x { secret "password"; timeout 5; source-address x.x.x.x; } } } } } } ...

Comment on Config files To XML
Select or Download Code
Re: Config files To XML
by mr_mischief (Monsignor) on Mar 13, 2009 at 18:56 UTC
    I think you'd need to parse the Cisco configuration files and transform them into XML. Then you'd have to transform them back for loading them onto the equipment. It'd probably be worthwhile to do that if you find XML is the best format for dealing with the others.

    You could even come up with a completely standardized XML application for describing network device configuration. You could have a module for each vendor's configuration language, and just call your toXML and toVendorConfig methods after you've set your object to use a particular vendor's language. A name for this language, a DTD, and a website for your language, and you've suddenly got the reference implementation of a new buzzword.

    See also Pancho (created by c) which originally supported configuring Cisco equipment over SNMP and TFTP but has templates-based support for the configurations of other vendors' products. It may be a good starting point or at least give you some ideas on how you want to do this. It may even save you implementing your own solution altogether.

Re: Config files To XML
by hsinclai (Deacon) on Mar 13, 2009 at 20:38 UTC
    Look how short your configs are! What do you win by using XML (other than the joy of discovery)? The pancho suggestion is good. Since you are obviously already a heavy duty do-it-yourselfer:) you could use that. In the past I have kept all my router + switch configs in Subversion, and scripted something to keep TFTP dirs synched up for deployment.. I had 4 or 5 different classes of equipment including Cisco CSS. Or maybe - you have hundreds of nodes to manage... and it makes sense to standardize?

      I can assure you that I deal with large configs of 5 to 20Meg in text format which is quite large.

      As I said, I'm seeking for possible advantages that the so popular XML format would possibly provide.

      To the point I am now and with all your excellent advises, I am stil not convinced of the benefits of XML for this task...
Re: Config files To XML
by quester (Vicar) on Mar 13, 2009 at 21:03 UTC
    If I recall correctly, the Cisco commands "write memory" and "copy running-config..." always indent child nodes by one space. I never wrote anything that depended on the indentation, but it certainly looked consistent enough to use in parsing the files. YMMV.

    For example, this is a fragment of a lab router config for a 7200:

    interface FastEthernet1/0 no ip address duplex full ! interface FastEthernet1/0.1 encapsulation dot1Q 1 native ipv6 address xxxx:1::3/48 ipv6 traffic-filter lab-only in ipv6 ospf 1 area 0 ! gatekeeper shutdown ! ! line con 0 stopbits 1 line aux 0 stopbits 1
    So "no ip address" and "duplex full" are child nodes of "interface FastEthernet1/0" because they are indented farther to the right.

    There are a few cases where second-level child nodes exist and are indented by two spaces, but I don't have any examples handy. Oh, and by the way, don't try to use the exclamation points in parsing; they are not nearly as consistent as the spacing.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://750491]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2014-12-25 07:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls