本文整理汇总了Python中pynipap.Pool类的典型用法代码示例。如果您正苦于以下问题:Python Pool类的具体用法?Python Pool怎么用?Python Pool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pool类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_add_pool
def test_add_pool(self):
""" We should NOT be able to execute add_pool as read-only user
"""
p = Pool()
p.name = 'test'
with self.assertRaises(NipapAuthorizationError):
p.save()
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:7,代码来源:nipap-ro.py
示例2: test_edit_pool
def test_edit_pool(self):
""" We should NOT be able to execute edit_pool as read-only user
"""
p = Pool()
p.id = 123
with self.assertRaises(NipapAuthorizationError):
p.save()
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:7,代码来源:nipap-ro.py
示例3: test_remove_pool
def test_remove_pool(self):
""" We should NOT be able to execute remove_pool as read-only user
"""
p = Pool()
p.id = 0
with self.assertRaises(NipapAuthorizationError):
p.remove()
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:7,代码来源:nipap-ro.py
示例4: add_pool
def add_pool(self):
""" Add a pool.
"""
# extract attributes
p = Pool()
if 'name' in request.json:
p.name = validate_string(request.json, 'name')
if 'description' in request.json:
p.description = validate_string(request.json, 'description')
if 'default_type' in request.json:
p.default_type = validate_string(request.json, 'default_type')
# TODO: handle integers
if 'ipv4_default_prefix_length' in request.json:
p.ipv4_default_prefix_length = request.json['ipv4_default_prefix_length']
if 'ipv6_default_prefix_length' in request.json:
p.ipv6_default_prefix_length = request.json['ipv6_default_prefix_length']
if 'tags' in request.json:
p.tags = request.json['tags']
if 'avps' in request.json:
p.avps = request.json['avps']
try:
p.save()
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:26,代码来源:xhr.py
示例5: test_load_data
def test_load_data(self):
"""
"""
th = TestHelper()
p1 = th.add_prefix('192.168.0.0/16', 'reservation', 'test')
p2 = th.add_prefix('192.168.0.0/20', 'reservation', 'test')
p3 = th.add_prefix('192.168.0.0/24', 'reservation', 'test')
p4 = th.add_prefix('192.168.1.0/24', 'reservation', 'test')
p5 = th.add_prefix('192.168.2.0/24', 'reservation', 'test')
p6 = th.add_prefix('192.168.32.0/20', 'reservation', 'test')
p7 = th.add_prefix('192.168.32.0/24', 'reservation', 'test')
p8 = th.add_prefix('192.168.32.1/32', 'reservation', 'test')
ps1 = th.add_prefix('2001:db8:1::/48', 'reservation', 'test')
ps2 = th.add_prefix('2001:db8:1::/64', 'reservation', 'test')
ps3 = th.add_prefix('2001:db8:2::/48', 'reservation', 'test')
pool1 = Pool()
pool1.name = 'upgrade-test'
pool1.ipv4_default_prefix_length = 31
pool1.ipv6_default_prefix_length = 112
pool1.save()
p2.pool = pool1
p2.save()
ps1.pool = pool1
ps1.save()
pool2 = Pool()
pool2.name = 'upgrade-test2'
pool2.save()
vrf1 = VRF()
vrf1.name = 'foo'
vrf1.rt = '123:123'
vrf1.save()
开发者ID:slillibri,项目名称:NIPAP,代码行数:35,代码来源:upgrade-before.py
示例6: add
def add(self):
""" Add a pool.
"""
if 'schema' not in request.params:
redirect(url(controller = 'schema', action = 'list'))
c.schema = Schema.get(int(request.params['schema']))
# Adding to NIPAP
if request.method == 'POST':
p = Pool()
p.schema = c.schema
p.name = request.params.get('name')
p.description = request.params.get('description')
p.default_type = request.params.get('default_type')
if request.params['ipv4_default_prefix_length'].strip() != '':
p.ipv4_default_prefix_length = request.params['ipv4_default_prefix_length']
if request.params['ipv6_default_prefix_length'].strip() != '':
p.ipv6_default_prefix_length = request.params['ipv6_default_prefix_length']
p.save()
redirect(url(controller = 'pool', action = 'list', schema = c.schema.id))
return render("/pool_add.html")
开发者ID:tobbakko,项目名称:NIPAP,代码行数:26,代码来源:pool.py
示例7: test_stats3
def test_stats3(self):
""" Check total stats are correct when adding and removing child prefixes from pool
"""
th = TestHelper()
# add a pool
pool1 = th.add_pool('test', 'assignment', 31, 112)
# add some members to the pool
p1 = th.add_prefix('1.0.0.0/24', 'reservation', 'test', pool_id=pool1.id)
p2 = th.add_prefix('2001:db8::/48', 'reservation', 'test', pool_id=pool1.id)
# add child from pool
pc1 = th.add_prefix_from_pool(pool1, 4, 'foo')
pc2 = th.add_prefix_from_pool(pool1, 6, 'foo')
# check stats for pool1
res = Pool.list({ 'id': pool1.id })
# ipv4
self.assertEqual(1, res[0].member_prefixes_v4)
self.assertEqual(1, res[0].used_prefixes_v4)
self.assertEqual(256, res[0].total_addresses_v4)
self.assertEqual(2, res[0].used_addresses_v4)
self.assertEqual(254, res[0].free_addresses_v4)
# ipv6
self.assertEqual(1, res[0].member_prefixes_v6)
self.assertEqual(1, res[0].used_prefixes_v6)
self.assertEqual(1208925819614629174706176, res[0].total_addresses_v6)
self.assertEqual(65536, res[0].used_addresses_v6)
self.assertEqual(1208925819614629174640640, res[0].free_addresses_v6)
# remove child prefixes
pc1.remove()
pc2.remove()
# check stats for pool1
res = Pool.list({ 'id': pool1.id })
# ipv4
self.assertEqual(1, res[0].member_prefixes_v4)
self.assertEqual(0, res[0].used_prefixes_v4)
self.assertEqual(256, res[0].total_addresses_v4)
self.assertEqual(0, res[0].used_addresses_v4)
self.assertEqual(256, res[0].free_addresses_v4)
# ipv6
self.assertEqual(1, res[0].member_prefixes_v6)
self.assertEqual(0, res[0].used_prefixes_v6)
self.assertEqual(1208925819614629174706176, res[0].total_addresses_v6)
self.assertEqual(0, res[0].used_addresses_v6)
self.assertEqual(1208925819614629174706176, res[0].free_addresses_v6)
开发者ID:Cougar,项目名称:NIPAP,代码行数:49,代码来源:nipaptest.py
示例8: test_stats2
def test_stats2(self):
""" Check total stats are correct when updating member prefix
"""
th = TestHelper()
# add a pool
pool1 = th.add_pool('test', 'assignment', 31, 112)
# add some members to the pool
p1 = th.add_prefix('1.0.0.0/24', 'reservation', 'test', pool_id=pool1.id)
p2 = th.add_prefix('2001:db8::/48', 'reservation', 'test', pool_id=pool1.id)
p1.prefix = '1.0.0.0/25'
p1.save()
p2.prefix = '2001:db8::/64'
p2.save()
# check stats for pool1
res = Pool.list({ 'id': pool1.id })
# ipv4
self.assertEqual(1, res[0].member_prefixes_v4)
self.assertEqual(0, res[0].used_prefixes_v4)
self.assertEqual(128, res[0].total_addresses_v4)
self.assertEqual(0, res[0].used_addresses_v4)
self.assertEqual(128, res[0].free_addresses_v4)
# ipv6
self.assertEqual(1, res[0].member_prefixes_v6)
self.assertEqual(0, res[0].used_prefixes_v6)
self.assertEqual(18446744073709551616, res[0].total_addresses_v6)
self.assertEqual(0, res[0].used_addresses_v6)
self.assertEqual(18446744073709551616, res[0].free_addresses_v6)
开发者ID:Cougar,项目名称:NIPAP,代码行数:31,代码来源:nipaptest.py
示例9: list
def list(self):
""" Displays a list of pools.
"""
c.pools = Pool.list()
return render('/pool_list.html')
开发者ID:hetznerZA,项目名称:NIPAP,代码行数:7,代码来源:pool.py
示例10: 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
示例11: smart_search_pool
def smart_search_pool(self):
""" Perform a smart pool search.
The "smart" search function tries extract a query from
a text string. This query is then passed to the search_pool
function, which performs the search.
"""
search_options = {}
if 'query_id' in request.params:
search_options['query_id'] = request.params['query_id']
if 'max_result' in request.params:
search_options['max_result'] = request.params['max_result']
if 'offset' in request.params:
search_options['offset'] = request.params['offset']
log.debug("params: %s" % str(request.params))
log.debug("Smart search query: schema=%d q=%s search_options=%s" %
(int(request.params['schema']),
request.params['query_string'],
str(search_options)
))
try:
schema = Schema.get(int(request.params['schema']))
result = Pool.smart_search(schema,
request.params['query_string'],
search_options
)
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:tobbakko,项目名称:NIPAP,代码行数:34,代码来源:xhr.py
示例12: remove
def remove(self, id):
""" Remove pool.
"""
p = Pool.get(int(id))
p.remove()
redirect(url(controller = 'pool', action = 'list'))
开发者ID:CrackerJackMack,项目名称:NIPAP,代码行数:7,代码来源:pool.py
示例13: edit_pool
def edit_pool(self, id):
""" Edit a pool.
"""
# extract attributes
p = Pool.get(int(id))
if 'name' in request.params:
p.name = request.params.get('name')
if 'description' in request.params:
p.description = request.params.get('description')
if 'default_type' in request.params:
p.default_type = request.params.get('default_type')
if 'ipv4_default_prefix_length' in request.params:
if request.params['ipv4_default_prefix_length'].strip() != '':
p.ipv4_default_prefix_length = request.params['ipv4_default_prefix_length']
else:
p.ipv4_default_prefix_length = None
if 'ipv6_default_prefix_length' in request.params:
if request.params['ipv6_default_prefix_length'].strip() != '':
p.ipv6_default_prefix_length = request.params['ipv6_default_prefix_length']
else:
p.ipv6_default_prefix_length = None
if 'tags' in request.params:
p.tags = json.loads(request.params['tags'])
if 'avps' in request.params:
p.avps = json.loads(request.params['avps'])
try:
p.save()
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:31,代码来源:xhr.py
示例14: modify_pool
def modify_pool(arg, opts):
""" Modify a pool with the options set in opts
"""
s = get_schema()
res = Pool.list(s, { 'name': arg })
if len(res) < 1:
print >> sys.stderr, "No pool with name %s found." % arg
sys.exit(1)
p = res[0]
if 'name' in opts:
p.name = opts['name']
if 'description' in opts:
p.description = opts['description']
if 'default-type' in opts:
p.default_type = opts['default-type']
if 'ipv4_default_prefix_length' in opts:
p.ipv4_default_prefix_length = opts['ipv4_default_prefix_length']
if 'ipv6_default_prefix_length' in opts:
p.ipv6_default_prefix_length = opts['ipv6_default_prefix_length']
p.save()
print "Pool %s saved." % p.name
开发者ID:tobbakko,项目名称:NIPAP,代码行数:26,代码来源:nipap_cli.py
示例15: smart_search_pool
def smart_search_pool(self):
""" Perform a smart pool search.
The "smart" search function tries extract a query from
a text string. This query is then passed to the search_pool
function, which performs the search.
"""
search_options = {}
if 'query_id' in request.json:
search_options['query_id'] = request.json['query_id']
if 'max_result' in request.json:
search_options['max_result'] = request.json['max_result']
if 'offset' in request.json:
search_options['offset'] = request.json['offset']
try:
result = Pool.smart_search(request.json['query_string'],
search_options
)
# Remove error key in result from backend as it interferes with the
# error handling of the web interface.
# TODO: Reevaluate how to deal with different types of errors; soft
# errors like query string parser errors and hard errors like lost
# database.
del result['error']
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:30,代码来源:xhr.py
示例16: list_pool
def list_pool(arg, opts):
""" List pools matching a search criteria
"""
s = get_schema()
query = _expand_list_query(opts)
res = Pool.search(s, query)
if len(res['result']) > 0:
print "%-19s %-39s %-14s %-8s" % (
"Name", "Description", "Default type", "4 / 6"
)
print "-----------------------------------------------------------------------------------"
else:
print "No matching pools found"
for p in res['result']:
if len(p.description) > 38:
desc = p.description[0:34] + "..."
else:
desc = p.description
print "%-19s %-39s %-14s %-2s / %-3s" % (
p.name, desc, p.default_type,
str(p.ipv4_default_prefix_length),
str(p.ipv6_default_prefix_length)
)
开发者ID:tobbakko,项目名称:NIPAP,代码行数:26,代码来源:nipap_cli.py
示例17: 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
示例18: list_pool
def list_pool(self):
""" List pools and return JSON encoded result.
"""
try:
schema = Schema.get(int(request.params['schema']))
pools = Pool.list(schema)
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:tobbakko,项目名称:NIPAP,代码行数:9,代码来源:xhr.py
示例19: add_pool
def add_pool(self, name, default_type, ipv4_default_prefix_length, ipv6_default_prefix_length):
pool = Pool()
pool.name = name
pool.default_type = default_type
pool.ipv4_default_prefix_length = ipv4_default_prefix_length
pool.ipv6_default_prefix_length = ipv6_default_prefix_length
pool.save()
return pool
开发者ID:Cougar,项目名称:NIPAP,代码行数:8,代码来源:nipaptest.py
示例20: remove_pool
def remove_pool(self, id):
""" Remove a pool.
"""
try:
pool = Pool.get(int(id))
pool.remove()
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:10,代码来源:xhr.py
注:本文中的pynipap.Pool类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论