Spirent TestCenter Tcl shell API 的包装器(stc::, sth::)
项目描述
更改列表
- 1.4.6,修复STCObject属性设置bug
- 1.4.5,修复STCObject.type bug
- 1.4.2, 修复 stc_get 函数返回 None 而不是 '' str
- 1.4.1,修复stdout输出字符过多时的死锁问题
- 1.4.0,添加STCObject,可以使用该对象包装stc_create、stc_get返回的句柄,然后可以通过object[attribute]方式轻松访问和设置属性
- 1.3.1、修复bug:有些值为掩码,如111、011,应保持str类型,auto convert函数无法处理,去掉auto convert to result
- 1.3.0,增加单例模式,可以使用SpirentAPI.instance获取实例
- 1.2.7,修复stc::get的bug
- 1.2.6、添加测试用例
- 1.2.5、strip { }后的strip空格;将 '' 结果变为无
- 1.2.4、添加pytest-cov
- 1.2.3,修复stc_get的bug
- 1.2.2, 修复 stc_get, stc_get(self, handle:str, attributes:Optional[list[str]]=[]) -> Union[dotdict, str, int, float, bool, datetime]
- 1.2.1、添加测试用例
- 1.2.0,将函数签名更改为 stc_get(self, handle:str, attributes:Optional[list[str]]=[]) -> dotdict:
- 1.1.0,支持将true/false转换为bool类型,并将children属性的值分解为list
- 1.0.2,修复缺少的API.TXT
- 1.0.1,更新简介
- 1.0.0,支持stc::sth::tclsh调用
反馈
如何安装
pip install spirentapi
已知的问题
- Greate FireWall 在中国可能会阻止茶杯安装 Tclx 和 ip pakcages
SpirentHltApi 需要 Tclx 和 ip 包
所以,你可能需要 VPN 来安装 Tclx 和 ip
您可以尝试键入teacup install Tclx
并teacup install ip
在 tclsh 中进行检查
如何使用
-
安装 Tcl/Tk
访问https://www.activestate.com/products/tcl/downloads/ 安装 Tcl/Tk
思博伦TestCenter需要8.5版本
-
设置PATH环境
设置
PATH
环境,包括 tcl/tk 路径例如:
PATH=C:\Tcl\bin;%PATH%
-
安装思博伦测试中心
访问 Spirent TestCenter Web 门户,下载并安装 Spirent TestCenter
-
设置 SpirentTestCenter 环境
设置
SpirentTestCenter
环境指向 Spirent TestCenter 安装目录
testcenter.exe 应该在路径下
例如:
SpirentTestCenter="C:\Program Files\Spirent Communications\Spirent TestCenter 4.95\Spirent TestCenter Application"
-
导入 spirentapi
from spirentapi import SpirentAPI
-
使用 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
-
使用 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') # use STCObject to wrap handle to access or set attributes project_object = STCObject(project_handle) project_object['Name'] project_object['Name'] = 'new name' # 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
-
使用某事:: api
注意:因为 sth:: 函数是动态创建的,所以有些 IDE 不能给你提示。如果您知道如何修复它,请告诉我 ( 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
如何扩展
-
覆盖 sth:: 的默认实现
有时,通过点访问 sth:: 命令的结果并不方便例如:
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
-
添加更多 sth::functions
可以修改 package 下的 API.TXT 文件,添加 sth:: 函数名
项目详情
spirentapi -1.4.6.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ae08af035816813269b2f2641c62de12c181b43d4430d65c8a836fe31e9d38a9 |
|
MD5 | 90adba785aa992e4799c05be2096d5ba |
|
布莱克2-256 | 063df17a48e98ed239b61ab472754a5c7e6eca1cc076d95b21df7d63c0797bb1 |