User guide
Embedded Python Scripting Web Services, CLI Scripting and OpenFlow
page 11-26 OmniSwitch AOS Release 7 Switch Management Guide March 2015
-> show event-action statistics
Script Launch
Type Name Last Launched Count
------+---------------------------------------+--------------------+----------
trap linkDown 2014-10-23 13:45:34 2
Python Examples in AOS
To following is a simple interactive example of how AOS can be used to execute Python commands.
-> python3
Python 3.2.2 (default, Dec 10 2014, 02:41:47)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("Hello, World from AOS-python\n")
Hello, World from AOS-python
>>> quit()
->
To following is an example of how AOS can be used to execute a Python script named sample.py that is
stored on the switch.
-> cat sample.py
# sample python command file
for i in [1, 2, 3, 4]:
print("Hello, World " + str(i))
-> python3 sample.py
Hello, World 1
Hello, World 2
Hello, World 3
Hello, World 4
->
To following is an example of how AOS can be used to execute a Python script named import_sam-
ple.py that is stored on the switch and uses the imported subprocess and os libraries.
-> cat import_sample.py
#!/bin/python3
import os
import subprocess
result = subprocess.check_output(["show","microcode"],universal_newlines=True)
print ("----Subprocess Output----")
print (result)
print ("----OS Output----")
os.system("show microcode")
->
-> python3 import_sample.py
----Subprocess Output----
/flash/working
Package Release Size Description
-----------------+-------------------------+--------+---------------------------
Tos.img 7.3.4.314.R01 210517932 Alcatel-Lucent OS
----OS Output----
/flash/working
Package Release Size Description
-----------------+-------------------------+--------+---------------------------
Tos.img 7.3.4.314.R01 210517932 Alcatel-Lucent OS