wrapper to the Spirent TestCenter Tcl shell API(stc::, sth::)
Project description
changelist
- 1.1.0, support convert true/false to bool type, and break children attribute's value to list
- 1.0.2, fix missing API.TXT
- 1.0.1, update brief
- 1.0.0, support stc:: sth:: tclsh call
feedback
- send email to dvdface@gmail.com
- visit https://github.com/dvdface/spirentapi
how to install
pip install spirentapi
known issues
Greate FireWall in China may prevent teacup install Tclx and ip pakcages
Tclx and ip packages are needed by SpirentHltApi
so, you may need VPN to install Tclx and ip
you can try to type teacup install Tclx
and teacup install ip
in the tclsh to check
how to use
-
install Tcl/Tk
visit https://www.activestate.com/products/tcl/downloads/ to install Tcl/Tk
Spirent TestCenter need 8.5 version
-
set PATH environment
set
PATH
environment, include tcl/tk pathfor example:
PATH=C:\Tcl\bin;%PATH%
-
install Spirent TestCenter
visit Spirent TestCenter Web Portal, download and install Spirent TestCenter
-
set SpirentTestCenter environment
set
SpirentTestCenter
environmentpoint to Spirent TestCenter installation directory
testcenter.exe should under the path
for example:
SpirentTestCenter="C:\Program Files\Spirent Communications\Spirent TestCenter 4.95\Spirent TestCenter Application"
-
import spirentapi
from spirentapi import SpirentAPI
-
use tclsh
# create SpirentAPI object api = SpirentAPI() # use teacup to install packages # you don't need install Tclx, ip, SpirentAPI's __init__ function will install for you api.install('Tclx') api.install('ip') # run tcl/sh command # you don't need run the following commands, SpirentAPI's __init__ function will run for you api.eval('package require SpirentTestCenter') api.eval('package require SpirentHltApi') # shutdown tclsh del api
-
use stc:: api
# create SpirentAPI object api = SpirentAPI() # call stc::connect api.stc_connect(chassisIp='10.182.32.138') # call stc::create, and access result project_handle = api.stc_create(objectType='Project', under='system1') # call stc::perform api.stc_perform(cmd='SaveAsXml', config=project_handle, filename='test.xml') # call stc::disconnect api.stc_disconnect(chassisIp='10.182.32.138') # shutdown tclsh del api
-
use sth:: api
Notes: because sth:: function is dynamically created, so some IDE can't give you hint. If you know how to fix it, tell me(dvdface@hotmail.com)
# create SpirentAPI object api = SpirentAPI() # call sth::connect -device '10.182.32.138' -port_list '1/1 1/11', and access result conn_ret = api.sth_connect(device='10.182.32.138', port_list='1/1 1/11', break_locks=1) # access result by dot # name is a special key, save the variable name of sth:: command returns # if you want to access the result by youself, you can use the variable conn_ret.name conn_ret.status conn_ret.offline # call sth::cleanup_session api.sth_cleanup_session() # shutdown tclsh del api
how to extend
-
override default implementation of sth::
Sometimes, it's not convenience to access result of sth:: command by dotfor example:
conn_ret = api.sth_connect(device='10.182.32.138', port_list='1/1 1/11', break_locks=1) # access port handle is very unconvenience conn_ret['port_handle']['10']['182']['32']['138']['1/1'] # so you can extend SpirentAPI, add a sth_connect function to override dynamically created function class MyExtendedAPI(SpirentAPI): def sth_connect(self, **kwargs): # use _run_api to run sth::connect # same as set connect? [ sth::connect ... ] # you can know connect? by ret.name ret = self._run_api('connect', 'sth::connect', **kwargs) # create a special key to save your result ret.port_handles = [ ] for port in re.split("\s+", kwargs['port_list']): port_handle = self.eval( 'keylget %s port_handle.%s.%s' % (ret.name, kwargs['device'], port)) ret.port_handles.append(port_handle) logger.debug('sth_connect return: %s' % ret) return ret
-
add more sth:: functions
you can modify the API.TXT file under package, add the sth:: function name to it
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.