本文整理汇总了Python中pynipap.Prefix.smart_search方法的典型用法代码示例。如果您正苦于以下问题:Python Prefix.smart_search方法的具体用法?Python Prefix.smart_search怎么用?Python Prefix.smart_search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynipap.Prefix
的用法示例。
在下文中一共展示了Prefix.smart_search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stats5
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_stats5(self):
""" Add prefixes within other prefix and verify parent prefix has correct statistics
"""
th = TestHelper()
# add a top level prefix
p1 = th.add_prefix('1.0.0.0/24', 'assignment', 'test')
# check stats for p1
res = Prefix.smart_search('1.0.0.0/24', {})
self.assertEqual(256, res['result'][0].total_addresses)
self.assertEqual(0, res['result'][0].used_addresses)
self.assertEqual(256, res['result'][0].free_addresses)
# add a host in our top prefix
p2 = th.add_prefix('1.0.0.1/32', 'host', 'bar')
# check stats for p1, our top level prefix
res = Prefix.smart_search('1.0.0.0/24', {})
self.assertEqual(256, res['result'][0].total_addresses)
self.assertEqual(1, res['result'][0].used_addresses)
self.assertEqual(255, res['result'][0].free_addresses)
# check stats for p2, our new host prefix
res = Prefix.smart_search('1.0.0.1/32', {})
self.assertEqual(1, res['result'][0].total_addresses)
self.assertEqual(1, res['result'][0].used_addresses)
self.assertEqual(0, res['result'][0].free_addresses)
示例2: test_stats7
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_stats7(self):
""" Enlarge / shrink prefix over several indent levels
"""
th = TestHelper()
# p1 children are p2 (which covers p3 and p4) and p5
p1 = th.add_prefix('1.0.0.0/16', 'reservation', 'test')
p2 = th.add_prefix('1.0.0.0/22', 'reservation', 'test')
p3 = th.add_prefix('1.0.0.0/23', 'reservation', 'FOO')
p4 = th.add_prefix('1.0.0.0/24', 'reservation', 'test')
p5 = th.add_prefix('1.0.1.0/24', 'reservation', 'test')
p6 = th.add_prefix('1.0.2.0/24', 'reservation', 'test')
p7 = th.add_prefix('1.0.3.0/24', 'reservation', 'test')
# enlarge p3 so that it covers p2, ie moved up several indent levels
p3.prefix = '1.0.0.0/21'
p3.save()
# check stats for p3
res = Prefix.smart_search('1.0.0.0/21', {})
self.assertEqual(2048, res['result'][0].total_addresses)
self.assertEqual(1024, res['result'][0].used_addresses)
self.assertEqual(1024, res['result'][0].free_addresses)
# move back p3
p3.prefix = '1.0.0.0/23'
p3.save()
# check stats for p3
res = Prefix.smart_search('1.0.0.0/23', {})
self.assertEqual(512, res['result'][0].total_addresses)
self.assertEqual(512, res['result'][0].used_addresses)
self.assertEqual(0, res['result'][0].free_addresses)
示例3: test_children8
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_children8(self):
""" Remove prefix and check old parent is correctly updated
"""
th = TestHelper()
# p1 children are p2 (which covers p3 and p4) and p5
p1 = th.add_prefix('1.0.0.0/20', 'reservation', 'test')
p2 = th.add_prefix('1.0.0.0/22', 'reservation', 'test')
p3 = th.add_prefix('1.0.0.0/24', 'reservation', 'test')
p4 = th.add_prefix('1.0.1.0/24', 'reservation', 'test')
p5 = th.add_prefix('1.0.7.0/24', 'reservation', 'test')
# moving p2 means that p1 get p3, p4 and p5 as children
p2.prefix = '2.0.0.0/22'
p2.save()
# check stats for p1
res = Prefix.smart_search('1.0.0.0/20', {})
self.assertEqual(3, res['result'][0].children)
# moving back p2 which means that p1 get p2 and p5 as children
p2.prefix = '1.0.0.0/22'
p2.save()
# check stats for p1
res = Prefix.smart_search('1.0.0.0/20', {})
self.assertEqual(2, res['result'][0].children)
示例4: test_children9
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_children9(self):
""" Move prefix several indent steps and check children is correct
"""
th = TestHelper()
# tree of prefixes
p1 = th.add_prefix('1.0.0.0/20', 'reservation', 'test')
p2 = th.add_prefix('1.0.0.0/21', 'reservation', 'test')
p3 = th.add_prefix('1.0.0.0/22', 'reservation', 'test')
p4 = th.add_prefix('1.0.0.0/23', 'reservation', 'test')
p5 = th.add_prefix('1.0.0.0/24', 'reservation', 'test')
p6 = th.add_prefix('1.0.2.0/24', 'reservation', 'test')
p7 = th.add_prefix('1.0.4.0/22', 'reservation', 'test')
# check stats for p2
res = Prefix.smart_search('1.0.0.0/21', {})
self.assertEqual(2, res['result'][0].children)
# move p3 outside of the tree
p3.prefix = '2.0.0.0/22'
p3.save()
# check stats for p2
res = Prefix.smart_search('1.0.0.0/21', {})
self.assertEqual(3, res['result'][0].children)
# move p3 into the tree again
p3.prefix = '1.0.0.0/22'
p3.save()
# check stats for p2
res = Prefix.smart_search('1.0.0.0/21', {})
self.assertEqual(2, res['result'][0].children)
示例5: test_tags1
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_tags1(self):
""" Verify tags are correctly inherited
"""
th = TestHelper()
# add to "top level" prefix, each with a unique tag
p1 = th.add_prefix('1.0.0.0/8', 'reservation', 'test', tags=['a'])
p2 = th.add_prefix('1.0.0.0/9', 'reservation', 'test')
p3 = th.add_prefix('1.0.0.0/10', 'reservation', 'test')
# p3 should have inherited_tags = ['a'] from p1
res = Prefix.smart_search('1.0.0.0/10', {})
self.assertEqual(['a'], res['result'][0].inherited_tags.keys())
p4 = th.add_prefix('1.0.0.0/24', 'reservation', 'test')
p5 = th.add_prefix('1.0.0.0/23', 'reservation', 'test')
p6 = th.add_prefix('1.0.0.0/22', 'reservation', 'test')
# p4 should have inherited_tags = ['a'] from p1
res = Prefix.smart_search('1.0.0.0/24', {})
self.assertEqual(['a'], res['result'][0].inherited_tags.keys())
# change tags on top level prefix
p1.tags = ['b']
p1.save()
# p4 should have inherited_tags = ['a'] from p1
res = Prefix.smart_search('1.0.0.0/8', {})
self.assertEqual([], res['result'][0].inherited_tags.keys())
self.assertEqual(['b'], res['result'][1].inherited_tags.keys())
self.assertEqual(['b'], res['result'][2].inherited_tags.keys())
self.assertEqual(['b'], res['result'][3].inherited_tags.keys())
self.assertEqual(['b'], res['result'][4].inherited_tags.keys())
self.assertEqual(['b'], res['result'][5].inherited_tags.keys())
示例6: test_stats3
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_stats3(self):
""" Check stats are correct when shrinking prefix
"""
th = TestHelper()
# add a top level prefix
p1 = th.add_prefix('1.0.0.0/24', 'assignment', 'test')
p2 = th.add_prefix('1.0.7.0/24', 'assignment', 'test')
# add a covering supernet around p1 and p2
p3 = th.add_prefix('1.0.0.0/21', 'reservation', 'bar')
# check that p3 looks good
res = Prefix.smart_search('1.0.0.0/21', {})
self.assertEqual(2048, res['result'][0].total_addresses)
self.assertEqual(512, res['result'][0].used_addresses)
self.assertEqual(1536, res['result'][0].free_addresses)
# now move our supernet, so we see that the update thingy works
p3.prefix = '1.0.0.0/22'
p3.save()
# check that p3 only covers p1
res = Prefix.smart_search('1.0.0.0/22', {})
self.assertEqual(1024, res['result'][0].total_addresses)
self.assertEqual(256, res['result'][0].used_addresses)
self.assertEqual(768, res['result'][0].free_addresses)
示例7: test_prefix_edit
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_prefix_edit(self):
""" Verify indent is correct after prefix edit
"""
th = TestHelper()
# add a few prefixes
p1 = th.add_prefix('192.168.0.0/16', 'reservation', 'test')
p2 = th.add_prefix('192.168.0.0/24', 'reservation', 'test')
p3 = th.add_prefix('192.168.1.0/24', 'reservation', 'test')
# now edit the "middle prefix" so that it now covers 192.168.1.0/24
p3.prefix = '192.168.0.0/20'
p3.save()
expected = []
# expected result is a list of list, each row is a prefix, first value is prefix, next is indent level
# notice how p2 and p3 switch places efter the edit
expected.append([p1.prefix, 0])
expected.append([p3.prefix, 1])
expected.append([p2.prefix, 2])
res = Prefix.smart_search('0.0.0.0/0', {})
result = []
for prefix in res['result']:
result.append([prefix.prefix, prefix.indent])
self.assertEqual(expected, result)
示例8: test_children3
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_children3(self):
""" Check children are correct when adding prefix
"""
th = TestHelper()
# add a top level prefix
p1 = th.add_prefix('1.0.0.0/24', 'assignment', 'test')
# check stats for p1
res = Prefix.smart_search('1.0.0.0/24', {})
self.assertEqual(0, res['result'][0].children)
# add a covering supernet around p1
p2 = th.add_prefix('1.0.0.0/20', 'reservation', 'bar')
# check stats for p2, our new top level prefix
res = Prefix.smart_search('1.0.0.0/20', {})
self.assertEqual(1, res['result'][0].children)
示例9: test_children4
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_children4(self):
""" Check children are correct when enlarging prefix
"""
th = TestHelper()
# add a top level prefix
p1 = th.add_prefix('1.0.0.0/24', 'assignment', 'test')
p2 = th.add_prefix('1.0.7.0/24', 'assignment', 'test')
# add a covering supernet around p1
p3 = th.add_prefix('1.0.0.0/22', 'reservation', 'bar')
# check that p3 looks good
res = Prefix.smart_search('1.0.0.0/22', {})
self.assertEqual(1, res['result'][0].children)
# now move our supernet, so we see that the update thingy works
p3.prefix = '1.0.0.0/21'
p3.save()
# check stats for p2, our new top level prefix
res = Prefix.smart_search('1.0.0.0/21', {})
self.assertEqual(2, res['result'][0].children)
示例10: test_stats1
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_stats1(self):
""" Check stats are correct when adding prefix
"""
th = TestHelper()
# add a top level prefix
p1 = th.add_prefix('1.0.0.0/24', 'assignment', 'test')
# check stats for p1
res = Prefix.smart_search('1.0.0.0/24', {})
self.assertEqual(256, res['result'][0].total_addresses)
self.assertEqual(0, res['result'][0].used_addresses)
self.assertEqual(256, res['result'][0].free_addresses)
# add a covering supernet around p1
p2 = th.add_prefix('1.0.0.0/20', 'reservation', 'bar')
# check stats for p2, our new top level prefix
res = Prefix.smart_search('1.0.0.0/20', {})
self.assertEqual(4096, res['result'][0].total_addresses)
self.assertEqual(256, res['result'][0].used_addresses)
self.assertEqual(3840, res['result'][0].free_addresses)
示例11: test_children7
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_children7(self):
""" Add prefixes within other prefix and verify parent prefix has correct children
"""
th = TestHelper()
# add a top level prefix
p1 = th.add_prefix('1.0.0.0/24', 'assignment', 'test')
# check stats for p1
res = Prefix.smart_search('1.0.0.0/24', {})
self.assertEqual(0, res['result'][0].children)
# add a host in our top prefix
p2 = th.add_prefix('1.0.0.1/32', 'host', 'bar')
# check stats for p1, our top level prefix
res = Prefix.smart_search('1.0.0.0/24', {})
self.assertEqual(1, res['result'][0].children)
# check stats for p2, our new host prefix
res = Prefix.smart_search('1.0.0.1/32', {})
self.assertEqual(0, res['result'][0].children)
示例12: test_children5
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_children5(self):
""" Check children are correct when shrinking prefix
"""
th = TestHelper()
# add a top level prefix
p1 = th.add_prefix('1.0.0.0/24', 'assignment', 'test')
p2 = th.add_prefix('1.0.7.0/24', 'assignment', 'test')
# add a covering supernet around p1 and p2
p3 = th.add_prefix('1.0.0.0/21', 'reservation', 'bar')
# check that p3 looks good
res = Prefix.smart_search('1.0.0.0/21', {})
self.assertEqual(2, res['result'][0].children)
# shrink our supernet, so it only covers p1
p3.prefix = '1.0.0.0/22'
p3.save()
# check that p3 only covers p1
res = Prefix.smart_search('1.0.0.0/22', {})
self.assertEqual(1, res['result'][0].children)
示例13: test_children6
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_children6(self):
""" Check children are correct when moving prefix
"""
th = TestHelper()
# add a top level prefix
p1 = th.add_prefix('1.0.0.0/24', 'assignment', 'test')
p2 = th.add_prefix('2.0.0.0/25', 'reservation', 'bar')
# now move our supernet, so we see that the update thingy works
p2.prefix = '2.0.0.0/22'
p2.save()
# check stats for p2, we shouldn't see children based on our old
# position (2.0.0.0/25)
res = Prefix.smart_search('2.0.0.0/22', {})
self.assertEqual(0, res['result'][0].children)
# now move our supernet, so we see that the update thingy works
p2.prefix = '1.0.0.0/22'
p2.save()
# check stats for p2, we should get p1 as child
res = Prefix.smart_search('1.0.0.0/22', {})
self.assertEqual(1, res['result'][0].children)
示例14: get_prefixes
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def get_prefixes(self, query):
""" Get prefix data from NIPAP
"""
try:
res = Prefix.smart_search(query, {})
except socket.error:
print >> sys.stderr, "Connection refused, please check hostname & port"
sys.exit(1)
except xmlrpclib.ProtocolError:
print >> sys.stderr, "Authentication failed, please check your username / password"
sys.exit(1)
for p in res['result']:
p.prefix_ipy = IPy.IP(p.prefix)
self.prefixes.append(p)
示例15: test_prefix_edit
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import smart_search [as 别名]
def test_prefix_edit(self):
""" Verify tags are correct after prefix edit
"""
# ran into this issue in #507
th = TestHelper()
# add to "top level" prefix, each with a unique tag
p1 = th.add_prefix('1.0.0.0/8', 'reservation', 'test', tags=['a'])
p2 = th.add_prefix('2.0.0.0/8', 'reservation', 'test', tags=['b'])
# add a subnet of p1
p3 = th.add_prefix('1.0.0.0/24', 'reservation', 'test')
# p3 should have inherited_tags = ['a'] from p1
res = Prefix.smart_search('1.0.0.0/24', {})
self.assertEqual(['a'], res['result'][0].inherited_tags.keys())
# edit p3 to become subnet of p2
p3.prefix = '2.0.0.0/24'
p3.save()
# p3 should have inherited_tags = ['b'] from p2
res = Prefix.smart_search('2.0.0.0/24', {})
self.assertEqual(['b'], res['result'][0].inherited_tags.keys())