Network OS Administration Guide

Supporting Network OS 6.0.1a

Part Number: 53-1003768-04

Script for assigning interfaces to port channels (create_po.py)

The create_po.py script is an example for automating common configuration tasks.

Script (create_po.py)

This script runs the relevant show running-config commands before and after the following actions:
  • VLAN configuration
  • Port-channel configuration
  • Adding interfaces to port channels
NOTE
Lines beginning with # are annotations.
#Required in all scripts for NOS:
from CLI import CLI

rbridges = [3, 4]
interfaces = [40, 41, 42, 43]
port_channel = 10
vlan_range = "101-105"
slot_number = 0

# Runs show running-config int vlan before the configuration, and assigns this NOS 
# command to a Python variable named cmd_show_running_vlans.
cmd_show_running_vlans = CLI("show running-config int vlan")

# Configures VLANs.  {} is a placeholder for the format (arg1, arg2, ... argN) variables:
cmd_configure_vlans = CLI("config \n int vlan {}".format(vlan_range))

# Reruns show running-config int vlan, following definition of new VLANs:
cmd_show_running_vlans.rerun()

# Configures port channel (vLAG):
cmd_show_running_port_channels = CLI("show running-config int po")
cmd_configure_port_channel = CLI("config \n int po {} \n switchport \n switchport mode trunk \n switchport trunk allowed vlan add {} \n switchport trunk tag native-vlan ; no shut".format(port_channel, vlan_range))

# Reruns show running-config int po, following configuration changes:
cmd_show_running_port_channels.rerun()

# Add interfaces to port channel (vLAG)
for rbridge in rbridges:
    for interface in interfaces:
        cmd_configure_interface = CLI("config \n int te {}/{}/{} \n fabric isl enable \n fabric trunk enable \n channel-group {} mode active type standard \n no shut".format(rbridge, slot_number, interface, port_channel))
        cmd_show_running_int_tengig = CLI("show running-config int te {}/{}/{}".format (rbridge, slot_number, interface))

# Runs show running-config:
cmd_show_running = CLI("show running-config")

Run-log (create_po.py)

A log upon running create_po.py was as follows:

device# python create_po.py
!Command: show running-config int vlan
!Time: Mon May 18 15:08:52 2015

interface Vlan 1
!
!Command: config 
 int vlan 101-105
!Time: Mon May 18 15:08:52 2015

!Command: show running-config int vlan
!Time: Mon May 18 15:08:53 2015
interface Vlan 1
!
interface Vlan 101
!
interface Vlan 102
!
interface Vlan 103
!
interface Vlan 104
!
interface Vlan 105
!

!Command: show running-config int po
!Time: Mon May 18 15:08:54 2015

% No entries found.

!Command: config 
 int po 10 
 switchport 
 switchport mode trunk 
 switchport trunk allowed vlan add 101-105 
 switchport trunk tag native-vlan ; no shut
!Time: Mon May 18 15:08:54 2015

!Command: show running-config int po
!Time: Mon May 18 15:08:56 2015

interface Port-channel 10
 vlag ignore-split
 switchport
 switchport mode trunk
 switchport trunk allowed vlan add 101-105
 switchport trunk tag native-vlan
 spanning-tree shutdown
 no shutdown
!
!Command: config 
 int te 3/0/40 
 fabric isl enable 
 fabric trunk enable 
 channel-group 10 mode active type standard 
 no shut
!Time: Mon May 18 15:08:57 2015

!Command: show running-config int te 3/0/40
!Time: Mon May 18 15:08:59 2015

interface TenGigabitEthernet 3/0/40
 fabric isl enable
 fabric trunk enable
 channel-group 10 mode active type standard
 lacp timeout long
 no shutdown
!
!Command: config 
 int te 3/0/41 
 fabric isl enable 
 fabric trunk enable 
 channel-group 10 mode active type standard 
 no shut
!Time: Mon May 18 15:09:00 2015

!Command: show running-config int te 3/0/41
!Time: Mon May 18 15:09:01 2015

interface TenGigabitEthernet 3/0/41
 fabric isl enable
 fabric trunk enable
 channel-group 10 mode active type standard
 lacp timeout long
 no shutdown
!
!Command: config 
 int te 3/0/42 
 fabric isl enable 
 fabric trunk enable 
 channel-group 10 mode active type standard 
 no shut
!Time: Mon May 18 15:09:03 2015

!Command: show running-config int te 3/0/42
!Time: Mon May 18 15:09:05 2015

interface TenGigabitEthernet 3/0/42
 fabric isl enable
 fabric trunk enable
 channel-group 10 mode active type standard
 lacp timeout long
 no shutdown
!
!Command: config 
 int te 3/0/43 
 fabric isl enable 
 fabric trunk enable 
 channel-group 10 mode active type standard 
 no shut
!Time: Mon May 18 15:09:06 2015

!Command: show running-config int te 3/0/43
!Time: Mon May 18 15:09:07 2015

interface TenGigabitEthernet 3/0/43
 fabric isl enable
 fabric trunk enable
 channel-group 10 mode active type standard
 lacp timeout long
 no shutdown
!
!Command: config 
 int te 4/0/40 
 fabric isl enable 
 fabric trunk enable 
 channel-group 10 mode active type standard 
 no shut
!Time: Mon May 18 15:09:08 2015

!Command: show running-config int te 4/0/40
!Time: Mon May 18 15:09:10 2015

interface TenGigabitEthernet 4/0/40
 fabric isl enable
 fabric trunk enable
 channel-group 10 mode active type standard
 lacp timeout long
 no shutdown
!
!Command: config 
 int te 4/0/41 
 fabric isl enable 
 fabric trunk enable 
 channel-group 10 mode active type standard 
 no shut
!Time: Mon May 18 15:09:11 2015

!Command: show running-config int te 4/0/41
!Time: Mon May 18 15:09:12 2015

interface TenGigabitEthernet 4/0/41
 fabric isl enable
 fabric trunk enable
 channel-group 10 mode active type standard
 lacp timeout long
 no shutdown
!
!Command: config 
 int te 4/0/42 
 fabric isl enable 
 fabric trunk enable 
 channel-group 10 mode active type standard 
 no shut
!Time: Mon May 18 15:09:13 2015

!Command: show running-config int te 4/0/42
!Time: Mon May 18 15:09:15 2015

interface TenGigabitEthernet 4/0/42
 fabric isl enable
 fabric trunk enable
 channel-group 10 mode active type standard
 lacp timeout long
 no shutdown
!
!Command: config 
 int te 4/0/43 
 fabric isl enable 
 fabric trunk enable 
 channel-group 10 mode active type standard 
 no shut
!Time: Mon May 18 15:09:16 2015

!Command: show running-config int te 4/0/43
!Time: Mon May 18 15:09:17 2015

interface TenGigabitEthernet 4/0/43
 fabric isl enable
 fabric trunk enable
 channel-group 10 mode active type standard
 lacp timeout long
 no shutdown
!
!Command: show running-config
!Time: Mon May 18 15:09:18 2015

diag post rbridge-id 1 enable
diag post rbridge-id 2 enable
diag post rbridge-id 3 enable
diag post rbridge-id 4 enable
hardware
 connector-group 2/0/1
  speed LowMixed
 !
 connector-group 2/0/3
  speed LowMixed
 !
 connector-group 2/0/5
  speed LowMixed
 !
 connector-group 2/0/6
  speed LowMixed
 !