当前位置: 首页>>代码示例>>Python>>正文


Python IPDB.release方法代码示例

本文整理汇总了Python中pyroute2.IPDB.release方法的典型用法代码示例。如果您正苦于以下问题:Python IPDB.release方法的具体用法?Python IPDB.release怎么用?Python IPDB.release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyroute2.IPDB的用法示例。


在下文中一共展示了IPDB.release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_fail_released

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
 def test_fail_released(self):
     ip = IPDB()
     ip.release()
     try:
         ip.interfaces.lo.up()
     except RuntimeError:
         pass
开发者ID:0x90,项目名称:pyroute2,代码行数:9,代码来源:test_ipdb.py

示例2: test_dummy0_unloaded

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
 def test_dummy0_unloaded(object):
     require_user('root')
     # firstly unload the dummy module
     with open(os.devnull, 'w') as fnull:
         subprocess.call(['modprobe', '-r', 'dummy'],
                         stdout=fnull,
                         stderr=fnull)
     ip = None
     try:
         # now create the dummy0 -- it will cause the
         # module autoload
         ip = IPDB()
         # that must succeed
         ip.create(ifname='dummy0', kind='dummy').commit()
         # just in case: the second attempt must fail on the
         # create() stage, even w/o any commit()
         try:
             ip.create(ifname='dummy0', kind='dummy')
         except CreateException:
             pass
     except Exception:
         raise
     finally:
         if ip is not None:
             ip.release()
开发者ID:thezeep,项目名称:pyroute2,代码行数:27,代码来源:test_ipdb.py

示例3: test_create_vxlan

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
    def test_create_vxlan(self):
        require_user('root')

        ifL = self.get_ifname()
        ifV = self.get_ifname()
        ifdb = self.ip.interfaces

        self.ip.create(kind='dummy',
                       ifname=ifL).commit()
        self.ip.create(kind='vxlan',
                       ifname=ifV,
                       vxlan_link=ifdb[ifL],
                       vxlan_id=101,
                       vxlan_group='239.1.1.1').commit()

        ip2 = IPDB()
        ifdb = ip2.interfaces

        try:
            assert ifdb[ifV].vxlan_link == ifdb[ifL].index
            assert ifdb[ifV].vxlan_group == '239.1.1.1'
            assert ifdb[ifV].vxlan_id == 101
        except Exception:
            raise
        finally:
            ip2.release()
开发者ID:0x90,项目名称:pyroute2,代码行数:28,代码来源:test_ipdb.py

示例4: initContainerNetwork

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
 def initContainerNetwork(self, network=None):
     if not network:
         try:
             network = Network(None)
             network.name = 'cygnet_internal'
             network.address = self['internal_ip']
             if not self.ovs_client.bridgeExists(network.name):
                 self.ovs_client.addBridge(network.name)
                 self.ovs_client.setBridgeProperty(network.name,
                                                   'stp_enable',
                                                   True)
         except KeyError as e:
             print("OpenvSwitch: CYGNET_INTERNAL_IP \
                     environment variable not found")
             raise e
     else:
         network.name = "cygnet_" + network.id[:8]
         if not self.ovs_client.bridgeExists(network.name):
             self.ovs_client.addBridge(network.name)
             self.ovs_client.setBridgeProperty(network.name,
                                               'stp_enable',
                                               True)
     ip = IPDB()
     ifaces = ip.interfaces
     ifaces[network.name].begin()
     ifaces[network.name].add_ip(network.address, network.mask)
     ifaces[network.name].up()
     ifaces[network.name].commit()
     ip.release()
     self.interfaces.append(network)
     return network
开发者ID:SaadTalaat,项目名称:cygnet-common,代码行数:33,代码来源:interfaces.py

示例5: __ovs_setup

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
    def __ovs_setup(self):
        if not self.ovs_client.bridgeExists('cygnet0'):
            self.ovs_client.addBridge('cygnet0')
            self.ovs_client.addPort('cygnet0', self.external_iface)
        elif not self.ovs_client.portExists(self.external_iface):
            self.ovs_client.addPort('cygnet0', self.external_iface)
        ip = IPDB()
        ifaces = ip.interfaces
        ifaces.cygnet0.begin()
        addrs= ip.interfaces[self.external_iface].ipaddr.raw
        addr = None
        for address, attrs in addrs.items():
            if __getIPv4Addr__([address]) == None:
                continue
            addr = address
        ifaces.cygnet0.add_ip(addr[0], int(addr[1]))
        ifaces.cygnet0.up()
        ifaces.cygnet0.commit()
        ifaces[self.external_iface].begin()
        ifaces[self.external_iface].down()
        ifaces[self.external_iface].commit()

        ifaces[self.external_iface].begin()
        ifaces[self.external_iface].up()
        ifaces[self.external_iface].commit()

        ip.release()
开发者ID:SaadTalaat,项目名称:cygnet-common,代码行数:29,代码来源:interfaces.py

示例6: test_create_gretap

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
    def test_create_gretap(self):
        require_user('root')

        ifL = self.get_ifname()
        ifV = self.get_ifname()
        with self.ip.create(kind='dummy', ifname=ifL) as i:
            i.add_ip('172.16.0.1/24')
            i.up()

        self.ip.create(kind='gretap',
                       ifname=ifV,
                       gre_local='172.16.0.1',
                       gre_ikey=1,
                       gre_okey=2,
                       gre_iflags=0x0020,
                       gre_oflags=0x0020,
                       gre_collect_metadata=True,
                       gre_ttl=16).commit()

        ip2 = IPDB()
        ifdb = ip2.interfaces
        try:
            assert ifdb[ifV].gre_local == '172.16.0.1'
            assert ifdb[ifV].gre_ikey == 1
            assert ifdb[ifV].gre_okey == 2
            assert ifdb[ifV].gre_iflags == 0x0020
            assert ifdb[ifV].gre_oflags == 0x0020
            if kernel_version_ge(4, 3):
                assert ifdb[ifV].gre_collect_metadata
            assert ifdb[ifV].gre_ttl == 16
        except Exception:
            raise
        finally:
            ip2.release()
开发者ID:linzhonghong,项目名称:pyroute2,代码行数:36,代码来源:test_ipdb.py

示例7: test_commit_barrier

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
    def test_commit_barrier(self):
        require_user("root")

        ifname = uifname()

        # barrier 0
        try:
            ip = IPDB()
            config.commit_barrier = 0
            ts1 = time.time()
            ip.create(ifname=ifname, kind="dummy").commit()
            ts2 = time.time()
            assert 0 < (ts2 - ts1) < 1
        except:
            raise
        finally:
            config.commit_barrier = 0.2
            ip.interfaces[ifname].remove().commit()
            ip.release()

        # barrier 5
        try:
            ip = IPDB()
            config.commit_barrier = 5
            ts1 = time.time()
            ip.create(ifname=ifname, kind="dummy").commit()
            ts2 = time.time()
            assert 5 < (ts2 - ts1) < 6
        except:
            raise
        finally:
            config.commit_barrier = 0.2
            ip.interfaces[ifname].remove().commit()
            ip.release()
开发者ID:abn,项目名称:pyroute2,代码行数:36,代码来源:test_ipdb.py

示例8: test_move_ns_pid

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
    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,代码行数:31,代码来源:test_netns.py

示例9: test_create_gre

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
    def test_create_gre(self):
        require_user('root')

        ifL = self.get_ifname()
        ifV = self.get_ifname()
        with self.ip.create(kind='dummy', ifname=ifL) as i:
            i.add_ip('172.16.0.1/24')
            i.up()

        self.ip.create(kind='gre',
                       ifname=ifV,
                       gre_local='172.16.0.1',
                       gre_remote='172.16.0.2',
                       gre_ttl=16).commit()

        ip2 = IPDB()
        ifdb = ip2.interfaces
        try:
            assert ifdb[ifV].gre_local == '172.16.0.1'
            assert ifdb[ifV].gre_remote == '172.16.0.2'
            assert ifdb[ifV].gre_ttl == 16
        except Exception:
            raise
        finally:
            ip2.release()
开发者ID:0x90,项目名称:pyroute2,代码行数:27,代码来源:test_ipdb.py

示例10: TestDirect

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
class TestDirect(object):

    def setup(self):
        self.ifname = uifname()
        self.ip = IPDB(mode='direct')
        try:
            self.ip.create(ifname=self.ifname, kind='dummy')
        except:
            pass

    def teardown(self):
        try:
            self.ip.interfaces[self.ifname].remove()
        except KeyError:
            pass
        self.ip.release()

    def test_context_fail(self):
        require_user('root')
        try:
            with self.ip.interfaces[self.ifname] as i:
                i.down()
        except TypeError:
            pass

    def test_create(self):
        require_user('root')
        ifname = uifname()
        assert ifname not in self.ip.interfaces
        self.ip.create(ifname=ifname, kind='dummy')
        assert ifname in self.ip.interfaces
        self.ip.interfaces[ifname].remove()
        assert ifname not in self.ip.interfaces

    def test_updown(self):
        require_user('root')

        assert not (self.ip.interfaces[self.ifname].flags & 1)
        self.ip.interfaces[self.ifname].up()

        assert self.ip.interfaces[self.ifname].flags & 1
        self.ip.interfaces[self.ifname].down()

        assert not (self.ip.interfaces[self.ifname].flags & 1)

    def test_exceptions_last(self):
        try:
            self.ip.interfaces.lo.last()
        except TypeError:
            pass

    def test_exception_review(self):
        try:
            self.ip.interfaces.lo.review()
        except TypeError:
            pass
开发者ID:thezeep,项目名称:pyroute2,代码行数:58,代码来源:test_ipdb.py

示例11: destroyInterface

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
	def destroyInterface(self):
		ipdb = IPDB()

		with ipdb.interfaces[self.bridge_iface] as i:
			i.del_port(ipdb.interfaces[self.veth0])

		with ipdb.interfaces[self.veth0] as i:
			i.remove()

		ipdb.release()
开发者ID:Zaynullin,项目名称:sensors,代码行数:12,代码来源:NetworkNamespace.py

示例12: test_ipdb

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
 def test_ipdb(self):
     require_user('root')
     ip = IPDB()
     try:
         assert ip._nl_async is False
         assert len(ip.interfaces.keys()) > 1
     except:
         raise
     finally:
         ip.release()
开发者ID:0xD3ADB33F,项目名称:pyroute2,代码行数:12,代码来源:test_eventlet.py

示例13: deleteService

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
def deleteService(name, terminalName):
    if_svc_name = name
    if_terminal_name = name + '_' + terminalName
    ip_host = IPDB()
    with ip_host.interfaces[if_terminal_name] as veth:
        veth.remove()
    ip_host.release()
    subprocess.call(["ovs-vsctl", "del-port", "vs-" + name, if_svc_name])
    subprocess.call(["ovs-vsctl", "del-port", "br0", if_terminal_name])
    subprocess.call(["ovs-vsctl", "del-br", "vs-" + name])
    return json.dumps({ 'status' : 'deleted service'})
开发者ID:michaelhenkel,项目名称:tcc,代码行数:13,代码来源:terminalServer.py

示例14: _TestDhcpClient

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
class _TestDhcpClient(object):

    def setup(self):
        require_user('root')
        require_executable('busybox')
        self.ip = IPDB()
        # create internal network
        self.if1 = uifname()
        self.if2 = uifname()
        self.ip.create(kind='veth', ifname=self.if1, peer=self.if2).commit()
        # set interfaces up
        with self.ip.interfaces[self.if1] as i:
            i.add_ip('172.16.101.1/24')
            i.up()

        with self.ip.interfaces[self.if2] as i:
            i.up()
        # prepare configuration for udhcpd
        with open('udhcpd.conf.in', 'r') as conf_in:
            with open('udhcpd.conf', 'w') as conf_out:
                conf_out.write('interface %s\n' % self.if1)
                conf_out.write(conf_in.read())
        # run busybox dhcp server on $if1
        with open(os.devnull, 'w') as fnull:
            subprocess.check_call(['busybox', 'udhcpd', 'udhcpd.conf'],
                                  stdout=fnull,
                                  stderr=fnull)

    def teardown(self):
        # read pid from file and kill the server
        with open('udhcpd.pid', 'r') as pid_file:
            pid = int(pid_file.read())
            os.kill(pid, 15)
        # teardown interfaces (enough to remove only master)
        self.ip.interfaces[self.if1].remove().commit()
        # release IPDB
        self.ip.release()
        # remove configuration file
        os.unlink('udhcpd.conf')
        # collect garbage
        gc.collect()

    def test_defaults(self):
        msg = dhclient.action(self.if2)
        assert msg['yiaddr'].startswith('172.16.101.')
        assert msg['op'] == BOOTREPLY
        assert msg['options']['message_type'] == DHCPACK
        assert msg['options']['router'] == ['172.16.101.1']
        assert msg['options']['server_id'] == '172.16.101.1'
        assert msg['options']['subnet_mask'] == '255.255.255.0'
        assert set(msg['options']['name_server']) ==\
            set(('172.16.101.1', '172.16.101.2'))
开发者ID:celebdor,项目名称:pyroute2,代码行数:54,代码来源:test_dhcp.py

示例15: initalize

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import release [as 别名]
 def initalize(self):
     ip = IPDB()
     try:
         # Check if public interface is up
         self.addr = __getIPv4Addr__(list(ip.interfaces.br1.ipaddr))
         self.addr = self.addr[0], str(self.addr[1])
         self.interfaces.append(('br1', self.addr))
     except Exception as e:
         print(e)
     finally:
         ip.release()
     self.range_buckets[int(self.addr[0].split(".")[-1])] = 1
     return self.addr
开发者ID:Cygnus-Inc,项目名称:cygnet-common,代码行数:15,代码来源:interfaces.py


注:本文中的pyroute2.IPDB.release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。