Cisco VPP CSIT调用API过程
2018-02-27 20:18
357 查看
csit_cmd: vpp_ipsec_add_sad_entry file: vpp-csit\csit\resources\libraries\python\IPsecUtil.py 1、组织数据 ckey = crypto_key.encode('hex') ikey = integ_key.encode('hex') tunnel = 'tunnel_src {0} tunnel_dst {1}'.format(tunnel_src, tunnel_dst)\ if tunnel_src is not None and tunnel_dst is not None else '' 2、调用SSH out = VatExecutor.cmd_from_template(node, "ipsec/ipsec_sad_add_entry.vat", sad_id=sad_id, spi=spi, calg=crypto_alg.alg_name, ckey=ckey, ialg=integ_alg.alg_name, ikey=ikey, tunnel=tunnel) 2.1: ipsec/ipsec_sad_add_entry.vat 内容 file: vpp-csit\csit\resources\templates\vat\ipsec\ipsec_sad_add_entry.vat date: ipsec_sad_add_del_entry esp sad_id {sad_id} spi {spi} crypto_alg {calg} crypto_key {ckey} integ_alg {ialg} integ_key {ikey} {tunnel} 2.2: VatExecutor.cmd_from_template 调用过程 2.2.1:file: vpp-csit\csit\resources\libraries\python\VatExecutor.py func: def cmd_from_template(node, vat_template_file, **vat_args): """Execute VAT script on specified node. This method supports script templates with parameters. :param node: Node in topology on witch the script is executed. :param vat_template_file: Template file of VAT script. :param vat_args: Arguments to the template file. :return: List of JSON objects returned by VAT. """ with VatTerminal(node) as vat: return vat.vat_terminal_exec_cmd_from_template(vat_template_file, **vat_args) describute: 构造VatTerminal对象时,VatTerminal首先打开SSH连接(interactive_terminal_open),然后 调用interactive_terminal_exec_command启动(VAT_BIN_NAME = 'vpp_api_test'),终端进入 VAT模式,此时的SSH调用都在VAT环境中进行 1、连接SSH 2、启动vpp_api_test进程(vpp_api_test进程使用共享内存方式与VPP交互) 2.2.2:file: vpp-csit\csit\resources\libraries\python\VatExecutor.py func: def vat_terminal_exec_cmd_from_template(self, vat_template_file, **args): """Execute VAT script from a file. :param vat_template_file: Template file name of a VAT script. :param args: Dictionary of parameters for VAT script. :return: List of JSON objects returned by VAT. """ file_path = '{}/{}'.format(Constants.RESOURCES_TPL_VAT, vat_template_file) with open(file_path, 'r') as template_file: cmd_template = template_file.readlines() ret = [] for line_tmpl in cmd_template: vat_cmd = line_tmpl.format(**args) ret.append(self.vat_terminal_exec_cmd(vat_cmd.replace('\n', ''))) return ret 2.2.3:file: vpp-csit\csit\resources\libraries\python\VatExecutor.py func: def vat_terminal_exec_cmd(self, cmd): """Execute command on the opened VAT terminal. :param cmd: Command to be executed. :return: Command output in python representation of JSON format or None if not in JSON mode. """ VatHistory.add_to_vat_history(self._node, cmd) logger.debug("Executing command in VAT terminal: {0}".format(cmd)) try: out = self._ssh.interactive_terminal_exec_command(self._tty, cmd, self.__VAT_PROMPT) ........ ........ ........ 2.2.4: file: vpp-csit\csit\resources\libraries\python\ssh.py func: chan.sendall('{c}\n'.format(c=cmd)) buf = '' while not buf.endswith(prompt): try: chunk = chan.recv(self.__MAX_RECV_BUF) if not chunk: break buf += chunk ........ ........ ........ csit_cmd: show_vpp_settings file: vpp-csit\csit\resources\libraries\python\VPPUtil.py func: def_setting_tb_displayed = { 'IPv6 FIB': 'ip6 fib', 'IPv4 FIB': 'ip fib', 'Interface IP': 'int addr', 'Interfaces': 'int', 'ARP': 'ip arp', 'Errors': 'err' } if additional_cmds: for cmd in additional_cmds: def_setting_tb_displayed['Custom Setting: {}'.format(cmd)] = cmd ssh = SSH() ssh.connect(node) for _, value in def_setting_tb_displayed.items(): ssh.exec_command_sudo('vppctl sh {}'.format(value)) 1、组织数据 2、打开SSH终端 3、使用vppctl方式调用CLI命令
相关文章推荐
- 关于opentack的(2)--利用debug信息大概了解api的调用过程
- Adodbapi调用sqlserver储存过程的问题及pymssql的使用2009-12-22
- 在C#中调用API的基本过程
- 简单介绍C#调用API的基本过程
- 跟着Code走,详解Symbian OS API调用过程
- 壳的加载过程中需要的API用显式调用加载dll
- 调用docker registry api交互过程中http code码详解
- 24、jQuery常用AJAX-API/Java调用MySQL / Oracle过程与函数
- 在Visual C#中调用API的基本过程:
- 在Visual C#中调用API的基本过程:
- 在Visual C#中调用API的基本过程
- 浅析Linux从API调用到底层驱动的过程
- 在C#中调用API的基本过程 .
- 再测一个mybatis调用oracle过程
- 暴强贴:从.NET平台调用Win32 API
- JENKINS的远程API调用,然后用PYTHON解析出最新的版本及稳定成功的版本
- eoLinker-API_Shop_验证码识别API调用的代码示例合集:四位图片验证码生成等
- java后台api间的相互调用
- 通过 Hibernate 调用存储过程
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation