Administrator Guide

14 Python Scripting for Dell Networking N-Series | Version 1.0.1
3.2 Example 2: Applying Python scripts for execution at reload
This example shows how to configure a Python script to execute each time an N-Series switch reloads. This
particular script copies the startup configuration to a TFTP server upon each reboot of the switch.
For this script to work the switch must have access to a TFTP server and the switch’s configuration must
include a username/password and OOB IP address.
This example demonstrates the following three areas:
i. Applying a Python script to be run upon reloading of the switch
ii. Performing management tasks, such as backing up the switch configuration or updating firmware
using Python scripts
iii. Provides the framework for applying any CLI command in a Python script
Save the commands below into a file using a script editor, then compress the file into a .tgz or .tar.gz format
(as discussed on page 8
).
Note: There is a limit of 16 characters for script filenames, including the extension. This limitation also
applies to the compressed (.tgz or .tar.gz) file containing the script.
#!/usr/bin/env python
#load this script using the start-on-boot parameter in
#order to back up the switch each time the switch reloads
import telnetlib
import os
import re
import time
import string
import sys
HOST = '127.0.0.1'
PORT = 23
LOGIN_STRING = "Login:"
PASSWORD_STRING = "Password:"
TERMINAL_LEN_ZERO = "terminal length 0\n"
TERMINAL_MONITOR = "terminal monitor\n"
ENABLE_STRING = "enable\n"
CONFIG_STRING = "configure\n"
USERNAME = 'admin'
PASSWORD = 'password'
ENABLE_PASSWORD = ''
TIMEOUT = 3
def do_terminal_settings(tn):