Cisco-CopyConfig

 view release on metacpan or  search on metacpan

CopyConfig.pm  view on Meta::CPAN

    snmp-server community public view backup RW 10
    end

=head1 METHODS

=over 8

=item I<new>

Create a new Cisco::CopyConfig object.

    $config = Cisco::CopyConfig->new(
               Host  => $ios_device_hostname,
               Comm  => $community_string,
            [ Tmout  => $snmp_timeout_in_seconds, ]
            [ Retry  => $snmp_retries_on_failure, ]
    );

=item I<copy>

Copy the running-config to a file via TFTP:

    $config->copy($tftp_address, $tftp_file);

=item I<merge>

Merge a configuration file into the running-config via TFTP:

    $config->merge($tftp_address, $tftp_file);

=item I<error>

Return the last error message, if any.  This is a convenience method
that simply returns the value of $config->{'err'}:

    $config->error();

=back

=head1 EXAMPLE

Using 10.0.1.3 as a TFTP server, the following example merges a
configuration file into the running-config of lab-router-a, and 
then copies the entire config of lab-router-a to a file:

    use Cisco::CopyConfig;

    $|		= 1; # autoflush output
    $tftp	= '10.0.1.3';
    $merge_f	= 'new-config.upload';
    $copy_f	= 'lab-router-a.config';
    $host	= 'lab-router-a';
    $comm	= 'public';
    $config	= Cisco::CopyConfig->new(
		     Host => $host,
		     Comm => $comm
    );
    $path	= "/tftpboot/${copy_f}"; 

    open(COPY_FH, "> $path") || die $!;
    close(COPY_FH); chmod 0666, $path || die $!;

    print "${tftp}:${merge_f} -> ${host}:running-config... ";
    if ($config->merge($tftp, $merge_f)) {  # merge the new config
      print "OK\n";
    } else {
      die $config->error();
    }
    print "${host}:running-config -> ${tftp}:${copy_f}... ";
    if ($config->copy($tftp, $copy_f)) {    # copy the updated config
      print "OK\n";
    } else {
      die $config->error();
    }

    ---->8---- new-config.upload file ---->8----
    alias exec example_ccout copy running-config tftp
    alias exec example_ccin copy tftp running-config
    ! configuration uploads need an 'end' statement
    end

=head1 TROUBLESHOOTING

Manipulating the running-configuration of a device running IOS can be a 
frustrating experience.  Checking the status of $config->error() is a good
starting point to debugging the problem.  Here's a short list of other things
to try before giving up:

=over 4

=item 1.

Most TFTP servers will not automatically create files. Scripts should 
create files that will be read from or copied to, and set the appropriate
permissions (usually global).  

=item 2.

Most TFTP servers change directories (usually to '/tftpboot') for security
reasons.  If it does, make sure not to prepend the TFTP directory in the 
file path passed to I<Cisco::CopyConfig>.

=item 3.

Try manually copying files to and from the TFTP server to flash.  This is 
accomplished via the "copy" command in IOS (copy ? for help).  If the files 
are able to be copied in each direction, it is probably a problem with the 
SNMP configuration.  It could also indicate a file path issue.  See above.

=item 4.

Make sure the community string in the script and the IOS device match
and that it is a read/write (RW) community.  See B<PREPERATION> above for 
an example of how to set a read/write community with reasonable restrictions.

=back

=head1 PREREQUISITES

This module requires the I<Net::SNMP> and I<Socket> modules.  



( run in 0.852 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )