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 added Timestamp of added prefix last_modified Timestamp of last modify 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__ })
def add_prefix_to_vrf(self, vrfrt, prefix, type, description, status, tags=[]): """ Note: This function adds a prefix to a given VRF, if the prefix is used or invalid, it will return None :param vrfrt: String like "209:123" :param prefix: String like "1.0.0.0/29" :param type: String, must be on of the following: 'reservation', 'assignment', 'host' :param description: String :param status: String, must be "assigned" or "reserved" :param tags: Array of Strings :return: Prefix object or None """ myvrf = None p = None # get the vrf myvrf = self.find_vrf('rt', vrfrt) p = Prefix() p.prefix = prefix p.type = type p.status = status p.description = description p.vrf = myvrf p.tags = tags try: p.save() except: e = sys.exc_info()[0] logging.error("Error: could not add prefix: %s" % e) return p
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__})
def new_prefix(): p = Prefix() p.monitor = True p.alarm_priority = "high" p.vrf = DEFAULT_VRF p.node = None p.tags["infoblox-import"] = 1 p.customer_id = DEFAULT_CUSTOMER p.authoritative_source = "import" # https://github.com/SpriteLink/NIPAP/issues/721 p.expires = "2100-01-30 00:00:00" return p
def new_prefix(): p = Prefix() p.monitor = True p.alarm_priority = 'high' p.vrf = DEFAULT_VRF p.node = None p.tags['infoblox-import'] = 1 p.customer_id = DEFAULT_CUSTOMER p.authoritative_source = 'import' # https://github.com/SpriteLink/NIPAP/issues/721 p.expires = '2100-01-30 00:00:00' return p
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)