本文整理汇总了Python中pyroute2.common.AddrPool.locate方法的典型用法代码示例。如果您正苦于以下问题:Python AddrPool.locate方法的具体用法?Python AddrPool.locate怎么用?Python AddrPool.locate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyroute2.common.AddrPool
的用法示例。
在下文中一共展示了AddrPool.locate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_locate
# 需要导入模块: from pyroute2.common import AddrPool [as 别名]
# 或者: from pyroute2.common.AddrPool import locate [as 别名]
def test_locate(self):
ap = AddrPool()
f = ap.alloc()
base1, bit1, is_allocated1 = ap.locate(f)
base2, bit2, is_allocated2 = ap.locate(f + 1)
assert base1 == base2
assert bit2 == bit1 + 1
assert is_allocated1
assert not is_allocated2
assert ap.allocated == 1
示例2: test_setaddr_allocated
# 需要导入模块: from pyroute2.common import AddrPool [as 别名]
# 或者: from pyroute2.common.AddrPool import locate [as 别名]
def test_setaddr_allocated(self):
ap = AddrPool()
f = ap.alloc()
base, bit, is_allocated = ap.locate(f + 1)
assert not is_allocated
assert ap.allocated == 1
ap.setaddr(f + 1, 'allocated')
base, bit, is_allocated = ap.locate(f + 1)
assert is_allocated
assert ap.allocated == 2
ap.free(f + 1)
base, bit, is_allocated = ap.locate(f + 1)
assert not is_allocated
assert ap.allocated == 1
示例3: test_setaddr_free
# 需要导入模块: from pyroute2.common import AddrPool [as 别名]
# 或者: from pyroute2.common.AddrPool import locate [as 别名]
def test_setaddr_free(self):
ap = AddrPool()
f = ap.alloc()
base, bit, is_allocated = ap.locate(f + 1)
assert not is_allocated
assert ap.allocated == 1
ap.setaddr(f + 1, 'free')
base, bit, is_allocated = ap.locate(f + 1)
assert not is_allocated
assert ap.allocated == 1
ap.setaddr(f, 'free')
base, bit, is_allocated = ap.locate(f)
assert not is_allocated
assert ap.allocated == 0
try:
ap.free(f)
except KeyError:
pass