本文整理汇总了Python中pynipap.Prefix类的典型用法代码示例。如果您正苦于以下问题:Python Prefix类的具体用法?Python Prefix怎么用?Python Prefix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Prefix类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_stats3
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)
开发者ID:Cougar,项目名称:NIPAP,代码行数:26,代码来源:nipaptest.py
示例2: test_add_prefix
def test_add_prefix(self):
""" We should NOT be able to execute add_prefix as read-only user
"""
p = Prefix()
p.prefix = '1.3.3.7'
with self.assertRaises(NipapAuthorizationError):
p.save()
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:7,代码来源:nipap-ro.py
示例3: test_children8
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)
开发者ID:Cougar,项目名称:NIPAP,代码行数:27,代码来源:nipaptest.py
示例4: test_remove_prefix
def test_remove_prefix(self):
""" We should NOT be able to execute remove_prefix as read-only user
"""
p = Prefix()
p.id = 0
with self.assertRaises(NipapAuthorizationError):
p.remove()
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:7,代码来源:nipap-ro.py
示例5: test_children9
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)
开发者ID:Cougar,项目名称:NIPAP,代码行数:33,代码来源:nipaptest.py
示例6: test_tags1
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())
开发者ID:Cougar,项目名称:NIPAP,代码行数:34,代码来源:nipaptest.py
示例7: test_edit_prefix
def test_edit_prefix(self):
""" We should NOT be able to execute edit_prefix as read-only user
"""
p = Prefix()
p.id = 123
with self.assertRaises(NipapAuthorizationError):
p.save()
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:7,代码来源:nipap-ro.py
示例8: test_stats7
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)
开发者ID:Cougar,项目名称:NIPAP,代码行数:33,代码来源:nipaptest.py
示例9: test_stats5
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)
开发者ID:Cougar,项目名称:NIPAP,代码行数:27,代码来源:nipaptest.py
示例10: add_prefix
def add_prefix(self):
""" Add prefix according to the specification.
The following keys can be used:
schema Schema to which the prefix is to be added (mandatory)
prefix the prefix to add if already known
family address family (4 or 6)
description A short description
comment Longer comment
node Hostname of node
type Type of prefix; reservation, assignment, host
pool ID of pool
country Country where the prefix is used
order_id Order identifier
vrf VRF
alarm_priority Alarm priority of prefix
monitor If the prefix should be monitored or not
from-prefix A prefix the prefix is to be allocated from
from-pool A pool (ID) the prefix is to be allocated from
prefix_length Prefix length of allocated prefix
"""
p = Prefix()
# parameters which are "special cases"
try:
p.schema = Schema.get(int(request.params['schema']))
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:tobbakko,项目名称:NIPAP,代码行数:31,代码来源:xhr.py
示例11: add_prefix_from_pool
def add_prefix_from_pool(self, pool, family, description):
p = Prefix()
args = {}
args['from-pool'] = pool
args['family'] = family
p.type = pool.default_type
p.save(args)
return p
开发者ID:Cougar,项目名称:NIPAP,代码行数:9,代码来源:nipaptest.py
示例12: edit
def edit(self, id):
""" Edit a pool.
"""
c.pool = Pool.get(int(id))
c.prefix_list = Prefix.list({ 'pool_id': c.pool.id })
c.prefix = ''
# save changes to NIPAP
if request.method == 'POST':
c.pool.name = request.params['name']
c.pool.description = request.params['description']
c.pool.default_type = request.params['default_type']
if request.params['ipv4_default_prefix_length'].strip() == '':
c.pool.ipv4_default_prefix_length = None
else:
c.pool.ipv4_default_prefix_length = request.params['ipv4_default_prefix_length']
if request.params['ipv6_default_prefix_length'].strip() == '':
c.pool.ipv6_default_prefix_length = None
else:
c.pool.ipv6_default_prefix_length = request.params['ipv6_default_prefix_length']
c.pool.save()
redirect(url(controller = 'pool', action = 'list'))
c.search_opt_parent = 'all'
c.search_opt_child = 'none'
return render("/pool_edit.html")
开发者ID:CrackerJackMack,项目名称:NIPAP,代码行数:28,代码来源:pool.py
示例13: test_prefix_edit
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)
开发者ID:sohonet,项目名称:NIPAP,代码行数:26,代码来源:nipaptest.py
示例14: search_prefix
def search_prefix(self):
""" Search prefixes. Does not yet incorporate all the functions of the
search_prefix API function due to difficulties with transferring
a complete 'dict-to-sql' encoded data structure.
Instead, a list of prefix attributes can be given which will be
matched with the 'equals' operator if notheing else is specified. If
multiple attributes are given, they will be combined with the 'and'
operator. Currently, it is not possible to specify different
operators for different attributes.
"""
# extract operator
if 'operator' in request.json:
operator = request.json['operator']
else:
operator = 'equals'
# fetch attributes from request.json
attr = XhrController.extract_prefix_attr(request.json)
# build query dict
n = 0
q = {}
for key, val in attr.items():
if n == 0:
q = {
'operator': operator,
'val1': key,
'val2': val
}
else:
q = {
'operator': 'and',
'val1': {
'operator': operator,
'val1': key,
'val2': val
},
'val2': q
}
n += 1
# extract search options
search_opts = {}
if 'children_depth' in request.json:
search_opts['children_depth'] = request.json['children_depth']
if 'parents_depth' in request.json:
search_opts['parents_depth'] = request.json['parents_depth']
if 'include_neighbors' in request.json:
search_opts['include_neighbors'] = request.json['include_neighbors']
if 'max_result' in request.json:
search_opts['max_result'] = request.json['max_result']
if 'offset' in request.json:
search_opts['offset'] = request.json['offset']
try:
result = Prefix.search(q, search_opts)
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:60,代码来源:xhr.py
示例15: view_prefix
def view_prefix(arg, opts):
""" View a single prefix.
"""
s = get_schema()
res = Prefix.search(s, { 'operator': 'equals', 'val1': 'prefix', 'val2': arg }, {})
if len(res['result']) == 0:
print "Address %s not found." % arg
return
p = res['result'][0]
print "-- Address "
print " %-15s : %s" % ("Prefix", p.prefix)
print " %-15s : %s" % ("Display prefix", p.display_prefix)
print " %-15s : %s" % ("Type", p.type)
print " %-15s : IPv%s" % ("Family", p.family)
print " %-15s : %s" % ("Description", p.description)
print " %-15s : %s" % ("Node", p.node)
print " %-15s : %s" % ("Order", p.order_id)
print " %-15s : %s" % ("VRF", p.vrf)
print " %-15s : %s" % ("Alarm priority", p.alarm_priority)
print " %-15s : %s" % ("Monitor", p.monitor)
print "-- Comment"
print p.comment
开发者ID:tobbakko,项目名称:NIPAP,代码行数:26,代码来源:nipap_cli.py
示例16: new_prefix
def new_prefix():
p = Prefix()
p.monitor = True
p.alarm_priority = "high"
p.vrf = DEFAULT_VRF
p.node = None
p.tags["infoblox-import"] = 1
p.customer_id = DEFAULT_CUSTOMER
p.authoritative_source = "import"
# https://github.com/SpriteLink/NIPAP/issues/721
p.expires = "2100-01-30 00:00:00"
return p
开发者ID:genokan,项目名称:NIPAP,代码行数:13,代码来源:infoblox-import.py
示例17: test_children3
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)
开发者ID:Cougar,项目名称:NIPAP,代码行数:17,代码来源:nipaptest.py
示例18: edit_prefix
def edit_prefix(self, id):
""" Edit a prefix.
"""
try:
p = Prefix.get(int(id))
# extract attributes
if 'prefix' in request.json:
p.prefix = validate_string(request.json, 'prefix')
if 'type' in request.json:
p.type = validate_string(request.json, 'type')
if 'description' in request.json:
p.description = validate_string(request.json, 'description')
if 'expires' in request.json:
p.expires = validate_string(request.json, 'expires')
if 'comment' in request.json:
p.comment = validate_string(request.json, 'comment')
if 'node' in request.json:
p.node = validate_string(request.json, 'node')
if 'status' in request.json:
p.status = validate_string(request.json, 'status')
if 'pool' in request.json:
if request.json['pool'] is None:
p.pool = None
else:
try:
p.pool = Pool.get(int(request.json['pool']))
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
if 'alarm_priority' in request.json:
p.alarm_priority = validate_string(request.json, 'alarm_priority')
if 'monitor' in request.json:
if request.json['monitor'] == 'true':
p.monitor = True
else:
p.monitor = False
if 'country' in request.json:
p.country = validate_string(request.json, 'country')
if 'order_id' in request.json:
p.order_id = validate_string(request.json, 'order_id')
if 'customer_id' in request.json:
p.customer_id = validate_string(request.json, 'customer_id')
if 'vrf' in request.json:
try:
if request.json['vrf'] is None or len(unicode(request.json['vrf'])) == 0:
p.vrf = None
else:
p.vrf = VRF.get(int(request.json['vrf']))
except ValueError:
return json.dumps({'error': 1, 'message': "Invalid VRF ID '%s'" % request.json['vrf']})
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:58,代码来源:xhr.py
示例19: save_hosts
def save_hosts():
for host in hosts:
try:
host.save()
continue
except:
pass
r = Prefix().search({"operator": "contains", "val1": "prefix", "val2": host.prefix})
for p in r["result"]:
try:
p.type = "assignment"
p.tags["guessed"] = 1
p.save()
except:
pass
try:
host.save()
continue
except:
pass
# this is a last and probably wrong attempt
# to fix the bad data in infoblox.
p = Prefix()
p.type = "assignment"
p.description = "AUTO: host container (import)"
p.tags["auto"] = 1
ip = ipaddr.IPNetwork(host.prefix)
p.prefix = str(ip.supernet(prefixlen_diff=1).network) + "/127"
p.save()
host.save()
开发者ID:genokan,项目名称:NIPAP,代码行数:33,代码来源:infoblox-import.py
示例20: add_prefix
def add_prefix(self, prefix, type, description, tags=[]):
p = Prefix()
p.prefix = prefix
p.type = type
p.description = description
p.tags = tags
p.save()
return p
开发者ID:Cougar,项目名称:NIPAP,代码行数:8,代码来源:upgrade-before.py
注:本文中的pynipap.Prefix类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论