Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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; } } } } } } ...

Replies are listed 'Best First'.
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.

Re: Config files To XML
by Anonymous Monk on Jan 06, 2016 at 07:26 UTC
    #-------------------------------------------------- echo "Log Configuration" #-------------------------------------------------- log file-id 60 location cf3: rollover 480 retention 72 exit snmp-trap-group 98 description "5620sam" trap-target "" address snmpv3 not +ify-community "SNMPv3user" security-level privacy trap-target "" address snmpv3 not +ify-community "SNMPv3user" security-level privacy exit log-id 50 from debug-trace exit log-id 60 time-format local from main security change to file 60 exit log-id 98 from main security to snmp 1024 exit exit

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://750491]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2018-03-19 20:02 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.