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")
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")
def list_prefix(self): """ List prefixes and return JSON encoded result. """ # fetch attributes from request.json attr = XhrController.extract_prefix_attr(request.json) try: prefixes = Prefix.list(attr) except NipapError, e: return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
def get_prefixs(self, name=''): """ Return a prefix with the passed in name :param name: prefix name such as '1.1.1.0/32' :return: Prefix object list """ if len(name) > 0: pass else: p = Prefix.list() return p
def list_prefix(self): """ List prefixes and return JSON encoded result. """ # fetch attributes from request.params attr = XhrController.extract_prefix_attr(request.params) try: schema = Schema.get(int(request.params['schema'])) prefixes = Prefix.list(schema, attr) except NipapError, e: return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
def list_prefix(self): """ List prefixes and return JSON encoded result. """ # fetch attributes from request.json attr = XhrController.extract_prefix_attr(request.json) try: prefixes = Prefix.list(attr) except NipapError, e: return json.dumps({ 'error': 1, 'message': e.args, 'type': type(e).__name__ })
def remove_prefix(arg, opts): """ Remove prefix """ s = get_schema() res = Prefix.list(s, { 'prefix': arg }) if len(res) < 1: print >> sys.stderr, "No prefix %s found." % arg sys.exit(1) p = res[0] res = raw_input("Do you really want to remove the prefix %s in schema %s? [y/n]: " % (p.prefix, s.name)) if res == 'y': p.remove() print "Prefix %s removed." % p.prefix else: print "Operation canceled."
def view_pool(arg, opts): """ View a single pool """ s = get_schema(opts.get('schema')) res = Pool.list(s, { 'name': arg }) if len(res) == 0: print "No pool named %s found." % arg return p = res[0] print "-- Pool " print " %-15s : %s" % ("Name", p.name) print " %-15s : %s" % ("Description", p.description) print " %-15s : %s" % ("Default type", p.default_type) print " %-15s : %s / %s" % ("Preflen (v4/v6)", str(p.ipv4_default_prefix_length), str(p.ipv6_default_prefix_length)) print "\n-- Prefixes in pool" res = Prefix.list(s, { 'pool': p.id}) for pref in res: print " %s" % pref.display_prefix
def modify_prefix(arg, opts): """ Modify the prefix 'arg' with the options 'opts' """ s = get_schema() res = Prefix.list(s, { 'prefix': arg }) if len(res) == 0: print >> sys.stderr, "Prefix %s not found in schema %s." % (arg, s.name) return p = res[0] if 'description' in opts: p.description = opts['description'] if 'comment' in opts: p.comment = opts['comment'] if 'node' in opts: p.node = opts['node'] if 'type' in opts: p.type = opts['type'] if 'country' in opts: p.country = opts['country'] if 'order_id' in opts: p.order_id = opts['order_id'] if 'vrf' in opts: p.vrf = opts['vrf'] if 'alarm_priority' in opts: p.alarm_priority = opts['alarm_priority'] if 'monitor' in opts: p.monitor = _str_to_bool(opts['monitor']) try: p.save() except NipapError, e: print >> sys.stderr, "Could not save prefix changes: %s" % e.message sys.exit(1)
if len(res) > 0 and res.lower()[0] == 'y': remove_confirmed = True else: print "Operation aborted." if remove_confirmed: print "Removing: ", for p in Pool.list(): p.remove() sys.stdout.write(".") sys.stdout.flush() print " done!" if args.clear_prefixes: remove_confirmed = args.force if not remove_confirmed: res = raw_input("Are you sure you want to remove all prefixes? [y/N]") if len(res) > 0 and res.lower()[0] == 'y': remove_confirmed = True else: print "Aborted" if remove_confirmed: print "Removing: ", for p in Prefix.list({'indent': 0}): p.remove(recursive=True) sys.stdout.write(".") sys.stdout.flush() print " done!"