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


Python IPDB.commit方法代码示例

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


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

示例1: test_vrouter

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import commit [as 别名]
    def test_vrouter(self):
        require_user('root')
        nsid = str(uuid.uuid4())
        ns = NetNS(nsid)
        ipdb = IPDB()
        ipns = IPDB(nl=ns)
        try:
            ipdb.create(ifname='ve0p0', peer='ve0p1', kind='veth').commit()
            ipdb.interfaces.ve0p1.net_ns_fd = nsid
            ipdb.commit()

            with ipns.interfaces.ve0p1 as i:
                i.set_ifname('eth0')
                i.up()

        except:
            raise
        finally:
            ipdb.interfaces.ve0p0.remove()
            ipdb.commit()
            ipdb.release()
            ipns.release()
            ns.remove()
开发者ID:0xD3ADB33F,项目名称:pyroute2,代码行数:25,代码来源:test_eventlet.py

示例2: TestExplicit

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import commit [as 别名]

#.........这里部分代码省略.........

    def test_reprs(self):
        assert isinstance(repr(self.ip.interfaces.lo.ipaddr), basestring)
        assert isinstance(repr(self.ip.interfaces.lo), basestring)

    def test_dotkeys(self):
        # self.ip.lo hint for ipython
        assert "lo" in dir(self.ip.interfaces)
        assert "lo" in self.ip.interfaces
        assert self.ip.interfaces.lo == self.ip.interfaces["lo"]
        # create attribute
        self.ip.interfaces["newitem"] = True
        self.ip.interfaces.newattr = True
        self.ip.interfaces.newitem = None
        assert self.ip.interfaces.newitem == self.ip.interfaces["newitem"]
        assert self.ip.interfaces.newitem is None
        # delete attribute
        del self.ip.interfaces.newitem
        del self.ip.interfaces.newattr
        assert "newattr" not in dir(self.ip.interfaces)
        # test hasattr protocol
        assert hasattr(self.ip.interfaces, "nonexistinginterface") is False

    @skip_if_not_supported
    def test_vlan_slave_bridge(self):
        # https://github.com/svinota/pyroute2/issues/58
        # based on the code by Petr Horáček
        dXname = self.get_ifname()
        vXname = self.get_ifname()
        vYname = self.get_ifname()
        brname = self.get_ifname()

        require_user("root")
        dX = self.ip.create(ifname=dXname, kind="dummy").commit()
        vX = self.ip.create(ifname=vXname, kind="vlan", link=dX, vlan_id=101).commit()
        vY = self.ip.create(ifname=vYname, kind="vlan", link=dX, vlan_id=102).commit()
        with self.ip.create(ifname=brname, kind="bridge") as i:
            i.add_port(vX)
            i.add_port(vY["index"])

        assert vX["index"] in self.ip.interfaces[brname]["ports"]
        assert vY["index"] in self.ip.interfaces[brname].ports
        assert vX["link"] == dX["index"]
        assert vY["link"] == dX["index"]
        assert vX["master"] == self.ip.interfaces[brname]["index"]
        assert vY["master"] == self.ip.interfaces[brname].index

    def _test_commit_hook_positive(self):
        require_user("root")

        # test callback, that adds an address by itself --
        # just to check the possibility
        def cb(interface, snapshot, transaction):
            self.ip.nl.addr("add", self.ip.interfaces[self.ifd].index, address="172.16.22.1", mask=24)

        # register callback and check CB chain length
        self.ip.interfaces[self.ifd].register_commit_hook(cb)
        assert len(self.ip.interfaces[self.ifd]._commit_hooks) == 1

        # create a transaction and commit it
        if self.ip.interfaces[self.ifd]._mode == "explicit":
            self.ip.interfaces[self.ifd].begin()
        self.ip.interfaces[self.ifd].add_ip("172.16.21.1/24")
        self.ip.interfaces[self.ifd].commit()

        # added address should be there
开发者ID:abn,项目名称:pyroute2,代码行数:70,代码来源:test_ipdb.py

示例3: TestExplicit

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import commit [as 别名]

#.........这里部分代码省略.........
            assert len(self.ip.interfaces[name]['ipaddr']) == \
                len(get_ip_addr(name))

    def test_reprs(self):
        assert isinstance(repr(self.ip.interfaces.lo.ipaddr), basestring)
        assert isinstance(repr(self.ip.interfaces.lo), basestring)

    def test_dotkeys(self):
        # self.ip.lo hint for ipython
        assert 'lo' in dir(self.ip.interfaces)
        assert 'lo' in self.ip.interfaces
        assert self.ip.interfaces.lo == self.ip.interfaces['lo']
        # create attribute
        self.ip.interfaces['newitem'] = True
        self.ip.interfaces.newattr = True
        self.ip.interfaces.newitem = None
        assert self.ip.interfaces.newitem == self.ip.interfaces['newitem']
        assert self.ip.interfaces.newitem is None
        # delete attribute
        del self.ip.interfaces.newitem
        del self.ip.interfaces.newattr
        assert 'newattr' not in dir(self.ip.interfaces)

    @skip_if_not_supported
    def test_vlan_slave_bridge(self):
        # https://github.com/svinota/pyroute2/issues/58
        # based on the code by Petr Horáček
        dXname = self.get_ifname()
        vXname = self.get_ifname()
        vYname = self.get_ifname()
        brname = self.get_ifname()

        require_user('root')
        dX = self.ip.create(ifname=dXname, kind='dummy').commit()
        vX = self.ip.create(ifname=vXname, kind='vlan',
                            link=dX, vlan_id=101).commit()
        vY = self.ip.create(ifname=vYname, kind='vlan',
                            link=dX, vlan_id=102).commit()
        with self.ip.create(ifname=brname, kind='bridge') as i:
            i.add_port(vX)
            i.add_port(vY['index'])

        assert vX['index'] in self.ip.interfaces[brname]['ports']
        assert vY['index'] in self.ip.interfaces[brname].ports
        assert vX['link'] == dX['index']
        assert vY['link'] == dX['index']
        assert vX['master'] == self.ip.interfaces[brname]['index']
        assert vY['master'] == self.ip.interfaces[brname].index

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

        # test callback, that adds an address by itself --
        # just to check the possibility
        def cb(interface, snapshot, transaction):
            self.ip.nl.addr('add',
                            self.ip.interfaces[self.ifd].index,
                            address='172.16.22.1',
                            mask=24)

        # register callback and check CB chain length
        self.ip.interfaces[self.ifd].register_commit_hook(cb)
        assert len(self.ip.interfaces[self.ifd]._commit_hooks) == 1

        # create a transaction and commit it
        if self.ip.interfaces[self.ifd]._mode == 'explicit':
开发者ID:thezeep,项目名称:pyroute2,代码行数:70,代码来源:test_ipdb.py


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