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


Python IPDB.watchdog方法代码示例

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


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

示例1: run

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import watchdog [as 别名]
    def run(self):
        logging.info('Started LinkNeg...')
        iface = self.get_mopt('iface')
        state = bool_it(self.get_mopt('state'))
        timeout = self.get_opt('timeout', default=10)

        ip = IPDB()
        self.oper_state = ip.interfaces[iface]['operstate']
        wd = ip.watchdog(ifname=iface)
        cuid = ip.register_callback(self._cb)

        wd.wait(timeout=timeout)
        ip.unregister_callback(cuid)
        ip.release()

        admin_state = 'UP' if state else 'DOWN'
        oper_state = self.oper_state
        res_data = {'admin_state': admin_state, 'oper_state': oper_state}

        if admin_state == oper_state:
            self.set_pass(res_data)
        else:
            self.set_fail(res_data)
开发者ID:aloughlam,项目名称:lnst,代码行数:25,代码来源:LinkNeg.py

示例2: TestExplicit

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

#.........这里部分代码省略.........
        require_user("root")

        ifA = self.get_ifname()
        ifB = self.get_ifname()
        self.ip.create(ifname=ifA, kind="dummy")
        self.ip.create(ifname=ifB, kind="dummy")
        self.ip.commit()

        assert ifA in self.ip.interfaces
        assert ifB in self.ip.interfaces
        assert grep("ip link", pattern=ifA)
        assert grep("ip link", pattern=ifB)

    def test_global_priorities(self):
        require_user("root")
        ifA = self.get_ifname()
        ifB = self.get_ifname()
        ifC = self.get_ifname()
        a = self.ip.create(ifname=ifA, kind="dummy").commit()
        #
        if a._mode == "explicit":
            a.begin()

        # prepare transaction: two interface creations
        # and one failure on an existing interface
        a.set_address("11:22:33:44:55:66")
        b = self.ip.create(ifname=ifB, kind="dummy")
        c = self.ip.create(ifname=ifC, kind="dummy")
        # now assign priorities
        b.ipdb_priority = 15  # will be execute first
        a.ipdb_priority = 10  # second -- and fail
        c.ipdb_priority = 5  # should not be executed
        # prepare watchdogs
        wdb = self.ip.watchdog(ifname=ifB)
        wdc = self.ip.watchdog(ifname=ifC)
        # run the transaction
        try:
            self.ip.commit()
        except NetlinkError:
            pass
        # control system state
        assert ifA in self.ip.interfaces
        assert ifB in self.ip.interfaces
        assert ifC in self.ip.interfaces
        assert a.ipdb_scope == "system"
        assert b.ipdb_scope == "create"
        assert c.ipdb_scope == "create"
        assert a.address != "11:22:33:44:55:66"
        assert grep("ip link", pattern=ifA)
        assert not grep("ip link", pattern=ifB)
        assert not grep("ip link", pattern=ifC)
        wdb.wait(1)
        wdc.wait(1)
        assert wdb.is_set
        assert not wdc.is_set

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

        ifA = self.get_ifname()
        ifB = self.get_ifname()
        a = self.ip.create(ifname=ifA, kind="dummy").commit()
        #
        if a._mode == "explicit":
            a.begin()
        a.remove()
开发者ID:abn,项目名称:pyroute2,代码行数:70,代码来源:test_ipdb.py

示例3: IPDB

# 需要导入模块: from pyroute2 import IPDB [as 别名]
# 或者: from pyroute2.IPDB import watchdog [as 别名]
    if action == 'RTM_NEWLINK' and \
            msg.get_attr('IFLA_IFNAME', '').startswith('bala_port'):
        # get corresponding interface -- in the case of
        # post-callbacks it is created already
        interface = ipdb.interfaces[msg['index']]
        # add it as a port to the bridge
        ipdb.interfaces.br0.add_port(interface)
        try:
            ipdb.interfaces.br0.commit()
        except Exception:
            pass

# create IPDB instance
ip = IPDB()
# create watchdogs
wd0 = ip.watchdog(ifname='br0')
wd1 = ip.watchdog(ifname='bala_port0')
wd2 = ip.watchdog(ifname='bala_port1')
# create bridge
ip.create(kind='bridge', ifname='br0').commit()
# wait the bridge to be created
wd0.wait()
# register callback
ip.register_callback(cb)
# create ports
ip.create(kind='dummy', ifname='bala_port0').commit()
ip.create(kind='dummy', ifname='bala_port1').commit()
# sleep for interfaces
wd1.wait()
wd2.wait()
开发者ID:0x90,项目名称:pyroute2,代码行数:32,代码来源:ipdb_autobr.py

示例4: TestExplicit

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

#.........这里部分代码省略.........
        require_user('root')

        ifA = self.get_ifname()
        ifB = self.get_ifname()
        self.ip.create(ifname=ifA, kind='dummy')
        self.ip.create(ifname=ifB, kind='dummy')
        self.ip.commit()

        assert ifA in self.ip.interfaces
        assert ifB in self.ip.interfaces
        assert grep('ip link', pattern=ifA)
        assert grep('ip link', pattern=ifB)

    def test_global_priorities(self):
        require_user('root')
        ifA = self.get_ifname()
        ifB = self.get_ifname()
        ifC = self.get_ifname()
        a = self.ip.create(ifname=ifA, kind='dummy').commit()
        #
        if a._mode == 'explicit':
            a.begin()

        # prepare transaction: two interface creations
        # and one failure on an existing interface
        a.set_address('11:22:33:44:55:66')
        b = self.ip.create(ifname=ifB, kind='dummy')
        c = self.ip.create(ifname=ifC, kind='dummy')
        # now assign priorities
        b.ipdb_priority = 15  # will be execute first
        a.ipdb_priority = 10  # second -- and fail
        c.ipdb_priority = 5   # should not be executed
        # prepare watchdogs
        wdb = self.ip.watchdog(ifname=ifB)
        wdc = self.ip.watchdog(ifname=ifC)
        # run the transaction
        try:
            self.ip.commit()
        except NetlinkError:
            pass
        # control system state
        assert ifA in self.ip.interfaces
        assert ifB in self.ip.interfaces
        assert ifC in self.ip.interfaces
        assert a.ipdb_scope == 'system'
        assert b.ipdb_scope == 'create'
        assert c.ipdb_scope == 'create'
        assert a.address != '11:22:33:44:55:66'
        assert grep('ip link', pattern=ifA)
        assert not grep('ip link', pattern=ifB)
        assert not grep('ip link', pattern=ifC)
        wdb.wait(1)
        wdc.wait(1)
        assert wdb.is_set
        assert not wdc.is_set

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

        ifA = self.get_ifname()
        ifB = self.get_ifname()
        self.ip.create(ifname=ifA, peer=ifB, kind='veth')
        self.ip.commit()

        assert self.ip.interfaces[ifA]['ipdb_scope'] == 'system'
        assert self.ip.interfaces[ifB]['ipdb_scope'] == 'system'
开发者ID:thezeep,项目名称:pyroute2,代码行数:70,代码来源:test_ipdb.py


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