Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
    def parse_line(self, line):
        """ Parse one line
        """

        try:
            # text params, ie params from the text file
            tp = self.split_columns(line)
        except CommentLine:
            # just ignore comments
            return

        if tp['prefix_type'] == 'reservation':  # reservations / aggregates
            print "Reservation:", tp['prefix'], tp['description']
            p = Prefix()
            p.schema = self.schema
            p.prefix = tp['prefix']
            p.type = 'reservation'
            p.description = tp['description']
            p.monitor = True
            p.alarm_priority = 'low'
            p.authoritative_source = 'nw'
            p.save({})
            return

        elif tp['node'] == '.' and tp['description'] == '.':
            # ignore prefixes without description or node set
            return

        elif tp['prefix_length'] == 32:   # loopback
            # if it's a loopback, the covering prefix will be a reservation and we can just insert an assignment.
            # if this insert fails, it means the parent prefix is an assignment and we instead insert a host
            try:
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                # loopbacks are always of type 'assignment'
                p.type = 'assignment'
                p.node = tp['node']
                p.description = tp['description']
                p.monitor = True
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                p.save({})
                print "Loopback:", tp['prefix']
                return
            except:
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                # loopbacks are always of type 'assignment'
                p.type = 'host'
                p.node = tp['node']
                p.description = tp['description']
                p.monitor = True
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                p.save({})
                print "Host:", tp['prefix']
                return

        elif tp['prefix_length'] == 30 or tp['prefix_length'] == 31:   # link network
            octets = tp['address'].split('.')
            prefix_node1 = None
            prefix_node2 = None
            if tp['prefix_length'] == 30:
                prefix_node1 = '.'.join(octets[:3] + [str( int(octets[3]) + 1 )] ) + '/32'
                prefix_node2 = '.'.join(octets[:3] + [str( int(octets[3]) + 2 )] ) + '/32'
            else:
                prefix_node1 = '.'.join(octets) + '/32'
                prefix_node2 = '.'.join(octets[:3] + [str( int(octets[3]) + 1 )] ) + '/32'

            #m = re.match('(ETHER_KAP|ETHER_PORT|IP-KAP|IP-PORT|IP-SIPNET|IP-SNIX|IPSUR|L2L|RED-IPPORT|SNIX|SWIP|T2V-@|T2V-DIGTV|T2V-SUR)[0-9]{4,}', tp['order_id'])
            m = re.match('.*[0-9]{6}$', tp['order_id'])
            if m is not None or tp['type'] == 'CUSTOMER':
                print "Customer link", tp['prefix'], ':', tp['description']
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                p.type = 'assignment'
                p.description = tp['description']
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                if tp['order_id'] != '.':
                    p.order_id = tp['order_id']
                p.save({})

                # insert node1 and node2
                p1 = Prefix()
                p1.schema = self.schema
                p1.prefix = prefix_node1
                p1.type = 'host'
                p1.description = 'Some PE router'
                p1.authoritative_source = 'nw'
                p1.save({})

                p2 = Prefix()
                p2.schema = self.schema
                p2.prefix = prefix_node2
                p2.type = 'host'
                p2.node = tp['node']
                p2.description = 'CPE'
                p2.authoritative_source = 'nw'
                p2.save({})

                return


            m = re.match(r'([^\s]+)\s*<->\s*([^\s]+)', tp['description'])
            if m is not None:
                node1 = m.group(1)
                node2 = m.group(2)
                print "Link network: ", tp['prefix'], "  ", node1, "<->", node2

                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                p.type = 'assignment'
                p.description = node1 + ' <-> ' + node2
                p.monitor = True
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                p.save({})

                # insert node1 and node2
                p1 = Prefix()
                p1.schema = self.schema
                p1.prefix = prefix_node1
                p1.type = 'host'
                p1.node = node1
                p1.description = node1
                p1.authoritative_source = 'nw'
                p1.save({})

                p2 = Prefix()
                p2.schema = self.schema
                p2.prefix = prefix_node2
                p2.type = 'host'
                p2.node = node2
                p2.description = node2
                p2.authoritative_source = 'nw'
                p2.save({})

                return

            m = re.match('(DN)[0-9]{4,}', tp['order_id'])
            if m is not None:
                print "Internal order link network", tp['prefix'], ':', tp['description']
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                p.type = 'assignment'
                p.description = tp['description']
                p.monitor = True
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                p.save({})
                return

            print "Other link network", tp['prefix'], ':', tp['description']
            p = Prefix()
            p.schema = self.schema
            p.prefix = tp['prefix']
            p.type = 'assignment'
            p.description = tp['description']
            p.monitor = True
            p.alarm_priority = tp['alarm_priority']
            p.authoritative_source = 'nw'
            p.save({})
            return

        else:
            try:
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                p.type = 'assignment'
                p.description = tp['description']
                p.monitor = True
                p.alarm_priority = 'low'
                p.authoritative_source = 'nw'
                p.save({})
                print "Other:", tp['prefix']
            except NipapValueError, e:
                print tp['prefix'], ':', e
                sys.exit(1)

            return
Ejemplo n.º 5
0
    def parse_line(self, line):
        """ Parse one line
        """

        try:
            # text params, ie params from the text file
            tp = self.split_columns(line)
        except CommentLine:
            # just ignore comments
            return

        if tp['prefix_type'] == 'reservation':  # reservations / aggregates
            print "Reservation:", tp['prefix'], tp['description']
            p = Prefix()
            p.schema = self.schema
            p.prefix = tp['prefix']
            p.type = 'reservation'
            p.description = tp['description']
            p.monitor = True
            p.alarm_priority = 'low'
            p.authoritative_source = 'nw'
            p.save({})
            return

        elif tp['node'] == '.' and tp['description'] == '.':
            # ignore prefixes without description or node set
            return

        elif tp['prefix_length'] == 32:   # loopback
            # if it's a loopback, the covering prefix will be a reservation and we can just insert an assignment.
            # if this insert fails, it means the parent prefix is an assignment and we instead insert a host
            try:
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                # loopbacks are always of type 'assignment'
                p.type = 'assignment'
                p.node = tp['node']
                p.description = tp['description']
                p.monitor = True
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                p.save({})
                print "Loopback:", tp['prefix']
                return
            except:
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                # loopbacks are always of type 'assignment'
                p.type = 'host'
                p.node = tp['node']
                p.description = tp['description']
                p.monitor = True
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                p.save({})
                print "Host:", tp['prefix']
                return

        elif tp['prefix_length'] == 30 or tp['prefix_length'] == 31:   # link network
            octets = tp['address'].split('.')
            prefix_node1 = None
            prefix_node2 = None
            if tp['prefix_length'] == 30:
                prefix_node1 = '.'.join(octets[:3] + [str( int(octets[3]) + 1 )] ) + '/32'
                prefix_node2 = '.'.join(octets[:3] + [str( int(octets[3]) + 2 )] ) + '/32'
            else:
                prefix_node1 = '.'.join(octets) + '/32'
                prefix_node2 = '.'.join(octets[:3] + [str( int(octets[3]) + 1 )] ) + '/32'

            #m = re.match('(ETHER_KAP|ETHER_PORT|IP-KAP|IP-PORT|IP-SIPNET|IP-SNIX|IPSUR|L2L|RED-IPPORT|SNIX|SWIP|T2V-@|T2V-DIGTV|T2V-SUR)[0-9]{4,}', tp['order_id'])
            m = re.match('.*[0-9]{6}$', tp['order_id'])
            if m is not None or tp['type'] == 'CUSTOMER':
                print "Customer link", tp['prefix'], ':', tp['description']
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                p.type = 'assignment'
                p.description = tp['description']
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                if tp['order_id'] != '.':
                    p.order_id = tp['order_id']
                p.save({})

                # insert node1 and node2
                p1 = Prefix()
                p1.schema = self.schema
                p1.prefix = prefix_node1
                p1.type = 'host'
                p1.description = 'Some PE router'
                p1.authoritative_source = 'nw'
                p1.save({})

                p2 = Prefix()
                p2.schema = self.schema
                p2.prefix = prefix_node2
                p2.type = 'host'
                p2.node = tp['node']
                p2.description = 'CPE'
                p2.authoritative_source = 'nw'
                p2.save({})

                return


            m = re.match(r'([^\s]+)\s*<->\s*([^\s]+)', tp['description'])
            if m is not None:
                node1 = m.group(1)
                node2 = m.group(2)
                print "Link network: ", tp['prefix'], "  ", node1, "<->", node2

                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                p.type = 'assignment'
                p.description = node1 + ' <-> ' + node2
                p.monitor = True
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                p.save({})

                # insert node1 and node2
                p1 = Prefix()
                p1.schema = self.schema
                p1.prefix = prefix_node1
                p1.type = 'host'
                p1.node = node1
                p1.description = node1
                p1.authoritative_source = 'nw'
                p1.save({})

                p2 = Prefix()
                p2.schema = self.schema
                p2.prefix = prefix_node2
                p2.type = 'host'
                p2.node = node2
                p2.description = node2
                p2.authoritative_source = 'nw'
                p2.save({})

                return

            m = re.match('(DN)[0-9]{4,}', tp['order_id'])
            if m is not None:
                print "Internal order link network", tp['prefix'], ':', tp['description']
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                p.type = 'assignment'
                p.description = tp['description']
                p.monitor = True
                p.alarm_priority = tp['alarm_priority']
                p.authoritative_source = 'nw'
                p.save({})
                return

            print "Other link network", tp['prefix'], ':', tp['description']
            p = Prefix()
            p.schema = self.schema
            p.prefix = tp['prefix']
            p.type = 'assignment'
            p.description = tp['description']
            p.monitor = True
            p.alarm_priority = tp['alarm_priority']
            p.authoritative_source = 'nw'
            p.save({})
            return

        else:
            try:
                p = Prefix()
                p.schema = self.schema
                p.prefix = tp['prefix']
                p.type = 'assignment'
                p.description = tp['description']
                p.monitor = True
                p.alarm_priority = 'low'
                p.authoritative_source = 'nw'
                p.save({})
                print "Other:", tp['prefix']
            except NipapValueError, e:
                print tp['prefix'], ':', e
                sys.exit(1)

            return