View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Kevin Ehlers > Net-Autoconfig-v1.13.2 > Net::Autoconfig



Annotate this POD


New  2
Open  0
View/Report Bugs
Module Version: 1.13.2   Source  


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("", "/24");
  $default_device->ip_addr("", "");

  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.

Methods ^

Public Methods

 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

$device->hostname(non string and not 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
$device->ip_addr("", "");
$device->ip_addr("", "/24");
    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

    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.

$favorite_color = $device->get_param("fav_color");
$my_attributes = $device->get_param();

    $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.

$device->set_attrib("model", "hp2600");
@attribs = ( model => "hp2600", vendor => "hp" );

Returns undef for success Returns TRUE for failure




Kevin Ehlers <>


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.

syntax highlighting: