The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Device::Network::ConfigParser - harness for parsing network configurations.

VERSION

version 0.006

SYNOPSIS

Device::Network::ConfigParser is a harness for parsing network device configuration. It exports a single subroutine - app() - which takes command line arguments and runs the harness. This module is used by the ncp command line utility. For information on how to use the command line utility, refer to the ncp, or following installation type perldoc ncp at the command line.

The harness supports specific parsing modules by:

  • Dynamically loading a specific parsing module based on command line arguments.

  • Slurping in the device configuration from STDIN or from a number of files.

  • Opening the required output filehandles.

CURRENT PARSER MODULES

Device::Network::ConfigParser::Cisco::ASA
Device::Network::ConfigParser::CheckPoint::Gaia
Device::Network::ConfigParser::Linux::NetUtils
Device::Network::ConfigParser::Linux::iproute2

DEVELOPING MODULES

Parsing modules exist within the Device::Network::ConfigParser:: namespace. For a vendor and type of device, the module is defined as Device::Network::ConfigParser::vendor::type.

The harness takes care of parsing the command line arguments, opening files (or STDIN/STDOUT) and slurping in their contents. It calls specified subroutines exported by the specified parsing module. All modules must export the following subroutines:

get_parser

    my $module_parser = get_parser();

This sub receives no arguments, and must return a reference to an object or subroutine that parses the configuration. This is most likely going to be a Parse::RecDescent object, but you're not limited to this.

parse_config

    my $parsed_config = parse_config($module_parser, $device_config);

This sub receives the reference returned by the get_parser sub, and the full contents of a file specified on the command line. It should return a reference a data structure that represents the parsed configuration.

post_process

    my $processed_config = post_process($parsed_config);

This sub receives the reference to the data structure returned by parse_config. It allows for some post-processing of the data structure. If no processing is required, it can be defined as sub post_process { return @_; }.

get_output_drivers

    open($fh, ">>:encoding(UTF-8)", $output_filename);
    my $output_drivers = get_output_drivers();

    $output_drivers->{csv}->($fh, $output_filename, $processed_config);

This sub takes no arguments, and must return a HASHREF of subroutines used to output the parsed configurationm keyed on the command line argument. For example the sub may return:

    {
        csv => \&csv_output_driver,
    }  

The drivers themselves take a filehandle to write the output to (this may be STDOUT), the output filename, and the post-processed configuration.

The driver called is based on the --output csv as a command line argument

There are two default drivers:

  • the 'raw' driver, which uses Data::Dumper to serialise the structure, and

  • the 'json' driver, which encodes the data structure as JSON.

 A module may return their own 'raw' or 'json' drivers which override these defaults.

SUBROUTINES

app

The app subroutine in general takes @ARGV (although it could be any list) and runs the harness.

AUTHOR

Greg Foletta, <greg at foletta.org>

BUGS

Please report any bugs or feature requests to bug-device-network-configparser at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Device-Network-ConfigParser. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Device::Network::ConfigParser

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2017 Greg Foletta.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.