本文整理汇总了Python中pyroute2.IPRoute.get_netns_info方法的典型用法代码示例。如果您正苦于以下问题:Python IPRoute.get_netns_info方法的具体用法?Python IPRoute.get_netns_info怎么用?Python IPRoute.get_netns_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyroute2.IPRoute
的用法示例。
在下文中一共展示了IPRoute.get_netns_info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestIPRoute
# 需要导入模块: from pyroute2 import IPRoute [as 别名]
# 或者: from pyroute2.IPRoute import get_netns_info [as 别名]
#.........这里部分代码省略.........
def test_create_ipvlan_l2(self):
return self._create_ipvlan('IPVLAN_MODE_L2')
def test_create_ipvlan_l3(self):
return self._create_ipvlan('IPVLAN_MODE_L3')
def _create_veth(self, peer):
ifname = self.uifname()
self.ip.link('add', kind='veth', ifname=ifname, peer=peer)
assert len(self.ip.link_lookup(ifname=ifname)) > 0
return ifname
def test_create_veth_simple(self):
require_user('root')
peer = self.uifname()
self._create_veth(peer)
assert len(self.ip.link_lookup(ifname=peer)) > 0
def test_create_veth_attrs(self):
require_user('root')
nsname = str(uuid.uuid4())
netns = NetNS(nsname)
try:
peer = {'ifname': self.uifname(),
'net_ns_fd': nsname}
self._create_veth(peer)
assert len(self.ip.link_lookup(ifname=peer['ifname'])) == 0
assert len(netns.link_lookup(ifname=peer['ifname'])) > 0
finally:
netns.close()
netns.remove()
def test_get_netns_info(self):
require_user('root')
nsname = str(uuid.uuid4())
netns = NetNS(nsname)
try:
peer = {'ifname': self.uifname(),
'net_ns_fd': nsname}
ifname = self._create_veth(peer)
# get veth
veth = self.ip.link('get', ifname=ifname)[0]
target = veth.get_attr('IFLA_LINK_NETNSID')
for info in self.ip.get_netns_info():
path = info.get_attr('NSINFO_PATH')
assert path.endswith(nsname)
netnsid = info['netnsid']
if target == netnsid:
break
else:
raise KeyError('peer netns not found')
finally:
netns.close()
netns.remove()
@skip_if_not_supported
def _create(self, kind, **kwarg):
name = self.uifname()
self.ip.link('add', ifname=name, kind=kind, **kwarg)
devs = self.ip.link_lookup(ifname=name)
assert devs
return (name, devs[0])
def test_create_dummy(self):
require_user('root')