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__})
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')
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') != 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')
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__ })
def get_vrfs(self): """ Get the list of VRFs from nipap self.vrfs = { 1: { "label": "global [65001:1234]", "vrf": nipap.VRF }, .... } self.vrf_labels = { "global [65001:1234]": 1, "default": 2, ... } :return: """ self.lock.acquire() try: vrf_list = VRF.list() except Exception as e: self.lock.release() raise e # Populate `self.vrfs` and `self.vrf_labels` for vrf in vrf_list: self.vrfs[vrf.id] = { 'label': "%s [%s]" % (vrf.name, vrf.rt), 'vrf': vrf } # If there's no RT (such in global), don't display brackets label = "VRF %s [%s]" % (vrf.name, vrf.rt) if vrf.rt else "VRF %s" % vrf.name self.vrf_labels[label] = str(vrf.id) self.lock.release() return True if self.vrfs else False
pynipap.xmlrpc_uri = xmlrpc_uri if args.clear_vrfs: remove_confirmed = args.force if not remove_confirmed: res = raw_input("Are you sure you want to remove all VRFs? Note how all" + " prefixes in these VRFs WILL BE DELETED. The default VRF" + " will NOT be deleted nor will it be emptied. [y/N]") if len(res) > 0 and res.lower()[0] == 'y': remove_confirmed = True else: print "Aborted" if remove_confirmed: print "Removing: ", for v in VRF.list(): if v.id == 0: continue v.remove() sys.stdout.write(".") sys.stdout.flush() print " done!" if args.clear_pools: remove_confirmed = args.force if not remove_confirmed: res = raw_input("Are you sure you want to remove all pools? [y/N]") if len(res) > 0 and res.lower()[0] == 'y': remove_confirmed = True else: print "Operation aborted."
pynipap.xmlrpc_uri = "http://*****:*****@localhost:1337" o = AuthOptions({"authoritative_source": "nipap"}) # set to a string if you want the customerid populated DEFAULT_CUSTOMER = None # set this to true if any of the network blocks # are unclean and are really assignments or hosts. # use with caution. detect_hosts = False # this is for network blocks that are misrepresented # it might not be needed for your network hosts = [] for vrf in VRF.list(): if vrf.id == 0: DEFAULT_VRF = vrf break else: raise ValueError("No default VRF") def export_tags(obj): def f(): for name, attr in obj["extattrs"].items(): # skip inherited attributes if attr.get("inheritance_source"): continue yield name, attr["value"]
def list(self): """ List VRFs. """ c.vrfs = VRF.list() return render("/vrf_list.html")
'authoritative_source': 'nipap' }) # set to a string if you want the customerid populated DEFAULT_CUSTOMER = None # set this to true if any of the network blocks # are unclean and are really assignments or hosts. # use with caution. detect_hosts = False # this is for network blocks that are misrepresented # it might not be needed for your network hosts = [] for vrf in VRF.list(): if vrf.id == 0: DEFAULT_VRF = vrf break else: raise ValueError("No default VRF") def export_tags(obj): def f(): for name, attr in obj['extattrs'].items(): # skip inherited attributes if attr.get('inheritance_source'): continue yield name, attr['value'] return dict(f())