How to use get_nic_name_by_mac method in tempest

Best Python code snippet using tempest_python

eip.py

Source:eip.py Github

copy

Full Screen

...53 return chain_name.split('-')[2]5455 def _create_eip(self, eip):56 ipt = iptables.from_iptables_save()57 private_nic_name = linux.get_nic_name_by_mac(eip.privateMac)58 vip_nic_name = linux.get_nic_name_by_ip(eip.vipIp)59 guest_ip = eip.guestIp60 vip = eip.vipIp6162 dnat_name = self._make_dnat_name(vip_nic_name, private_nic_name)63 snat_name = self._make_snat_name(vip_nic_name, private_nic_name)64 fwd_name = self._make_fwd_name(vip_nic_name, private_nic_name)6566 #def check_eip(table):67 #if not table:68 #return6970 #for chain in table.children:71 #vip_nic = self._get_vip_nic_name_from_chain_name(chain.name)72 #if vip_nic == vip_nic_name:73 #raise virtualrouter.VirtualRouterError('eip[%s] has been occupied, this is an internal error' % vip)7475 #check_eip(ipt.get_table(ipt.NAT_TABLE_NAME))76 #check_eip(ipt.get_table(ipt.FILTER_TABLE_NAME))7778 order = 99979 ipt.add_rule('-A PREROUTING -d {0} -j {1}'.format(vip, dnat_name), ipt.NAT_TABLE_NAME, order=order)80 ipt.add_rule('-A {0} -j DNAT --to-destination {1}'.format(dnat_name, guest_ip), ipt.NAT_TABLE_NAME, order=order)8182 ipt.add_rule('-A FORWARD -i {0} -o {1} -j {2}'.format(vip_nic_name, private_nic_name, fwd_name), order=order)83 ipt.add_rule('-A FORWARD -i {0} -o {1} -j {2}'.format(private_nic_name, vip_nic_name, fwd_name), order=order)84 ipt.add_rule('-A {0} -j ACCEPT'.format(fwd_name), order=order)8586 ipt.add_rule('-A POSTROUTING -s {0} -j {1}'.format(guest_ip, snat_name), ipt.NAT_TABLE_NAME, order=order)87 ipt.add_rule('-A {0} -j SNAT --to-source {1}'.format(snat_name, vip), ipt.NAT_TABLE_NAME, order=order)8889 if eip.snatInboundTraffic:90 gw_snat_name = self._make_gateway_snat_name(vip_nic_name, private_nic_name)91 guest_gw_ip = linux.get_ip_by_nic_name(private_nic_name)92 ipt.add_rule('-A POSTROUTING -d {0} -j {1}'.format(guest_ip, gw_snat_name), ipt.NAT_TABLE_NAME, order=order)93 ipt.add_rule('-A {0} -j SNAT --to-source {1}'.format(gw_snat_name, guest_gw_ip), ipt.NAT_TABLE_NAME, order=order)9495 ipt.iptable_restore()96 logger.debug('successfully created eip[{0}] to guest ip[{1}] from device[{2}] to device[{3}]'.format(vip, guest_ip, vip_nic_name, private_nic_name))9798 @virtualrouter.replyerror99 @lock.lock('eip')100 @lock.file_lock('iptables')101 def create_eip(self, req):102 cmd = jsonobject.loads(req[http.REQUEST_BODY])103 rsp = CreateEipRsp()104105 try:106 self._create_eip(cmd.eip)107 except virtualrouter.VirtualRouterError as e:108 logger.warning(linux.get_exception_stacktrace())109 rsp.error = str(e)110 rsp.success = False111112 return jsonobject.dumps(rsp)113114 def _remove_eip(self, eip):115 ipt = iptables.from_iptables_save()116 private_nic_name = linux.get_nic_name_by_mac(eip.privateMac)117 assert private_nic_name, "cannot find private nic by MAC[%s]" % eip.privateMac118 vip_nic_name = linux.get_nic_name_by_ip(eip.vipIp)119 assert vip_nic_name, "cannot find vip nic by IP[%s]" % eip.vipIp120 guest_ip = eip.guestIp121 vip = eip.vipIp122123 dnat_name = self._make_dnat_name(vip_nic_name, private_nic_name)124 snat_name = self._make_snat_name(vip_nic_name, private_nic_name)125 fwd_name = self._make_fwd_name(vip_nic_name, private_nic_name)126 gw_snat_name = self._make_gateway_snat_name(vip_nic_name, private_nic_name)127128 ipt.delete_chain(dnat_name, ipt.NAT_TABLE_NAME)129 ipt.delete_chain(snat_name, ipt.NAT_TABLE_NAME)130 ipt.delete_chain(gw_snat_name, ipt.NAT_TABLE_NAME) ...

Full Screen

Full Screen

snat.py

Source:snat.py Github

copy

Full Screen

...56 def make_snat_chain_name(self, private_nic_name):57 return self._make_name('snat', private_nic_name)5859 def _create_snat(self, info, iptc):60 privnicname = linux.get_nic_name_by_mac(info.privateNicMac)61 if not privnicname:62 raise virtualrouter.VirtualRouterError('cannot get private nic name for mac[%s]' % info.privateNicMac)63 pubnicnames = linux.get_nic_names_by_mac(info.publicNicMac)64 if not pubnicnames:65 raise virtualrouter.VirtualRouterError('cannot get public nic name for mac[%s]' % info.publicNicMac)66 pubnicname = pubnicnames[0].split(':')[0]6768 snat_chain_name = self.make_snat_chain_name(privnicname)69 iptc.add_rule('-A POSTROUTING -j %s' % snat_chain_name, iptc.NAT_TABLE_NAME)70 iptc.add_rule('-A {0} -o {1} -j SNAT --to-source {2}'.format(snat_chain_name, pubnicname, info.publicIp), iptc.NAT_TABLE_NAME)7172 fwd_chain_name = self._make_forward_chain_name(privnicname)73 iptc.add_rule('-A FORWARD -i {0} -o {1} -j {2}'.format(pubnicname, privnicname, fwd_chain_name))74 iptc.add_rule('-A FORWARD -i {0} -o {1} -j {2}'.format(privnicname, pubnicname, fwd_chain_name))75 iptc.add_rule('-A FORWARD -i {0} -o {1} -j {2}'.format(privnicname, privnicname, fwd_chain_name))76 iptc.add_rule('-A {0} -j ACCEPT'.format(fwd_chain_name))777879 def _remove_snat(self, info, iptc):80 privnicname = linux.get_nic_name_by_mac(info.privateNicMac)81 if not privnicname:82 raise virtualrouter.VirtualRouterError('cannot get private nic name for mac[%s]' % info.privateNicMac)8384 snat_chain_name = self.make_snat_chain_name(privnicname)85 iptc.delete_chain(snat_chain_name, iptc.NAT_TABLE_NAME)86 fwd_chain_name = self._make_forward_chain_name(privnicname)87 iptc.delete_chain(fwd_chain_name)8889 @virtualrouter.replyerror90 @lock.lock('snat')91 @lock.file_lock('iptables')92 def remove_snat(self, req):93 cmd = jsonobject.loads(req[http.REQUEST_BODY])94 rsp = RemoveSNATRsp() ...

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