本文整理汇总了Python中pyroute2.netns.remove函数的典型用法代码示例。如果您正苦于以下问题:Python remove函数的具体用法?Python remove怎么用?Python remove使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remove函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_create_peer_attrs
def test_create_peer_attrs(self):
foo = str(uuid4())
bar = str(uuid4())
ifA = uifname()
ifB = uifname()
netnsmod.create(foo)
netnsmod.create(bar)
with IPDB(nl=NetNS(foo)) as ip:
ip.create(ifname=ifA,
kind='veth',
peer={'ifname': ifB,
'net_ns_fd': bar}).commit()
assert ifA in ip.interfaces.keys()
assert ifB not in ip.interfaces.keys()
with IPDB(nl=NetNS(bar)) as ip:
assert ifA not in ip.interfaces.keys()
assert ifB in ip.interfaces.keys()
ip.interfaces[ifB].remove().commit()
assert ifA not in ip.interfaces.keys()
assert ifB not in ip.interfaces.keys()
with IPDB(nl=NetNS(foo)) as ip:
assert ifA not in ip.interfaces.keys()
assert ifB not in ip.interfaces.keys()
netnsmod.remove(foo)
netnsmod.remove(bar)
开发者ID:craneworks,项目名称:pyroute2,代码行数:29,代码来源:test_netns.py
示例2: test_connect_netns
def test_connect_netns(self):
nsname = str(uuid.uuid4())
with self.ndb.readonly:
s = len(list(self.ndb.interfaces.summary()))
assert self.count_interfaces(nsname) == 0
assert self.count_interfaces('localhost') == s
# connect RTNL source
event = threading.Event()
self.ndb.sources.add(**{'target': nsname,
'kind': 'netns',
'netns': nsname,
'event': event})
assert event.wait(5)
with self.ndb.readonly:
s = len(list(self.ndb.interfaces.summary()))
assert self.count_interfaces(nsname) > 0
assert self.count_interfaces('localhost') < s
# disconnect the source
self.ndb.sources[nsname].close()
with self.ndb.readonly:
s = len(list(self.ndb.interfaces.summary()))
assert self.count_interfaces(nsname) == 0
assert self.count_interfaces('localhost') == s
netns.remove(nsname)
开发者ID:svinota,项目名称:pyroute2,代码行数:28,代码来源:test_ndb.py
示例3: test_move_ns_fd
def test_move_ns_fd(self):
foo = str(uuid4())
bar = str(uuid4())
ifA = uifname()
ifB = uifname()
netnsmod.create(foo)
netnsmod.create(bar)
with IPDB(nl=NetNS(foo)) as ip:
ip.create(ifname=ifA, kind='veth', peer=ifB).commit()
assert ifA in ip.interfaces.keys()
assert ifB in ip.interfaces.keys()
with ip.interfaces[ifB] as intf:
intf.net_ns_fd = bar
assert ifA in ip.interfaces.keys()
assert ifB not in ip.interfaces.keys()
with IPDB(nl=NetNS(bar)) as ip:
assert ifA not in ip.interfaces.keys()
assert ifB in ip.interfaces.keys()
ip.interfaces[ifB].remove().commit()
assert ifA not in ip.interfaces.keys()
assert ifB not in ip.interfaces.keys()
with IPDB(nl=NetNS(foo)) as ip:
assert ifA not in ip.interfaces.keys()
assert ifB not in ip.interfaces.keys()
netnsmod.remove(foo)
netnsmod.remove(bar)
开发者ID:craneworks,项目名称:pyroute2,代码行数:30,代码来源:test_netns.py
示例4: test_move_ns_pid
def test_move_ns_pid(self):
foo = str(uuid4())
bar = str(uuid4())
ifA = uifname()
netnsmod.create(foo)
netnsmod.create(bar)
ns_foo = IPDB(nl=NetNS(foo))
ns_bar = IPDB(nl=NetNS(bar))
try:
ns_foo.create(ifname=ifA, kind='dummy').commit()
with ns_foo.interfaces[ifA] as iface:
iface.net_ns_pid = ns_bar.nl.server.pid
assert ifA in ns_bar.interfaces.keys()
assert ifA not in ns_foo.interfaces.keys()
with ns_bar.interfaces[ifA] as iface:
iface.net_ns_pid = ns_foo.nl.server.pid
assert ifA not in ns_bar.interfaces.keys()
assert ifA in ns_foo.interfaces.keys()
finally:
ns_foo.release()
ns_bar.release()
netnsmod.remove(foo)
netnsmod.remove(bar)
开发者ID:craneworks,项目名称:pyroute2,代码行数:29,代码来源:test_netns.py
示例5: setup_vnets
def setup_vnets(n_nets=3):
vnets = list()
for i in map(str, range(0, n_nets)):
try:
vns = IPDB(nl=NetNS('capdnet'+i, flags=os.O_CREAT | os.O_EXCL))
except OSError:
netns.remove('capdnet'+i)
vns = IPDB(nl=NetNS('capdnet'+i, flags=os.O_CREAT | os.O_EXCL))
try:
os.symlink(RUNDIR+'/defaults', '/etc/netns/capdnet'+i)
except OSError:
# some other day.
pass
vns.interfaces.lo.up().commit()
with ip.create(ifname='capd0peer'+i, kind='veth', peer='veth0') as dev:
dev.master = ip.interfaces['capd0'].index
dev.up()
ip.interfaces['veth0'].net_ns_fd = vns.nl.netns
ip.interfaces['veth0'].commit()
with vns.interfaces['veth0'] as dev:
dev.address = 'e0:00:00:00:00:00'
dev.add_ip('10.0.1.{}/8'.format(i)) # gonna break if > 253 threads
dev.up()
vns.routes.add({'dst': '0.0.0.0', 'mask': 0, 'gateway': '10.255.255.254'}).commit()
vnets.append(vns)
return vnets
开发者ID:veksev,项目名称:capd,代码行数:27,代码来源:daemon.py
示例6: test_multithread
def test_multithread(self):
require_user('root')
parallel_count = 5
test_count = 10
ns_names = ['testns%i' % i for i in range(parallel_count)]
success = [True]
for ns_name in ns_names:
NetNS(ns_name)
for _t in range(test_count):
threads = [
Thread(target=_ns_worker,
args=(netnsmod._get_netnspath(ns_name), i, success))
for i, ns_name in enumerate(ns_names)]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
for ns_name in ns_names:
netnsmod.remove(ns_name)
assert success[0]
开发者ID:svinota,项目名称:pyroute2,代码行数:27,代码来源:test_netns.py
示例7: test_connect_netns
def test_connect_netns(self):
nsname = str(uuid.uuid4())
with self.ndb.schema.db_lock:
s = len(self.ndb.interfaces.summary()) - 1
assert self.count_interfaces(nsname) == 0
assert self.count_interfaces('localhost') == s
# connect RTNL source
event = threading.Event()
self.ndb.connect_source(nsname, NetNS(nsname), event)
assert event.wait(5)
with self.ndb.schema.db_lock:
s = len(self.ndb.interfaces.summary()) - 1
assert self.count_interfaces(nsname) > 0
assert self.count_interfaces('localhost') < s
# disconnect the source
self.ndb.disconnect_source(nsname)
with self.ndb.schema.db_lock:
s = len(self.ndb.interfaces.summary()) - 1
assert self.count_interfaces(nsname) == 0
assert self.count_interfaces('localhost') == s
netns.remove(nsname)
开发者ID:celebdor,项目名称:pyroute2,代码行数:25,代码来源:test_ndb.py
示例8: remove
def remove(self):
'''
Try to remove this network namespace from the system.
This call be be ran only after `NetNS.close()`, otherwise
it will fail.
'''
remove(self.netns)
开发者ID:0x90,项目名称:pyroute2,代码行数:8,代码来源:nslink.py
示例9: remove_netns
def remove_netns(name, **kwargs):
"""Remove a network namespace.
:param name: The name of the namespace to remove
"""
try:
netns.remove(name, **kwargs)
except OSError as e:
if e.errno != errno.ENOENT:
raise
开发者ID:igordcard,项目名称:neutron,代码行数:10,代码来源:ip_lib.py
示例10: deleteService
def deleteService(data):
name = data['name']
customer = data['customer']
vr = data['virtualrouter']
svcId = data['Id']
if 'move' in data:
move = data['move']
else:
move = False
if 'delvn' in data:
delvn = data['delvn']
else:
delvn = False
print vr
print name + '_' + str(svcId)
lif = getLogicalInterface(vr, name + '_' + str(svcId))
if lif.get_virtual_machine_interface_refs() and not move:
for vmInt in lif.get_virtual_machine_interface_refs():
vmIntObj = vnc_client.virtual_machine_interface_read(id = vmInt['uuid'])
if vmIntObj.get_instance_ip_back_refs():
for instIp in vmIntObj.get_instance_ip_back_refs():
instIpObj = vnc_client.instance_ip_read(id = instIp['uuid'])
vnc_client.instance_ip_delete(id = instIp['uuid'])
if vmIntObj.get_logical_interface_back_refs():
for logicalInterface in vmIntObj.get_logical_interface_back_refs():
logInt = vnc_client.logical_interface_read(id = logicalInterface['uuid'])
logInt.del_virtual_machine_interface(vmIntObj)
vnc_client.logical_interface_update(logInt)
vnc_client.virtual_machine_interface_delete(id = vmIntObj.get_uuid())
vnc_client.logical_interface_delete(id = lif.get_uuid())
if not move:
vn = getVirtualNetwork(customer, name)
if delvn:
vnc_client.virtual_network_delete(id = vn.get_uuid())
p = subprocess.Popen(['ip','netns','pids',name + '_' + str(svcId)], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.splitlines():
print line
pid = int(line)
try:
os.kill(pid, signal.SIGKILL)
except:
print 'nothing to kill'
netns.remove(name + '_' + str(svcId))
ip_host = IPDB()
if name + '_' + str(svcId) in ip_host.interfaces:
with ip_host.interfaces[name + '_' + str(svcId)] as veth:
veth.remove()
subprocess.call(["ovs-vsctl", "del-port", "br0", name + '_' + str(svcId)])
if not move:
if delvn:
os.remove('/mnt/' + name + '.lease')
return json.dumps({ 'status' : 'deleted service'})
开发者ID:michaelhenkel,项目名称:tcc,代码行数:53,代码来源:ppServer.py
示例11: test_create_from_path
def test_create_from_path(self):
ns_dir = tempfile.mkdtemp()
# Create namespace
ns_name = str(uuid4())
nspath = '%s/%s' % (ns_dir, ns_name)
temp_ns = NetNS(nspath)
temp_ns.close()
fd = open(nspath)
self._test_create(nspath, fd.fileno())
fd.close()
netnsmod.remove(nspath)
assert ns_name not in netnsmod.listnetns()
assert ns_name not in netnsmod.listnetns(ns_dir)
开发者ID:craneworks,项目名称:pyroute2,代码行数:13,代码来源:test_netns.py
示例12: test_create
def test_create(self):
require_user('root')
nsid = str(uuid4())
ipdb_main = IPDB()
ipdb_test = IPDB(nl=NetNS(nsid))
if1 = uifname()
if2 = uifname()
# create VETH pair
ipdb_main.create(ifname=if1, kind='veth', peer=if2).commit()
# move the peer to netns
with ipdb_main.interfaces[if2] as veth:
veth.net_ns_fd = nsid
# assign addresses
with ipdb_main.interfaces[if1] as veth:
veth.add_ip('172.16.200.1/24')
veth.up()
with ipdb_test.interfaces[if2] as veth:
veth.add_ip('172.16.200.2/24')
veth.up()
# ping peer
try:
with open('/dev/null', 'w') as fnull:
subprocess.check_call(['ping', '-c', '1', '172.16.200.2'],
stdout=fnull, stderr=fnull)
ret_ping = True
except Exception:
ret_ping = False
# check ARP
time.sleep(0.5)
ret_arp = '172.16.200.1' in list(ipdb_test.interfaces[if2].neighbours)
# ret_arp = list(ipdb_test.interfaces.v0p1.neighbours)
# cleanup
ipdb_main.interfaces[if1].remove().commit()
ipdb_main.release()
ipdb_test.release()
netnsmod.remove(nsid)
assert ret_ping
assert ret_arp
assert nsid not in netnsmod.listnetns()
开发者ID:0xD3ADB33F,项目名称:pyroute2,代码行数:48,代码来源:test_netns.py
示例13: remove
def remove(self):
"""
Removes the Namespace and all included Network-Interfaces.
"""
logging.debug("%sDelete Namespace ...", LoggerSetup.get_log_deep(2))
try:
netns.remove(self.nsp_name)
self.ipdb_netns.release()
logging.debug("%s[+] Namespace(" + self.nsp_name + ") successfully deleted", LoggerSetup.get_log_deep(3))
except Exception as e:
if re.match("\[Errno 2\]*", str(e)):
logging.debug("%s[+] Namespace(" + self.nsp_name + ") is already deleted", LoggerSetup.get_log_deep(3))
return
logging.error("%s[-] Namespace(" + self.nsp_name +
") couldn't be deleted. Try 'ip netns delete <namespace_name>'", LoggerSetup.get_log_deep(3))
logging.error("%s" + str(e), LoggerSetup.get_log_deep(3))
开发者ID:PumucklOnTheAir,项目名称:TestFramework,代码行数:16,代码来源:namespace.py
示例14: deleteEndpoint
def deleteEndpoint(name, svcName, endpointtype):
if endpointtype == 'ns':
nsp = NSPopen(name, ['dhclient', '-r', name], stdout=subprocess.PIPE)
nsp.wait()
nsp.release()
netns.remove(name)
ip_host = IPDB()
if name + '_' + svcName in ip_host.interfaces:
with ip_host.interfaces[name + '_' + svcName] as veth:
veth.remove()
subprocess.call(["ovs-vsctl", "del-port", "vs-" + svcName, name + '_' + svcName])
if endpointtype == 'lxc':
subprocess.call(['/usr/bin/lxc-stop','-n',name])
subprocess.call(['/usr/bin/lxc-destroy','-n',name])
pass
return json.dumps({ 'status' : 'deleted endpoint'})
开发者ID:michaelhenkel,项目名称:tcc,代码行数:16,代码来源:terminalServer.py
示例15: __removePvd
def __removePvd(self, phyIfaceName, pvdId):
pvd = self.pvds.get((phyIfaceName, pvdId))
if (pvd):
# remove the network namespace associated with the PvD (this in turn removes the PvD network configuration as well)
if (pvd.netnsName in netns.listnetns()):
netns.remove(pvd.netnsName)
# remove the directory containing PvD-related DNS information
(dnsConfDir, dnsConfFile) = self.__getDnsConfPath(pvd.netnsName)
if (os.path.exists(dnsConfDir)):
shutil.rmtree(dnsConfDir, True)
# remove the PvD record from the PvD manager's log
del self.pvds[(phyIfaceName, pvdId)]
LOG.info('PvD {0} received through {1} REMOVED, network namespace {2} deleted, DNS directory {3} deleted, type {4}'.format(pvd.pvdId, pvd.phyIfaceName, pvd.netnsName, dnsConfDir, pvd.pvdInfo.pvdType))
self.pvdserver.stateChanged ("deleted", pvdId)
else:
raise Exception('There is no PvD {0} configured on {1}'.format(pvdInfo.pvdId, phyIfaceName))
开发者ID:l30nard0,项目名称:mif,代码行数:17,代码来源:pvdman.py
示例16: setup
def setup(self):
require_user('root')
try:
netns.create(NS_NAME)
except OSError as e:
if e.errno == errno.EEXIST:
netns.remove(NS_NAME)
netns.create(NS_NAME)
else:
raise
try:
check_output([NFT_BIN_PATH, "-f", "nftables.ruleset"])
except OSError as e:
if e.errno == errno.ENOENT:
raise SkipTest("You must install nftables for the test")
else:
raise
开发者ID:svinota,项目名称:pyroute2,代码行数:17,代码来源:test_nftables.py
示例17: test_create_tuntap
def test_create_tuntap(self):
# actually this test checks the nlsocket plugin feedback
# in a pair of remote client/server
foo = str(uuid4())
tun = uifname()
tap = uifname()
with IPDB(nl=NetNS(foo)) as ip:
ip.create(ifname=tun, kind='tuntap', mode='tun').commit()
ip.create(ifname=tap, kind='tuntap', mode='tap').commit()
assert tun in ip.interfaces.keys()
assert tap in ip.interfaces.keys()
ip.interfaces[tun].remove().commit()
ip.interfaces[tap].remove().commit()
assert tun not in ip.interfaces.keys()
assert tap not in ip.interfaces.keys()
netnsmod.remove(foo)
开发者ID:GateprotectGmbH,项目名称:pyroute2,代码行数:18,代码来源:test_netns.py
示例18: test_rename_plus_ipv6
def test_rename_plus_ipv6(self):
require_user('root')
mtu = 1280 # mtu must be >= 1280 if you plan to use IPv6
txqlen = 2000
nsid = str(uuid4())
ipdb_main = IPDB()
ipdb_test = IPDB(nl=NetNS(nsid))
if1 = uifname()
if2 = uifname()
if3 = uifname()
# create
ipdb_main.create(kind='veth',
ifname=if1,
peer=if2,
mtu=mtu,
txqlen=txqlen).commit()
# move
with ipdb_main.interfaces[if2] as veth:
veth.net_ns_fd = nsid
# set it up
with ipdb_test.interfaces[if2] as veth:
veth.add_ip('fdb3:84e5:4ff4:55e4::1/64')
veth.add_ip('fdff:ffff:ffff:ffc0::1/64')
veth.mtu = mtu
veth.txqlen = txqlen
veth.up()
veth.ifname = if3
veth = ipdb_test.interfaces.get(if3, None)
ipdb_main.release()
ipdb_test.release()
netnsmod.remove(nsid)
# check everything
assert ('fdb3:84e5:4ff4:55e4::1', 64) in veth.ipaddr
assert ('fdff:ffff:ffff:ffc0::1', 64) in veth.ipaddr
assert veth.flags & 1
assert veth.mtu == mtu
assert veth.txqlen == txqlen
开发者ID:craneworks,项目名称:pyroute2,代码行数:43,代码来源:test_netns.py
示例19: remove
def remove(self):
"""
Removes the virtual namespace and interface.
"""
Logger().debug("Delete Namespace ...", 2)
try:
if self.ipdb_netns is None:
netns.remove(self.nsp_name)
else:
self.ipdb_netns.interfaces[self.vlan_iface_name].nl.remove()
self.ipdb_netns.release()
Logger().debug("[+] Namespace(" + self.nsp_name + ") successfully deleted", 3)
except Exception as e:
if re.match("\[Errno 2\]*",str(e)):
Logger().debug("[+] Namespace(" + self.nsp_name + ") is already deleted", 3)
return
Logger().debug("[-] Namespace(" + self.nsp_name +
") couldn't be deleted. Try 'ip netns delete <namespace_name>'", 3)
Logger().error(str(e), 3)
开发者ID:freifunk-darmstadt,项目名称:TestFramework,代码行数:19,代码来源:namespace.py
示例20: test_pushns
def test_pushns(self):
require_user('root')
foo = str(uuid4())
ifA = uifname()
with IPRoute() as ipr:
ipr.link('add', ifname=ifA, kind='dummy')
netnsmod.pushns(foo)
with IPRoute() as ipr:
assert ifA not in [x.get_attr('IFLA_IFNAME') for x
in ipr.link('dump')]
netnsmod.popns()
with IPRoute() as ipr:
assert ifA in [x.get_attr('IFLA_IFNAME') for x
in ipr.link('dump')]
ipr.link('del', index=ipr.link_lookup(ifname=ifA)[0])
netnsmod.remove(foo)
开发者ID:svinota,项目名称:pyroute2,代码行数:20,代码来源:test_netns.py
注:本文中的pyroute2.netns.remove函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论