Open Ethernet Networking (OpEN) API Guide and Reference Manual  3.6.0.3
Example Puppet Netdev Provider

As an example of the Puppet and OpEN API usage, Broadcom has developed the Netdev provider for the netdev_device, netdev_interface, netdev_l2_interface, netdev_lag and netdev_vlan features. Netdev is a vendor-neutral network abstraction framework developed by Juniper Networks and contributed freely to the DevOps community. More information can be obtained from https://github.com/puppetlabs/netdev_stdlib.

Prerequisites

It is assumed that the reader is familiar with the concepts of Puppet:

Broadcom Puppet Agent Installation

For details on how to install the Puppet agent on a Broadcom switch see the Installing the Puppet Agent section.

Netdev Provider from DevOps community

Base Netdev Stdlib Installation

To install the base Netdev files execute the following command on your Puppet server:

  puppet-server% puppet module install netdevops/netdev_stdlib

These files provide the framework and types for the Netdev Stdlib, but do not install any providers. In the next section we explain how to install the Broadcom ICOS Netdev Stdlib providers.

Broadcom Netdev Stdlib Installation

The Broadcom Netdev provider is available in the ADK in the examples/puppet/netdev_stdlib_icos. The Netdev provider is implemented for the netdev_device, netdev_interface, netdev_l2_interface, netdev_l2_interface and netdev_vlan features. To install the Broadcom Netdev Stdlib feature, copy the netdev_stdlib_icos directory into the /etc/puppet/modules directory on your Puppet server, as shown below.

  puppet-server% scp -r <user>@<ip>:/<path>/examples/puppet/netdev_stdlib_icos /etc/puppet/modules

Updating the Puppet Manifest

To use the Netdev Stdlib types on a specific switch node you need to update the Puppet manifest site file, typically located in /etc/puppet/manifests/site.pp on the Puppet server. The following text illustrates how the site.pp file can be updated for the node named 'tor1.example.com'.

  node 'tor1.example.com' {
    netdev_device { $hostname: }
    # Create an interface 0/1 with the specified interface properties
    netdev_interface { "0/1":
        description => "Puppet modified interface 0/1",
        admin       => up,
        speed       => 1g,
        duplex      => full,
        mtu         => 2500
    }
    # Create an interface 0/2 with the specified interface properties
    netdev_interface { "0/2":
        description => "Puppet modified interface 0/2",
        admin       => down,
        speed       => 100m,
        duplex      => half,
        mtu         => 3500
    }
    # Delete an interface 0/3
    netdev_interface { "0/3":
        ensure => absent
    }
    # Create list of VLANs 10, 20 and 30
    $vlans_new = {
      'White' => { vlan_id => 10, description => "This is a Green vlan" },
      'Pink'  => { vlan_id => 20, description => "This is a Pink vlan" },
      'Blue'  => { vlan_id => 30, description => "This is a Red vlan"  },
    }
    create_resources( netdev_vlan, $vlans_new )
    # Create list of access ports 0/4, 0/5 and 0/6
    $access_ports = [
        '0/4',
        '0/5',
        '0/6'
    ]
    netdev_l2_interface { $access_ports:
        untagged_vlan => 'Blue',
        description   => "This is a Puppet created access port"
    }
    # Create list of uplink/trunk ports 0/7, 0/8 and 0/9
    $uplink_ports = [
        '0/7',
        '0/8',
        '0/9'
    ]
    netdev_l2_interface { $uplink_ports:
        tagged_vlans => [ 'White', 'Pink' ],
        description  => "This is a Puppet created uplink port"
    }
    # Delete an L2 interface 0/10
    netdev_l2_interface { "0/10":
        tagged_vlans  => [ 'White', 'Pink' ],
        untagged_vlan => 'Blue',
        ensure        => absent
    }
    # Create a LAG interface 3/1 and add the interfaces 0/11, 0/12 and 0/13 to LAG 3/1
    netdev_lag { "3/1":
        links         => [ '0/11', '0/12', '0/13' ],
        minimum_links => 3,
        lacp          => active
    }
    # Remove the interfaces 0/14, 0/15 from LAG 3/2 and delete the LAG interface
    netdev_lag { "3/2":
        links  => [ '0/14', '0/15' ],
        ensure => absent
    }
    # Create VLANs 100, 200 and delete VLANs 2, 1
    $vlans = {
      'Yellow' => { vlan_id => 100, description => "This is a Blue vlan" },
      'Green'  => { vlan_id => 200, description => "This is a Green vlan" },
      'Red'    => { vlan_id => 2,   ensure => absent },
      'Grey'   => { vlan_id => 1,   ensure => absent }
    }
    create_resources( netdev_vlan, $vlans )
  }

Once the site.pp file has been updated, and when the Puppet agent on tor1.example.com next checks its configuration, it will perform all the configurations as mentioned in the manifest file site.pp. To force the Puppet agent to check its configuration, and to see the output from the update, use the puppet agent --test command on the switch.

For further information on using the Netdev Stdlib the reader is directed to https://github.com/puppetlabs/netdev_stdlib. NOTE: The Netdev provider supports Netdev corresponding to the following commit: https://github.com/puppetlabs/netdev_stdlib/commit/4ecc128cfc3fd057c49c4d709fc752fb4230437e (March 29, 2013).

Netdev Provider from Broadcom

Broadcom Netdev Installation

The Broadcom Netdev provider is available in the ADK in the examples/puppet/netdev_stdlib_brcm. The Netdev provider is implemented for the netdev_config_script feature. To install the Broadcom Netdev feature, copy the netdev_stdlib_brcm directory into the /etc/puppet/modules directory on your Puppet server, as shown below.

  puppet-server% scp -r <user>@<ip>:/<path>/examples/puppet/netdev_stdlib_brcm /etc/puppet/modules

To use the Broadcom Netdev Stdlib types on a specific switch node you need to update the Puppet manifest site file, typically located in /etc/puppet/manifests/site.pp on the Puppet server. The following text illustrates how the site.pp file can be updated for the node named 'tor1.example.com'.

Updating Puppet File Server

Puppet File Server must be configured on Puppet Master in order to place the CLI text based configuration files for transferring to agent. Edit [files] section in '/etc/puppet/fileserver.conf' file to create custom mount point. For further information on Puppet File Server, refer to http://docs.puppetlabs.com. In the below example, '/etc/puppet/files' mount point is created to place CLI text based configuration files.

[files]
  path /etc/puppet/files
    allow *

Once the Puppet File Server is configured, copy the desired CLI text based configuration files in the folder '/etc/puppet/files'.

Updating the Puppet Manifest to apply CLI configuration

  node 'tor1.example.com' {
    $config_script_file = "config.scr"
    $file_path = "/mnt/fastpath/"
    file { "$file_path$config_script_file":
      source => "puppet:///files/$config_script_file",
    }
    netdev_config_script { 'config_script':
      file => "$file_path$config_script_file",
      action => 'apply',
    }
  }

Updating the Puppet Manifest to backup running configuration

In the below example, 'filebucket' is used to backup running configuration file. 'filebucket' is a repository for storing and retrieving file content by MD5 checksum. For further information on Puppet File Server, refer to http://docs.puppetlabs.com.

  node 'tor1.example.com' {
    $config_script_file = "config.scr"
    $file_path = "/mnt/fastpath/"
    netdev_config_script { 'config_script':
      file => "$file_path$config_script_file",
      action => 'backup',
    } ~> file { "$file_path$config_script_file":  backup => 'main', ensure => absent}
    filebucket { 'main':
      server => 'puppet.example.com',
      path => false,
    }
  }

The above example generates running configuration file on the switch and the file is transferred to the filebucket on puppet master. The file is placed in '/var/lib/puppet/bucket' folder.

Note: Ensure that the configuration file extension is .scr and filename is less than 32 characters including extension.

Once the site.pp file has been updated, and when the Puppet agent on tor1.example.com checks its configuration, it will perform the action as mentioned in the manifest file site.pp.

Updating the Puppet Manifest to save running configuration

  node 'tor1.example.com' {
    netdev_config_script { 'config_script':
      action => 'save'
    }
  }

The above example saves the running configuration to NVRAM. The configuration is persist across a reboot.

Once the site.pp file has been updated, and when the Puppet agent on tor1.example.com checks its configuration, it will perform the action as mentioned in the manifest file site.pp.