Chris Josephes > router-lg-0.98a > Router::LG

Download:
router-lg-0.98a.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.98   Source  

NAME ^

Router::LG - Looking Glass

SYNOPSIS ^

use Router::LG; $glass=Router::LG::new();

DESCRIPTION ^

The LG class is based on the lg.pl program originally written by Ed Kern of Digex. The original lg.pl program was used as a web-based front end to obtain information from routers via RSH.

All of the original features of lg.pl have been incorporated into LG.pm.

        - Multiple router vendor support
        - Multiple parameter support
        - Custom command definition

HOW IT WORKS ^

The LG module has a set of driver modules for accessing routers made by different vendors, like Cisco or Juniper. Each driver contains code and data structures regarding what commands it can send and how it can communicate with the router. The driver module is dynamically loaded when a router is defined.

CONSTRUCTOR METHOD ^

$glass=Router::LG->new();

OBJECT METHODS ^

version();

Returns version data on the Router::LG class.

router($ROUTER);

Sets or returns the router data structure. The router data structure defines the host address of the router, the vendor class, the remote access method, and any arguements are required to connect.

The following code defines a router data structure and tells the Looking Glass object to use it.

 #!/usr/local/bin/perl

 $router={ 
        -hostname => "core.pop.isp.node", 
        -class => "Cisco", 
        -method => "rsh", 
        -args => { 
                -luser => "local_user", 
                -ruser => "remote_user", 
        }, 
 }; 

 $glass->router($router);

See the POD documentation for a particular Router::LG class, (ex, Router::LG::Cisco, or Router::LG::Driver)

parameters([-clear|@LIST]);

Sets or returns an array of parameters that will be inserted into the command sent to the router. Setting the first arguement of the list to "-clear" erases the contents of the array.

cache( -directory => $CACHE, -ttl => $TTL);

Sets of returns a hash defining the optional cache setup. Defining a cache takes two parameters, a directory, and a default time to live (in seconds).

If no TTL is defined, a default value of 10 minutes will be used.

commands();

Returns a list of commands the driver supports

command($COMMAND,%PARAMETERS);

Sets or returns data regarding a command structure. See the POD documentation for the particular vendor class for more information.

execute($COMMAND);

Executes the command on the router. If the command is successful, the method returns a cache state variable, followed by the lines of output the router sent back. The cache state variable can be a 1 indicating that LG returned cached data instead of accessing the router, or a 0 indicating that the router was accessed to obtain the data.

If the command failed, undef will be returned.

Example:

($cache,@output)=$glass->execute("env");

$glass->parse($COMMAND);

Works like execute, however it returns the command it would send to the router, but doesn't actually send it.

$glass->error([-clear|@LIST]);

Sets or returns one or more error messages. If the first arguement in the list is "-clear", it will erase the list of errors.

HIDDEN METHODS ^

The following methods are part of the LG class, but implementors are not expected to use them.

_loadDriver()

Loads the driver defined in the router data structure

_driver()

Returns the object pointer to the router driver

_cacheFile

Returns a parsed filename for the cachefile, which is the name of the command followed by two dashes and the hostname of the remote router

_cacheOK

Returns a boolean flag indicating whether or not we could use cached data instead of accessing the remote router

_readCache

Reads a cached output file

_writeCache

Writes output to a cache file

syntax highlighting: