How to use create_router_interface method in tempest

Best Python code snippet using tempest_python

ec_same_account.py

Source:ec_same_account.py Github

copy

Full Screen

...16client = ACS_CLIENT17class RouterInterface(object):18 def __init__(self, client):19 self.client = client20 def create_router_interface(self, params):21 """22 create_router_interface: 创建路由器接口23 官网API参考: https://help.aliyun.com/document_detail/36032.html24 """25 try:26 request = CreateRouterInterfaceRequest.CreateRouterInterfaceRequest()27 # 路由器接口的规格28 request.set_Spec(params['spec'])29 # 路由器接口的角色30 request.set_Role(params['role'])31 # 路由器接口关联的路由器ID32 request.set_RouterId(params['router_id'])33 # 路由器接口关联的路由器类型34 request.set_RouterType(params['router_type'])35 # 连接接收端所在的地域ID36 request.set_OppositeRegionId(params['opposite_region_id'])37 # 对端路由器接口关联的路由器类型38 request.set_OppositeRouterType(params['opposite_router_type'])39 response = self.client.do_action_with_exception(request)40 response_json = json.loads(response)41 # 判断Router Interface状态是否可用42 if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,43 self.describe_ri_status,44 'Idle', response_json['RouterInterfaceId']):45 return response_json46 except ServerException as e:47 ExceptionHandler.server_exception(e)48 except ClientException as e:49 ExceptionHandler.client_exception(e)50 def connect_router_interface(self, params):51 """52 connect_router_interface: 由发起端路由器接口向接收端发起连接53 官网API参考: https://help.aliyun.com/document_detail/36031.html54 """55 try:56 request = ConnectRouterInterfaceRequest.ConnectRouterInterfaceRequest()57 # 发起端路由器接口的ID58 request.set_RouterInterfaceId(params['router_interface_id'])59 response = self.client.do_action_with_exception(request)60 response_json = json.loads(response)61 if CheckStatus.check_status(TIME_DEFAULT_OUT * 5, DEFAULT_TIME * 5,62 self.describe_ri_status,63 'Active', params['router_interface_id']):64 return response_json65 except ServerException as e:66 ExceptionHandler.server_exception(e)67 except ClientException as e:68 ExceptionHandler.client_exception(e)69 def deactivate_router_interface(self, params):70 """71 deactivate_router_interface: 冻结路由器接口72 官网API参考: https://help.aliyun.com/document_detail/36033.html73 """74 try:75 request = DeactivateRouterInterfaceRequest.DeactivateRouterInterfaceRequest()76 # 路由器接口的ID77 request.set_RouterInterfaceId(params['router_interface_id'])78 response = self.client.do_action_with_exception(request)79 response_json = json.loads(response)80 # 判断Router Interface状态是否可用81 if CheckStatus.check_status(TIME_DEFAULT_OUT * 5, DEFAULT_TIME * 5,82 self.describe_ri_status,83 'Inactive', params['router_interface_id']):84 return response_json85 except ServerException as e:86 ExceptionHandler.server_exception(e)87 except ClientException as e:88 ExceptionHandler.client_exception(e)89 def modify_router_interface_attribute(self, params):90 """91 modify_router_interface_attribute: 修改路由器接口的配置92 官网API参考: https://help.aliyun.com/document_detail/36036.html93 """94 try:95 request = ModifyRouterInterfaceAttributeRequest.ModifyRouterInterfaceAttributeRequest()96 # 路由器接口的ID97 request.set_RouterInterfaceId(params['router_interface_id'])98 # 对端路由器接口ID99 request.set_OppositeInterfaceId(params['opposite_interface_id'])100 # 对端的路由器的ID101 request.set_OppositeRouterId(params['opposite_router_id'])102 response = self.client.do_action_with_exception(request)103 response_json = json.loads(response)104 # 判断Router Interface状态是否可用105 if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME,106 self.describe_ri_status,107 'Idle', params['router_interface_id']):108 return response_json109 except ServerException as e:110 ExceptionHandler.server_exception(e)111 except ClientException as e:112 ExceptionHandler.client_exception(e)113 def describe_router_interface(self, instance_id):114 """115 describe_router_interface: 查询指定地域内的路由器接口116 官网API参考: https://help.aliyun.com/document_detail/36035.html117 """118 try:119 request = DescribeRouterInterfacesRequest.DescribeRouterInterfacesRequest()120 # 查询的过滤类型121 request.add_query_param('Filter.1.Key', "RouterInterfaceId")122 # 查询的实例ID123 request.add_query_param('Filter.1.Value.1', instance_id)124 response = self.client.do_action_with_exception(request)125 response_json = json.loads(response)126 return response_json127 except ServerException as e:128 ExceptionHandler.server_exception(e)129 except ClientException as e:130 ExceptionHandler.client_exception(e)131 def describe_ri_status(self, instance_id):132 """133 describe_ri_status: 查询指定地域内的路由器接口状态134 官网API参考: https://help.aliyun.com/document_detail/36035.html135 """136 response = self.describe_router_interface(instance_id)137 if len(response['RouterInterfaceSet']['RouterInterfaceType']) == 0:138 return ''139 return response['RouterInterfaceSet']['RouterInterfaceType'][0]['Status']140 def delete_router_interface(self, params):141 """142 delete_router_interface: 删除路由器接口143 官网API参考: https://help.aliyun.com/document_detail/36034.html144 """145 try:146 request = DeleteRouterInterfaceRequest.DeleteRouterInterfaceRequest()147 # 路由器接口的ID148 request.set_RouterInterfaceId(params['instance_id'])149 response = self.client.do_action_with_exception(request)150 response_json = json.loads(response)151 # 判断Router Interface状态是否可用152 if CheckStatus.check_status(TIME_DEFAULT_OUT, DEFAULT_TIME * 5,153 self.describe_ri_status,154 '', params['instance_id']):155 return response_json156 except ServerException as e:157 ExceptionHandler.server_exception(e)158 except ClientException as e:159 ExceptionHandler.client_exception(e)160def main():161 router_interface = RouterInterface(client)162 route_entry = RouteEntry(client)163 params = {}164 params['spec'] = "Large.2"165 params['role'] = "InitiatingSide"166 params['router_id'] = ROUTER_ID167 params['router_type'] = "VRouter"168 params['opposite_region_id'] = "cn-hangzhou"169 params['opposite_router_type'] = "VRouter"170 # 创建发起端ri171 router_interface_json = router_interface.create_router_interface(params)172 CommonUtil.log("create_router_interface", router_interface_json)173 # 创建接收端ri174 params['spec'] = "Negative"175 params['role'] = "AcceptingSide"176 params['router_id'] = ROUTER_ID2177 router_interface_json2 = router_interface.create_router_interface(params)178 CommonUtil.log("create_router_interface", router_interface_json2)179 # 修改发起端ri信息180 params['router_interface_id'] = router_interface_json['RouterInterfaceId']181 params['opposite_interface_id'] = router_interface_json2['RouterInterfaceId']182 params['opposite_router_id'] = ROUTER_ID2183 modify_ri_json = router_interface.modify_router_interface_attribute(params)184 CommonUtil.log("modify_router_interface_attribute", modify_ri_json)185 # 修改接收端ri信息186 params['router_interface_id'] = router_interface_json2['RouterInterfaceId']187 params['opposite_interface_id'] = router_interface_json['RouterInterfaceId']188 params['opposite_router_id'] = ROUTER_ID189 modify_ri_json2 = router_interface.modify_router_interface_attribute(params)190 CommonUtil.log("modify_router_interface_attribute", modify_ri_json2)191 # 查询发起端ri信息...

Full Screen

Full Screen

sai_l3.py

Source:sai_l3.py Github

copy

Full Screen

...54 vr_attribute2 = sai_thrift_attribute_t(id=1, value=vr_attribute1_value)55 vr_attr_list = [vr_attribute1, vr_attribute2]56 vr_id = client.sai_thrift_create_virtual_router(thrift_attr_list=vr_attr_list)57 return vr_id58def create_router_interface(client, vr_id, is_port, port_id, vlan_id,59 v4_enabled, v6_enabled):60 #vrf attribute61 rif_attribute1_value = sai_thrift_attribute_value_t(oid=vr_id)62 rif_attribute1 = sai_thrift_attribute_t(id=0, value=rif_attribute1_value)63 if is_port:64 #port type and port id65 rif_attribute2_value = sai_thrift_attribute_value_t(u8=0)66 rif_attribute2 = sai_thrift_attribute_t(id=1,67 value=rif_attribute2_value)68 rif_attribute3_value = sai_thrift_attribute_value_t(oid=port_id)69 rif_attribute3 = sai_thrift_attribute_t(id=2,70 value=rif_attribute3_value)71 else:72 #vlan type and vlan id73 rif_attribute2_value = sai_thrift_attribute_value_t(u8=1)74 rif_attribute2 = sai_thrift_attribute_t(id=1,75 value=rif_attribute2_value)76 rif_attribute3_value = sai_thrift_attribute_value_t(u16=vlan_id)77 rif_attribute3 = sai_thrift_attribute_t(id=3,78 value=rif_attribute3_value)79 #v4_enabled80 rif_attribute4_value = sai_thrift_attribute_value_t(booldata=v4_enabled)81 rif_attribute4 = sai_thrift_attribute_t(id=5, value=rif_attribute4_value)82 #v6_enabled83 rif_attribute5_value = sai_thrift_attribute_value_t(booldata=v6_enabled)84 rif_attribute5 = sai_thrift_attribute_t(id=6, value=rif_attribute5_value)85 rif_attr_list = [rif_attribute1, rif_attribute2, rif_attribute3,86 rif_attribute4, rif_attribute5]87 rif_id = client.sai_thrift_create_router_interface(rif_attr_list)88 return rif_id89def create_route(client, vr_id, addr_family, ip_addr, ip_mask, nhop):90 if addr_family == 0:91 addr = sai_thrift_ip_t(ip4=ip_addr)92 mask = sai_thrift_ip_t(ip4=ip_mask)93 ip_prefix = sai_thrift_ip_prefix_t(addr_family=0, addr=addr, mask=mask)94 else:95 addr = sai_thrift_ip_t(ip6=ip_addr)96 mask = sai_thrift_ip_t(ip6=ip_mask)97 ip_prefix = sai_thrift_ip_prefix_t(addr_family=1, addr=addr, mask=mask)98 route_attribute1_value = sai_thrift_attribute_value_t(oid=nhop)99 route_attribute1 = sai_thrift_attribute_t(id=2,100 value=route_attribute1_value)101 route = sai_thrift_unicast_route_entry_t(vr_id, ip_prefix)102 route_attr_list = [route_attribute1]103 client.sai_thrift_create_route(thrift_unicast_route_entry=route,104 thrift_attr_list=route_attr_list)105def create_nhop(client, addr_family, ip_addr, rif_id):106 if addr_family == 0:107 addr = sai_thrift_ip_t(ip4=ip_addr)108 ipaddr = sai_thrift_ip_address_t(addr_family=0, addr=addr)109 else:110 addr = sai_thrift_ip_t(ip6=ip_addr)111 ipaddr = sai_thrift_ip_address_t(addr_family=1, addr=addr)112 nhop_attribute1_value = sai_thrift_attribute_value_t(ipaddr=ipaddr)113 nhop_attribute1 = sai_thrift_attribute_t(id=1, value=nhop_attribute1_value)114 nhop_attribute2_value = sai_thrift_attribute_value_t(oid=rif_id)115 nhop_attribute2 = sai_thrift_attribute_t(id=2, value=nhop_attribute2_value)116 nhop_attr_list = [nhop_attribute1, nhop_attribute2]117 nhop = client.sai_thrift_create_next_hop(thrift_attr_list=nhop_attr_list)118 return nhop119def create_neighbor(client, addr_family, rif_id, ip_addr, dmac):120 if addr_family == 0:121 addr = sai_thrift_ip_t(ip4=ip_addr)122 ipaddr = sai_thrift_ip_address_t(addr_family=0, addr=addr)123 else:124 addr = sai_thrift_ip_t(ip6=ip_addr)125 ipaddr = sai_thrift_ip_address_t(addr_family=1, addr=addr)126 neighbor_attribute1_value = sai_thrift_attribute_value_t(mac=dmac)127 neighbor_attribute1 = sai_thrift_attribute_t(id=0,128 value=neighbor_attribute1_value)129 neighbor_attr_list = [neighbor_attribute1]130 neighbor_entry = sai_thrift_neighbor_entry_t(rif_id=rif_id,131 ip_address=ipaddr)132 client.sai_thrift_create_neighbor_entry(neighbor_entry, neighbor_attr_list)133def cfg_switch1():134 port_list = []135 transport, client = open_connection(25000)136 switch_attr_list = client.sai_thrift_get_switch_attribute()137 attr_list = switch_attr_list.attr_list138 for attr in attr_list:139 if attr.id == 0:140 print 'max ports: ', attr.value.u32141 elif attr.id == 1:142 for x in attr.value.objlist.object_id_list:143 port_list.append(x)144 else:145 print 'unknown switch attribute'146 port1 = port_list[0]147 port2 = port_list[1]148 vr = create_virtual_router(client, v4_enabled=1, v6_enabled=1)149 attr_value = sai_thrift_attribute_value_t(mac='00:01:00:00:00:03')150 attr = sai_thrift_attribute_t(id=17, value=attr_value)151 client.sai_thrift_set_switch_attribute(attr)152 rif1 = create_router_interface(client, vr, 1, port1, 0, v4_enabled=1,153 v6_enabled=1)154 attr_value = sai_thrift_attribute_value_t(mac='00:01:00:00:00:04')155 attr = sai_thrift_attribute_t(id=17, value=attr_value)156 client.sai_thrift_set_switch_attribute(attr)157 rif2 = create_router_interface(client, vr, 1, port2, 0, v4_enabled=1,158 v6_enabled=1)159 nhop1 = create_nhop(client, 0, '172.16.101.5', rif1)160 create_neighbor(client, 0, rif1, '172.16.101.5', '00:03:00:00:00:01')161 nhop2 = create_nhop(client, 0, '172.16.10.2', rif2)162 create_neighbor(client, 0, rif2, '172.16.10.2', '00:02:00:00:00:04')163 create_route(client, vr, 0, '172.16.101.5', '255.255.255.255', nhop1)164 create_route(client, vr, 0, '172.16.10.2', '255.255.255.255', nhop2)165 create_route(client, vr, 0, '172.16.102.0', '255.255.255.0', nhop2)166 close_connection(transport)167def cfg_switch2():168 port_list = []169 transport, client = open_connection(25001)170 switch_attr_list = client.sai_thrift_get_switch_attribute()171 attr_list = switch_attr_list.attr_list172 for attr in attr_list:173 if attr.id == 0:174 print 'max ports: ', attr.value.u32175 elif attr.id == 1:176 for x in attr.value.objlist.object_id_list:177 port_list.append(x)178 else:179 print 'unknown switch attribute'180 port1 = port_list[0]181 port2 = port_list[1]182 vr = create_virtual_router(client, v4_enabled=1, v6_enabled=1)183 attr_value = sai_thrift_attribute_value_t(mac='00:02:00:00:00:03')184 attr = sai_thrift_attribute_t(id=17, value=attr_value)185 client.sai_thrift_set_switch_attribute(attr)186 rif1 = create_router_interface(client, vr, 1, port1, 0, v4_enabled=1,187 v6_enabled=1)188 attr_value = sai_thrift_attribute_value_t(mac='00:02:00:00:00:04')189 attr = sai_thrift_attribute_t(id=17, value=attr_value)190 client.sai_thrift_set_switch_attribute(attr)191 rif2 = create_router_interface(client, vr, 1, port2, 0, v4_enabled=1,192 v6_enabled=1)193 nhop1 = create_nhop(client, 0, '172.16.102.5', rif1)194 create_neighbor(client, 0, rif1, '172.16.102.5', '00:04:00:00:00:01')195 nhop2 = create_nhop(client, 0, '172.16.10.1', rif2)196 create_neighbor(client, 0, rif2, '172.16.10.1', '00:01:00:00:00:04')197 create_route(client, vr, 0, '172.16.102.5', '255.255.255.255', nhop1)198 create_route(client, vr, 0, '172.16.10.1', '255.255.255.255', nhop2)199 create_route(client, vr, 0, '172.16.101.0', '255.255.255.0', nhop2)200 close_connection(transport)201def main():202 net = Mininet( controller = None )203 # add hosts204 h1 = net.addHost( 'h1', ip = '172.16.101.5/24', mac = '00:03:00:00:00:01' )205 h2 = net.addHost( 'h2', ip = '172.16.102.5/24', mac = '00:04:00:00:00:01' )...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful