Net::Autoconfig - Perl extension for provisioning or reconfiguring network devices.
use Net::Autoconfig::Device; my $default_device = Net::Autoconfig::Device->new(); my $preconfigured_device = Net::Autoconfig::Device->new(@key_value_pairs); $default_device->hostname("Device 1"); $default_device->ip_addr("192.168.0.1", "/24"); $default_device->ip_addr("192.168.0.1", "255.255.255.0"); $default_device->set_attributes(@key_value_pairs); print "Hostname: " . $preconfigured_device->ip_addr(); my ($ip_addr, $netmask, $prefix) = $preconfigured_device->ip_addr(); print "IP info: $ip_addr$prefix ($netmask)"; my $something = $preconfigured_device->get_attrib("somthing"); my %device_data = $preconfigured_device->get_attrib();
Net::Autoconfig was created to fill the void of having a utility to configured / provision devices in an automated way. The reason for its existence came about from having to deploy 150 new switches that were almost identically configured, except for the names, ip addresses and vlans. The devices had to be unpacked, firmware upgraded, given an initial configuration, and then given their final configuration. This process is error-prone and takes a long time. Using this module enabled one person to configure all 150 switches within a week.
Create a new Net::Autoconfig::Device object. Additional info can be configured after the object has been created. Pass an array with ( key1 => value1, key2 => value2, ...) to initialize the object with those key values.
Returns a Net::Autoconfig::Device object with default values.
Returns a Net::Autoconfig::Device object with user defined values.
Either returns or sets the hostname of the device depending on if a parameter is passed or not.
returns the hostname
sets the hostname and returns undef
Error!, returns true
Either sets the ip address or returns the ip addresses (and subnet and prefix if requested).
$ip_address = $device->ip_addr(); ($ip_address, $netmask, $prefix) = $device->ip_addr();
Sets the ip address returns undef if successful returns TRUE if failure
Sets the ip address and the subnet/netmask. The method will add both prefix and netmask to the device. Send either the netmask or the prefix. Whichever you prefer. The method will calculate the other one for you. The prefix must be in the form "/\d\d?". I.e., it needs the starting forward slash and must be followed by one or two digits. returns undef for success returns TRUE for failure
Get the value of the specified attribute, or get a hash ref of all of the attribute => value pairings. This provides a mechanism for getting attributes that are either part of the module, or that you have defined. Returns undef if an attribute does not exist.
E.g. $my_attritubes = { hostname => "", ip_addr => "", ... fav_color => "green", }
Set the value of an attribute. If the attribute does not yet exist, create it.
This method is used by passing an array to the method. The method then adds/overwrites existing key => value pairs to the object.
Returns undef for success Returns TRUE for failure
Net::Autoconfig
Kevin Ehlers <kevin@uoregon.edu>
Copyright (C) 2008 by Kevin Ehlers, University of Oregon.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install Net::Autoconfig, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Autoconfig
CPAN shell
perl -MCPAN -e shell install Net::Autoconfig
For more information on module installation, please visit the detailed CPAN module installation guide.