Python Scripting for Dell Networking N-Series Dell Networking Solutions Engineering March 2016 DRA D draft A Dell EMC Deployment and Configuration Guide
Revisions Date Description Authors March 2016 Initial Release - Version 1.0.1 Victor Teeter Ravindra Kadiyala Copyright © 2016 Dell Inc. or its subsidiaries. All Rights Reserved. Except as stated below, no part of this document may be reproduced, distributed or transmitted in any form or by any means, without express permission of Dell. You may distribute this document within your company or organization only, without alteration of its contents.
Contents 1 2 3 Introduction ................................................................................................................................................................... 5 1.1 Console output.................................................................................................................................................... 6 1.2 OOB Network................................................................................................................................
Executive Summary There are several ways to configure a Dell N-Series switch, each with its own advantages. While the Web User Interface allows new users to see all features displayed in logical tiers and can prompt them for settings, more experienced users often prefer the Command Line Interface (CLI) for entering commands to configure switches.
1 Introduction This document is a supplement to the Dell Networking N-Series User Guide and provides easy step-by-step instructions to help users configure Dell N-Series switches using Python scripts. This document primarily advises the reader on how to run Python scripts on N-Series switches. Explanation of Python syntax is beyond the scope of this document. Locate Python syntax explanations in numerous other resources both on the internet and in hardcopy material.
The topology includes two networks. The Out-of-Band (OOB) network is used only for management of switches on the network, while the Data network handles production traffic such as applications and file sharing. The examples in this guide apply to both a single N-Series switch as well as multiple, stacked NSeries switches as shown in Figure 1. A console cable may also be used between the management station and each switch to view the output of Python scripts. 1.
1.4 Python script flow on Dell N-Series Figure 2 depicts common flows of Python scripts on Dell N-Series switches. User writes and compresses script into .tgz or tar.
The list below includes the techniques represented in the flow chart along with a few others. The commands mentioned are covered in detail in this guide.
2 Switch commands for utilizing Python scripts This section covers all Dell N-Series commands for installing and managing Python scripts on an N-series switch: copy, dir, application install, show application, application start, application stop and erase. The commands are presented here in the order typically used. Descriptions, syntax and examples for each are described in detail below. 2.1 copy Use the copy command to copy Python scripts from the source to the switch.
2.3 application install Use the application install command (in global configuration mode) to load a script into switch memory. This does not start the script, but enables it to be started using one of the methods listed in section 1.4. Note: Scripts must be in the user-apps directory before they can be installed. See the copy command above for more information.
2.4 show application Use this command to see the scripts that are loaded into memory. Each script listed in the show applications command also has an entry in the running-configuration. Syntax: show application [files] Example: console#show application OpEN application table contains three entries. Name -----------SupportAssist hello hiveagent Optional parameter: files 2.
2.7 erase Use the erase command to remove a Python script from the switch. Use the dir user-apps command discussed above to verify that the script has been removed from the user-apps directory. Syntax: erase application filename Example: console#erase application hello Application file erased. 12 Python Scripting for Dell Networking N-Series | Version 1.0.
3 Examples of Python scripting on Dell N-Series Three examples are provided below to demonstrate various ways a Python script can be used to configure and manage Dell N-Series switches. Example 1: Quick Steps is a short illustration showing the fundamental commands to express how quickly scripts can be created and applied. Example 2: Applying Python scripts for execution at reload and 3.3 provide more intricate details to build a better understanding of these features while covering the remaining commands.
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.
tn.write(TERMINAL_MONITOR) tn.read_until("#") tn.write(TERMINAL_LEN_ZERO) tn.read_until("#") def do_login(tn): tn.read_until(LOGIN_STRING, TIMEOUT) tn.write(USERNAME + "\n") tn.read_until(PASSWORD_STRING, TIMEOUT) tn.write(PASSWORD + "\n") tn.read_until(">", TIMEOUT) tn.write(ENABLE_STRING) tn.read_until("#", TIMEOUT) #Replace the “xx.xx.xx.xx” below with the TFTP server IP address def do_config(tn): tn.read_until("#", TIMEOUT) tn.write("copy running-config tftp ://xx.xx.xx.xx/running-configuration\n"); tn.
Though the script was installed using the start-on-boot parameter, administrators can start it at any time using the application start command as long as the script allows for it (e.g. command prompts are properly detected).
3.3 Example 3: Running Python scripts on an active switch This example shows how to configure a Python script to be executed by the administrator at any time without reloading the switch (unless the script itself is programmed to execute a reload). This particular script performs the configuration tasks of creating and then verifying the creation of 1000 VLANs. This example demonstrates the following areas: i. ii. iii.
print ("Creating 1000 VLANs on the switch") for x in range(2, 1002): cmd = "vlan %d" %(x) send (cmd + '\r') expect(confPrompt) send ('exit\r') expect(confPrompt) #parse to count vlans created print ("Verifying the VLAN database") send('show vlan\r') vlan = expect(confPrompt) totalVlan = re.findall(r"VLAN(\d+){3}", vlan) exp = len(range(2, 1002)) #if-else to determine output if len(totalVlan) == exp: print exp,("VLANs are created on the switch") else: print ("Failed to create required number of VLANs on the
console#application start Opening telnet session to the device Creating 1000 VLANs on the switch Verifying the VLAN database VLANs are created on the switch Closing the telnet session Run the appropriate show commands to verify the results. console#show vlan VLAN Name ------------------1 default 3.4 Ports ----------Po1-128, Gi1/0/1-48, Te1/0/1-2 Type -----------Default 2 3 4 VLAN0002 VLAN0003 VLAN0004 Static Static Static 1001 1002 VLAN1001 VLAN1002 Static Static . ..
4 Troubleshooting This section provides tips on how to help alleviate problems that may be encountered when working with Python scripts. Problem Possible Solution(s) error “ImportError: no module” is received when importing a module into Python The module you are trying to use is not available. Double-check the spelling of the module. It is also possible that the module is valid for Python but not supported in the Dell N-Series switch.
“tar: no gzip magic” message is seen while copying the compressed file to the switch or “Unable to unpack archive…” message is seen while copying the compressed file to the switch The method used to compress the file is not acceptable, and the switch is not able to unpack it. Be sure to compress the script into a gzipped tar archive, with either a .tgz or .tar.gz extension as discussed on page 8 of this guide.
A Supported Python modules Table 1 shows the complete list of Python version 2.7 modules included with Dell N-Series switches. Each module is defined in the Python Standard Library.
_elementtree _functools _heapq _hotshot _io _json _locale _lsprof _md5 _multibytecodec _multiprocessing _osx_support _pyio _random _sha _sha256 _sha512 _socket _sre _ssl _strptime _struct _symtable _sysconfigdata _testcapi _threading_local _warnings _weakref _weakrefset abc aifc antigravity anydbm argparse array ast asynchat asyncore atexit audiodev 23 doctest dumbdbm dummy_thread dummy_threading email encodings errno exceptions fcntl filecmp fileinput fnmatch formatter fpformat fractions ftplib functools
B Console output options Python scripting output is displayed from the console. For a single switch, the console cable that comes with the Dell N-Series switch can be used to view the console output. This is the preferred method for those situations where there are only a few switches involved. See the User Guide for your switch for more information on how to use the console port.
C Glossary of Terms console – the interface that uses the serial port of a switch for management purposes. console switch – a device that allows management of several switches from a single management station, via the console port on each switch. CLI (command line interface) – a text-based interface for issuing commands to a switch (typically uses Telnet, SSH, or a serial console).
D Versions This document was compiled using the following components and versions: 26 Component Version Dell Networking N-Series firmware 6.3.0.3 Python (Dell N-Series supported modules) 2.7.10 Python 2.7.6 Ubuntu 14.04.3 gedit 3.10.4 tar (GNU tar) 1.27.1 Python Scripting for Dell Networking N-Series | Version 1.0.
Additional Resources Support.dell.com is focused on meeting your needs with proven services and support. DellTechCenter.com is an IT Community where you can connect with Dell EMC customers and Dell EMC employees to share knowledge, best practices and information about Dell EMC products and installations. Referenced or recommended Dell EMC publications: 27 • Dell Networking Support - http://www.dell.
Support and Feedback Contacting Technical Support Support Contact Information Web: http://Support.Dell.com/ Telephone: USA: 1-800-945-3355 Feedback for this document We encourage readers of this publication to provide feedback on the quality and usefulness of this deployment guide by sending an email to Dell_Networking_Solutions@Dell.