Network OS Administration Guide

Supporting Network OS 6.0.1a

Part Number: 53-1003768-04

Script for upgrading and reconfiguring switches (dad.py)

The dad.py script configures an RBridge or all VCS RBridges using DHCP automatic deployment (DAD).

Script (dad.py)

This example configures an RBridge or all of the RBridges in a VCS using DHCP automatic deployment (DAD). The python dad.py command calls this script. Lines beginning with # are annotations.

ATTENTION
This script is run automatically by the DAD process. Refer to the "Using DHCP Automatic Deployment" section of the Network OS Administration Guide.
##  
# Usage: 
# dad.py -h | --help     help message
#        -g | --global   option for LC mode to set cluster global config
#        -r | --rbridgeid <#> option for LC mode and FC mode to set switch-specific config
#        -l | --local otp option for LC mode to set switch-specific config
#
import os
import sys, getopt

# Import Network OS Python CLI module 
from CLI import CLI

# debug log
log=open("/tmp/dadscript.log", "a")

def main(argv):
   mode = -1 # 0 - global, 1 - local
   rbridgeid = 0
   localcmd = 0 # local command
   try:
      opts, args = getopt.getopt(argv,"ghr:l",["global", "help", "rbridgeid=", "local"])
   except getopt.GetoptError:
      log.write('dad2.py [-h|--help] [-g|--global] [-r|--rbridgeid <#>] [-l|--local]\n')
      sys.exit(2)

# Parsing options
   for opt, arg in opts:
      if opt in ("-g", "--global"):
         if len(opts) > 1:
            log.write("only one option is allowed\n")
            sys.exit(3)
         mode = 0
      elif opt in ("-r", "--rbridgeid"):
         mode = 1
         rbridgeid = int(arg)
      elif opt in ("-l", "--local"):
         if len(opts) == 1:
            log.write("-r is required\n")
            sys.exit(4)
         mode = 1
         localcmd = 1
      else:
         log.write('dad2.py [-h|--help] [-g|--global] [-r|--rbridgeid] [-l|--local]\n')
         sys.exit(1)
   log.write("mode = " + str(mode) + '\n')

# Execute command
   if mode == 0:
      log.write("apply global config\n")
      CLI("conf ; banner login DAD ; end")
   elif localcmd == 0:
      log.write("apply local config\n")
      log.write("rbridgeid = " + str(rbridgeid) + '\n')
      CLI("conf ; rbridge-id " + str(rbridgeid) " ;  switch-attributes host-name sw " + str(rbridgeid) + " ; end")
   else: # localcmd == 1
      log.write("apply local command\n")
      log.write("rbridgeid = " + str(rbridgeid) + '\n')
      os.system("date > /tmp/localcmd.date")
if __name__ == "__main__":
   main(sys.argv[1:])

Run-log (dad.py)

The following are logs of running dad.py with various parameters.

NOTE
Because dad.py is run automatically by the DAD process, you need to enter show dadstatus in order to see the results.
The following command runs the dad.py script and sets the switch login banner to "DAD".
device# python dad.py -g
!Command: conf ; banner incoming DAD0 ; end
!Time: Thu Apr 16 00:06:35 2015

device# 
The following command runs the dad.py script on RBridge 90, and sets the switch hostname to sw90.0:
device# python dad.py -r 90
!Command: conf ; rbridge-id 90 ; root en ; switch-attributes host-name sw90.0 ; end
!Time: Thu Apr 16 00:06:39 2015

device#
The following command runs the dad.py script on RBridge 90, and runs a Linux command to log the current time into /tmp/localcmd.date, with no monitor output:
device# python dad.py -r 90 -l

device#