Owner's Manual
Smart Scripting | 69
Creating a Python API Script
To create a Python script to be run on a Dell Networking switch, use the information
in this section. For information about how to run a Python script from the Dell
Networking OS CLI, refer to Scheduling Time / Event-based Scripts.
F10SmartUtils.py is the Python API library containing the supported functions
(described in Supported Dell Networking OS API Functions in Python Scripts),
which you can use in a Python script to invoke Dell Networking OS operations on a
switch. This file is stored at /usr/pkg/scripts/smartutils.
Code Dell Networking OS API functions in a Python script as shown in the following
example:
Figure 5-3. Python Script with API function call: Example
#!/usr/pkg/bin/python
import sys
sys.path.append('/usr/pkg/scripts/smartutils') <--------------- Load the Python
API
import F10SmartUtils
def create_vlans(startId,endId):
for vlanId in range(startId,endId+1):
result = F10SmartUtils.F10CreateVlanId(vlanId) <------- Invoke a Python API
function
print result
def main(args):
try:
startId = int(args[0])
endId = int(args[1])
if(startId<=endId):
create_vlans(startId, endId)
else :
print "Invalid range: startId cannot be larger than
endId",startId,endId
except ValueError:
print "Invalid arguments",args
if __name__=="__main__":
if len(sys.argv)>2:
main(sys.argv[1:])
else:
print "Please supply valid arguments"
print "createVlans.py <startId> <endId>"