Author image Robert Drake
and 1 contributors

NAME

App::Tel - A script for logging into devices

VERSION

0.201601

SYNOPSIS

    tel gw1-my-dev

See the README and COMMANDS files for examples of usage and ways to extend the application.

AUTHOR

Robert Drake, <rdrake at cpan.org>

COPYRIGHT & LICENSE

Copyright 2006 Robert Drake, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

METHODS

new

    my $tel = App::Tel->new();

Creates a new App::Tel object.

go

    $self->go('hostname');

Handles all the routines of connecting, enable, looping and disconnection. This is the method called by bin/tel for each host.

disconnect

    $self->disconnect($hard_close);

Tears down the session gracefully and resets internal variables to their default values. Useful if you want to connect to another host after the first one.

If you supply a true value, it will hard_close the session.

send

    $self->send("text\r");

Wrapper for Expect's send() method.

expect

    $self->expect("text");

Wrapper for Expect's expect() method.

load_config

Loads the config from /etc/telrc, /usr/local/etc/telrc, $ENV{HOME}/.telrc2, or it can be appended to by using the environment variable TELRC, or overridden by calling load_config with an argument:

    $self->load_config('/home/user/.my_custom_override');

hostname

   $hostname = $self->hostname("hostname");

Called to parse the hostname provided by the user when first making a connection. If the hostname has special attributes like a port designation, it's parsed here.

This also looks up the profile for the hostname to see if it needs to be translated because of an alias. The final hostname is stored and returned.

methods

    $self->methods();

This is used to determine the method used to connect to the remote device. Generally, the CLI argument -m has the highest priority. The uri should be second, profiles third, and the defaults would be last. If called without arguments it will return whatever the currently decided method array is. If called with an argument that will be set as the new method array.

If you call it multiple times it won't change right now. I may need to rethink this later but right now it works with the way the program flows. $self->disconnect removes all methods so connecting to another router will run this again.

    $self->methods('ssh', 'telnet');

rtr_find

    my $profile = $self->rtr_find($regex);

Find the router by hostname/regex and load the config associated with it. Load a profile for it if there is one.

If none of the router lines match then this does not merge another profile, but will return the existing profile. That may not be what you want in all cases. The workaround for it would be to clear profiles before calling this with $self->profile('default',1);

I'm trying to decide if there should be a better way to do this.

profile

   $profile = $self->profile;
   $profile = $self->profile('a_example_profile', $replace);

Called without arguments this will return the current profile. If called with a profile name it will load that new profile on top of whatever profile currently exists. You can set the second argument to true if you want to replace the current profile with the new one.

password

    my $password = $self->password;

This pulls the password from the config. If the password is blank it checks to see if you have a password manager, then tries to load the password from there. It then tries to use an OS keyring.

By default it will pull the regular password. To pull the enable password you can call it with $self->password('enable');

session

    my $session = $self->session;

Expect won't let you reuse a connection that has spawned a process, so you can call this with an argument to reset the session. If called without an argument it will return the current session (If it exists) or create a new session.

connect

    my $session = $self->connect('routername');

This sets up the session. If there already is a session open it closes and opens a new one.

connected

    if ($self->connected);
or
    $self->connected(1);

Returns connection status, or sets the status to whatever value is supplied to the method.

Note: This isn't the session state, but an indicator that our session has gotten through the login stage and is now waiting for input. i.e., the router is at a prompt of some kind.

enable

    $self->enable;

if enablecmd is set then this method attempts to enable the user. Returns $self.

enabled

    my $enabled = $self->enabled;

Check if enabled. This returns true if the $self->enable() method succeeds.

login

    $self->login("hostname");

Cycles through the connection methods trying each in the order specified by the profile until we successfully connect to the host. Returns $self.

logging

    $self->logging('filename');

Turns on logging for this session. If you specify a filename it will log to /tmp/<filename>.log, otherwise it will use /tmp/<hostname>.log.

run_commands

    $self->run_commands(@commands);

TODO: Document this

control_loop

    $self->control_loop();

This is where control should be passed once the session is logged in. This handles CLI commands passed via the -c option, or scripts executed with the -x option. It also handles auto commands passed via either option -a on the command line, or via autocmds in the profile.

Calling this without any commands will just run interact()