本文整理汇总了Python中pynipap.VRF类的典型用法代码示例。如果您正苦于以下问题:Python VRF类的具体用法?Python VRF怎么用?Python VRF使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VRF类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_remove_vrf
def test_remove_vrf(self):
""" We should NOT be able to execute remove_vrf as read-only user
"""
v = VRF()
v.id = 0
with self.assertRaises(NipapAuthorizationError):
v.remove()
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:7,代码来源:nipap-ro.py
示例2: 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')
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.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:Cougar,项目名称:NIPAP,代码行数:32,代码来源:upgrade-before.py
示例3: test_edit_vrf
def test_edit_vrf(self):
""" We should NOT be able to execute edit_vrf as read-only user
"""
v = VRF()
v.id = 123
with self.assertRaises(NipapAuthorizationError):
v.save()
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:7,代码来源:nipap-ro.py
示例4: test_add_vrf
def test_add_vrf(self):
""" We should NOT be able to execute add_vrf as read-only user
"""
v = VRF()
v.rt = '123:456'
v.name = 'test'
with self.assertRaises(NipapAuthorizationError):
v.save()
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:8,代码来源:nipap-ro.py
示例5: test_search_vrf
def test_search_vrf(self):
""" We should be able to execute search_vrf as read-only user
"""
v = VRF.search({ 'val1': 'id',
'operator': 'equals',
'val2': 0 })
self.assertEqual(v['result'][0].id, 0)
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:7,代码来源:nipap-ro.py
示例6: smart_search_vrf
def smart_search_vrf(self):
""" Perform a smart VRF search.
The "smart" search function tries extract a query from
a text string. This query is then passed to the search_vrf
function, which performs the search.
"""
search_options = {}
extra_query = None
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']
if 'vrf_id' in request.params:
extra_query = {
'val1': 'id',
'operator': 'equals',
'val2': request.params['vrf_id']
}
try:
result = VRF.smart_search(request.params['query_string'],
search_options, extra_query
)
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:33,代码来源:xhr.py
示例7: list_vrf
def list_vrf(self):
""" List VRFs and return JSON encoded result.
"""
try:
vrfs = VRF.list()
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:8,代码来源:xhr.py
示例8: edit_vrf
def edit_vrf(self, id):
""" Edit a VRF.
"""
try:
v = VRF.get(int(id))
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:8,代码来源:xhr.py
示例9: remove
def remove(self, id):
""" Removes a VRF.
"""
v = VRF.get(int(id))
v.remove()
redirect(url(controller="vrf", action="list"))
开发者ID:genokan,项目名称:NIPAP,代码行数:8,代码来源:vrf.py
示例10: 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
示例11: remove_vrf
def remove_vrf(self, id):
""" Remove a VRF.
"""
try:
vrf = VRF.get(int(id))
vrf.remove()
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:10,代码来源:xhr.py
示例12: edit
def edit(self, id):
""" Edit a prefix.
"""
# find prefix
c.prefix = Prefix.get(int(id))
# we got a HTTP POST - edit object
if request.method == 'POST':
c.prefix.prefix = request.params['prefix_prefix']
c.prefix.description = request.params['prefix_description']
if request.params['prefix_node'].strip() == '':
c.prefix.node = None
else:
c.prefix.node = request.params['prefix_node']
if request.params['prefix_country'].strip() == '':
c.prefix.country = None
else:
c.prefix.country = request.params['prefix_country']
if request.params['prefix_comment'].strip() == '':
c.prefix.comment = None
else:
c.prefix.comment = request.params['prefix_comment']
if request.params['prefix_order_id'].strip() == '':
c.prefix.order_id = None
else:
c.prefix.order_id = request.params['prefix_order_id']
if request.params['prefix_customer_id'].strip() == '':
c.prefix.customer_id = None
else:
c.prefix.customer_id = request.params['prefix_customer_id']
if request.params['prefix_vrf'].strip() == '':
c.prefix.vrf = None
else:
# TODO: handle non-existent VRF...
c.prefix.vrf = VRF.list({ 'rt': request.params['prefix_vrf'] })[0]
if request.params.get('prefix_monitor') is not None:
c.prefix.monitor = True
else:
c.prefix.monitor = False
c.prefix.alarm_priority = request.params['prefix_alarm_priority']
c.prefix.save()
redirect(url(controller='prefix', action='list'))
return render('/prefix_edit.html')
开发者ID:Dhyrule,项目名称:NIPAP,代码行数:54,代码来源:prefix.py
示例13: test_stats1
def test_stats1(self):
""" Check stats are correct when adding and removing prefixes
"""
th = TestHelper()
# add some top level prefixes to the default VRF
p1 = th.add_prefix('1.0.0.0/24', 'reservation', 'test')
p2 = th.add_prefix('2.0.0.0/24', 'reservation', 'test')
p3 = th.add_prefix('2001:db8:1::/48', 'reservation', 'test')
p4 = th.add_prefix('2001:db8:2::/48', 'reservation', 'test')
# check stats for VRF
res = VRF.get(0)
# ipv4
self.assertEqual(2, res.num_prefixes_v4)
self.assertEqual(512, res.total_addresses_v4)
self.assertEqual(0, res.used_addresses_v4)
self.assertEqual(512, res.free_addresses_v4)
# ipv6
self.assertEqual(2, res.num_prefixes_v6)
self.assertEqual(2417851639229258349412352, res.total_addresses_v6)
self.assertEqual(0, res.used_addresses_v6)
self.assertEqual(2417851639229258349412352, res.free_addresses_v6)
# remove some prefixes
p1.remove()
p3.remove()
# check stats for VRF
res = VRF.get(0)
# ipv4
self.assertEqual(1, res.num_prefixes_v4)
self.assertEqual(256, res.total_addresses_v4)
self.assertEqual(0, res.used_addresses_v4)
self.assertEqual(256, res.free_addresses_v4)
# ipv6
self.assertEqual(1, res.num_prefixes_v6)
self.assertEqual(1208925819614629174706176, res.total_addresses_v6)
self.assertEqual(0, res.used_addresses_v6)
self.assertEqual(1208925819614629174706176, res.free_addresses_v6)
开发者ID:Cougar,项目名称:NIPAP,代码行数:40,代码来源:nipaptest.py
示例14: test_stats2
def test_stats2(self):
""" Check stats are correct when adding and removing prefixes
"""
th = TestHelper()
# add some top level prefixes to the default VRF
p1 = th.add_prefix('1.0.0.0/24', 'reservation', 'test')
p2 = th.add_prefix('1.0.0.128/25', 'assignment', 'test')
p3 = th.add_prefix('2001:db8:1::/48', 'reservation', 'test')
p4 = th.add_prefix('2001:db8:1:1::/64', 'reservation', 'test')
# check stats for VRF
res = VRF.get(0)
# ipv4
self.assertEqual(2, res.num_prefixes_v4)
self.assertEqual(256, res.total_addresses_v4)
self.assertEqual(128, res.used_addresses_v4)
self.assertEqual(128, res.free_addresses_v4)
# ipv6
self.assertEqual(2, res.num_prefixes_v6)
self.assertEqual(1208925819614629174706176, res.total_addresses_v6)
self.assertEqual(18446744073709551616, res.used_addresses_v6)
self.assertEqual(1208907372870555465154560, res.free_addresses_v6)
# remove some prefixes
p1.remove()
p3.remove()
# check stats for VRF
res = VRF.get(0)
# ipv4
self.assertEqual(1, res.num_prefixes_v4)
self.assertEqual(128, res.total_addresses_v4)
self.assertEqual(0, res.used_addresses_v4)
self.assertEqual(128, res.free_addresses_v4)
# ipv6
self.assertEqual(1, res.num_prefixes_v6)
self.assertEqual(18446744073709551616, res.total_addresses_v6)
self.assertEqual(0, res.used_addresses_v6)
self.assertEqual(18446744073709551616, res.free_addresses_v6)
开发者ID:Cougar,项目名称:NIPAP,代码行数:40,代码来源:nipaptest.py
示例15: add_current_vrf
def add_current_vrf(self):
""" Add VRF to filter list session variable
"""
vrf_id = request.params.get('vrf_id')
if vrf_id is not None:
if vrf_id == 'null':
vrf = VRF()
else:
vrf = VRF.get(int(vrf_id))
session['current_vrfs'][vrf_id] = { 'id': vrf.id, 'rt': vrf.rt,
'name': vrf.name, 'description': vrf.description }
session.save()
return json.dumps(session.get('current_vrfs', {}))
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:18,代码来源:xhr.py
示例16: add_vrf
def add_vrf(self):
""" Add a new VRF to NIPAP and return its data.
"""
v = VRF()
if 'rt' in request.json:
v.rt = validate_string(request.json, 'rt')
if 'name' in request.json:
v.name = validate_string(request.json, 'name')
if 'description' in request.json:
v.description = validate_string(request.json, 'description')
if 'tags' in request.json:
v.tags = request.json['tags']
if 'avps' in request.json:
v.avps = request.json['avps']
try:
v.save()
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:fredsod,项目名称:NIPAP,代码行数:20,代码来源:xhr.py
示例17: add_vrf
def add_vrf(self):
""" Add a new VRF to NIPAP and return its data.
"""
v = VRF()
if 'rt' in request.params:
if request.params['rt'].strip() != '':
v.rt = request.params['rt'].strip()
if 'name' in request.params:
if request.params['name'].strip() != '':
v.name = request.params['name'].strip()
if 'description' in request.params:
v.description = request.params['description']
if 'tags' in request.params:
v.tags = json.loads(request.params['tags'])
if 'avps' in request.params:
v.avps = json.loads(request.params['avps'])
try:
v.save()
except NipapError, e:
return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
开发者ID:AlfredArouna,项目名称:NIPAP,代码行数:23,代码来源:xhr.py
示例18: add_prefix
def add_prefix(self):
""" Add prefix according to the specification.
The following keys can be used:
vrf ID of VRF to place the prefix in
prefix the prefix to add if already known
family address family (4 or 6)
description A short description
expires Expiry time of assignment
comment Longer comment
node Hostname of node
type Type of prefix; reservation, assignment, host
status Status of prefix; assigned, reserved, quarantine
pool ID of pool
country Country where the prefix is used
order_id Order identifier
customer_id Customer identifier
vlan VLAN ID
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()
# Sanitize input parameters
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,代码行数:40,代码来源:xhr.py
示例19: smart_search_vrf
def smart_search_vrf(self):
""" Perform a smart VRF search.
The "smart" search function tries extract a query from
a text string. This query is then passed to the search_vrf
function, which performs the search.
"""
search_options = {}
extra_query = None
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']
if 'vrf_id' in request.json:
extra_query = {
'val1': 'id',
'operator': 'equals',
'val2': request.json['vrf_id']
}
try:
result = VRF.smart_search(request.json['query_string'],
search_options, extra_query
)
# 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,代码行数:39,代码来源:xhr.py
示例20: get_current_vrfs
def get_current_vrfs(self):
""" Return VRF filter list from session variable
Before returning list, make a search for all VRFs currently in the
list to verify that they still exist.
"""
# Verify that all currently selected VRFs still exists
cur_vrfs = session.get('current_vrfs', {}).items()
if len(cur_vrfs) > 0:
q = {
'operator': 'equals',
'val1': 'id',
'val2': cur_vrfs[0][0]
}
if len(cur_vrfs) > 1:
for vrf_id, vrf in cur_vrfs[1:]:
q = {
'operator': 'or',
'val1': q,
'val2': {
'operator': 'equals',
'val1': 'id',
'val2': vrf_id
}
}
res = VRF.search(q)
session['current_vrfs'] = {}
for vrf in res['result']:
session['current_vrfs'][vrf.id] = { 'id': vrf.id, 'rt': vrf.rt,
'name': vrf.name, 'description': vrf.description }
session.save()
return json.dumps(session.get('current_vrfs', {}))
开发者ID:fredsod,项目名称:NIPAP,代码行数:38,代码来源:xhr.py
注:本文中的pynipap.VRF类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论