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)
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)