本文整理汇总了Python中pynipap.Prefix.country方法的典型用法代码示例。如果您正苦于以下问题:Python Prefix.country方法的具体用法?Python Prefix.country怎么用?Python Prefix.country使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynipap.Prefix
的用法示例。
在下文中一共展示了Prefix.country方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_country_code_length
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import country [as 别名]
def test_country_code_length(self):
""" Make sure only two character country codes are allowed
"""
p = Prefix()
p.prefix = '1.3.3.0/24'
p.type = 'assignment'
# try to input one character - should fail
p.country = 'a'
with self.assertRaisesRegexp(NipapValueError, 'Please enter a two letter country code according to ISO 3166-1 alpha-2'):
p.save()
# try to input three character - should fail
p.country = 'aaa'
with self.assertRaisesRegexp(NipapValueError, 'Please enter a two letter country code according to ISO 3166-1 alpha-2'):
p.save()
# try to input a number character - should fail
p.country = 'a1'
with self.assertRaisesRegexp(NipapValueError, 'Please enter a two letter country code according to ISO 3166-1 alpha-2'):
p.save()
# try to input two character - should succeed
p.country = 'se'
p.save()
# output should be capitalized
self.assertEqual('SE', p.country)
示例2: add_prefix
# 需要导入模块: from pynipap import Prefix [as 别名]
# 或者: from pynipap.Prefix import country [as 别名]
def add_prefix(arg, opts):
""" Add prefix to NIPAP
"""
s = get_schema()
p = Prefix()
p.schema = s
p.prefix = opts.get('prefix')
p.type = opts.get('type')
p.description = opts.get('description')
p.node = opts.get('node')
p.country = opts.get('country')
p.order_id = opts.get('order_id')
p.vrf = opts.get('vrf')
p.alarm_priority = opts.get('alarm_priority')
p.comment = opts.get('comment')
p.monitor = _str_to_bool(opts.get('monitor'))
args = {}
if 'from-pool' in opts:
res = Pool.list(s, { 'name': opts['from-pool'] })
if len(res) == 0:
print >> sys.stderr, "No pool named %s found." % opts['from-pool']
sys.exit(1)
args['from-pool'] = res[0]
if 'from-prefix' in opts:
args['from-prefix'] = [ opts['from-prefix'], ]
if 'prefix-length' in opts:
args['prefix_length'] = int(opts['prefix-length'])
if 'family' in opts:
family = opts['family']
if opts['family'] == 'ipv4':
family = 4
elif opts['family'] == 'ipv6':
family = 6
args['family'] = family
try:
p.save(args)
except NipapError, e:
print >> sys.stderr, "Could not add prefix to NIPAP: %s" % e.message
sys.exit(1)