示例#1
0
    def test_load_data(self):
        """
        """
        th = TestHelper()
        p1 = th.add_prefix('192.168.0.0/16', 'reservation', 'test')
        p2 = th.add_prefix('192.168.0.0/20', 'reservation', 'test')
        p3 = th.add_prefix('192.168.0.0/24', 'reservation', 'test')
        p4 = th.add_prefix('192.168.1.0/24', 'reservation', 'test')
        p5 = th.add_prefix('192.168.2.0/24', 'reservation', 'test')
        p6 = th.add_prefix('192.168.32.0/20', 'reservation', 'test')
        p7 = th.add_prefix('192.168.32.0/24', 'reservation', 'test')
        p8 = th.add_prefix('192.168.32.1/32', 'reservation', 'test')

        ps1 = th.add_prefix('2001:db8:1::/48', 'reservation', 'test')
        ps2 = th.add_prefix('2001:db8:1::/64', 'reservation', 'test')
        ps3 = th.add_prefix('2001:db8:2::/48', 'reservation', 'test')

        pool1 = Pool()
        pool1.name = 'upgrade-test'
        pool1.ipv4_default_prefix_length = 31
        pool1.ipv6_default_prefix_length = 112
        pool1.save()
        p2.pool = pool1
        p2.save()
        ps1.pool = pool1
        ps1.save()

        pool2 = Pool()
        pool2.name = 'upgrade-test2'
        pool2.save()

        vrf1 = VRF()
        vrf1.name = 'foo'
        vrf1.rt = '123:123'
        vrf1.save()
示例#2
0
    def add_pool(self):
        """ Add a pool.
        """

        # extract attributes
        p = Pool()
        p.name = request.params.get('name')
        p.description = request.params.get('description')
        p.default_type = request.params.get('default_type')
        if 'ipv4_default_prefix_length' in request.params:
            if request.params['ipv4_default_prefix_length'].strip() != '':
                p.ipv4_default_prefix_length = request.params[
                    'ipv4_default_prefix_length']
        if 'ipv6_default_prefix_length' in request.params:
            if request.params['ipv6_default_prefix_length'].strip() != '':
                p.ipv6_default_prefix_length = request.params[
                    'ipv6_default_prefix_length']

        try:
            p.save()
        except NipapError, e:
            return json.dumps({
                'error': 1,
                'message': e.args,
                'type': type(e).__name__
            })
示例#3
0
文件: xhr.py 项目: fredsod/NIPAP
    def add_pool(self):
        """ Add a pool.
        """

        # extract attributes
        p = Pool()
        if 'name' in request.json:
            p.name = validate_string(request.json, 'name')
        if 'description' in request.json:
            p.description = validate_string(request.json, 'description')
        if 'default_type' in request.json:
            p.default_type = validate_string(request.json, 'default_type')
        # TODO: handle integers
        if 'ipv4_default_prefix_length' in request.json:
            p.ipv4_default_prefix_length = request.json['ipv4_default_prefix_length']
        if 'ipv6_default_prefix_length' in request.json:
            p.ipv6_default_prefix_length = request.json['ipv6_default_prefix_length']
        if 'tags' in request.json:
            p.tags = request.json['tags']
        if 'avps' in request.json:
            p.avps = request.json['avps']

        try:
           p.save()
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
示例#4
0
    def add_pool(self):
        """ Add a pool.
        """

        # extract attributes
        p = Pool()
        if 'name' in request.json:
            p.name = validate_string(request.json, 'name')
        if 'description' in request.json:
            p.description = validate_string(request.json, 'description')
        if 'default_type' in request.json:
            p.default_type = validate_string(request.json, 'default_type')
        # TODO: handle integers
        if 'ipv4_default_prefix_length' in request.json:
            p.ipv4_default_prefix_length = request.json[
                'ipv4_default_prefix_length']
        if 'ipv6_default_prefix_length' in request.json:
            p.ipv6_default_prefix_length = request.json[
                'ipv6_default_prefix_length']
        if 'tags' in request.json:
            p.tags = request.json['tags']
        if 'avps' in request.json:
            p.avps = request.json['avps']

        try:
            p.save()
        except NipapError, e:
            return json.dumps({
                'error': 1,
                'message': e.args,
                'type': type(e).__name__
            })
示例#5
0
    def test_load_data(self):
        """
        """
        th = TestHelper()
        p1 = th.add_prefix('192.168.0.0/16', 'reservation', 'test')
        p2 = th.add_prefix('192.168.0.0/20', 'reservation', 'test')
        p3 = th.add_prefix('192.168.0.0/24', 'reservation', 'test')
        p4 = th.add_prefix('192.168.1.0/24', 'reservation', 'test')
        p5 = th.add_prefix('192.168.2.0/24', 'reservation', 'test')
        p6 = th.add_prefix('192.168.32.0/20', 'reservation', 'test')
        p7 = th.add_prefix('192.168.32.0/24', 'reservation', 'test')
        p8 = th.add_prefix('192.168.32.1/32', 'reservation', 'test')

        ps1 = th.add_prefix('2001:db8:1::/48', 'reservation', 'test')
        ps2 = th.add_prefix('2001:db8:1::/64', 'reservation', 'test')
        ps3 = th.add_prefix('2001:db8:2::/48', 'reservation', 'test')

        pool1 = Pool()
        pool1.name = 'upgrade-test'
        pool1.ipv4_default_prefix_length = 31
        pool1.ipv6_default_prefix_length = 112
        pool1.save()
        p2.pool = pool1
        p2.save()
        ps1.pool = pool1
        ps1.save()

        pool2 = Pool()
        pool2.name = 'upgrade-test2'
        pool2.save()

        vrf1 = VRF()
        vrf1.name = 'foo'
        vrf1.rt = '123:123'
        vrf1.save()
示例#6
0
文件: pool.py 项目: tobbakko/NIPAP
    def add(self):
        """ Add a pool.
        """

        if 'schema' not in request.params:
            redirect(url(controller = 'schema', action = 'list'))
        c.schema = Schema.get(int(request.params['schema']))

        # Adding to NIPAP
        if request.method == 'POST':
            p = Pool()
            p.schema = c.schema
            p.name = request.params.get('name')
            p.description = request.params.get('description')
            p.default_type = request.params.get('default_type')

            if request.params['ipv4_default_prefix_length'].strip() != '':
                p.ipv4_default_prefix_length = request.params['ipv4_default_prefix_length']

            if request.params['ipv6_default_prefix_length'].strip() != '':
                p.ipv6_default_prefix_length = request.params['ipv6_default_prefix_length']

            p.save()
            redirect(url(controller = 'pool', action = 'list', schema = c.schema.id))

        return render("/pool_add.html")
示例#7
0
文件: nipaptest.py 项目: Cougar/NIPAP
 def add_pool(self, name, default_type, ipv4_default_prefix_length, ipv6_default_prefix_length):
     pool = Pool()
     pool.name = name
     pool.default_type = default_type
     pool.ipv4_default_prefix_length = ipv4_default_prefix_length
     pool.ipv6_default_prefix_length = ipv6_default_prefix_length
     pool.save()
     return pool
示例#8
0
 def add_pool(self, name, description, default_type, ipv4_default_prefix_length):
     pool = Pool()
     pool.name = name
     pool.description = description
     pool.default_type = default_type
     pool.ipv4_default_prefix_length = ipv4_default_prefix_length
     try:
         pool.save()
         return pool
     except NipapError as exc:
         print("Error: could not add pool to NIPAP: %s" % str(exc))
         return None
示例#9
0
def add_pool(arg, opts):
    """ Add a pool.
    """

    p = Pool()
    p.schema = get_schema(opts.get('schema'))
    p.name = opts.get('name')
    p.description = opts.get('description')
    p.default_type = opts.get('default-type')
    p.ipv4_default_prefix_length = opts.get('ipv4_default_prefix_length')
    p.ipv6_default_prefix_length = opts.get('ipv6_default_prefix_length')

    try:
        p.save()
    except pynipap.NipapError, e:
        print >> sys.stderr, "Could not add pool to NIPAP: %s" % e.message
        sys.exit(1)
示例#10
0
文件: xhr.py 项目: sohonet/NIPAP
    def add_pool(self):
        """ Add a pool.
        """

        # extract attributes
        p = Pool()
        p.name = request.params.get('name')
        p.description = request.params.get('description')
        p.default_type = request.params.get('default_type')
        if 'ipv4_default_prefix_length' in request.params:
            if request.params['ipv4_default_prefix_length'].strip() != '':
                p.ipv4_default_prefix_length = request.params['ipv4_default_prefix_length']
        if 'ipv6_default_prefix_length' in request.params:
            if request.params['ipv6_default_prefix_length'].strip() != '':
                p.ipv6_default_prefix_length = request.params['ipv6_default_prefix_length']

        try:
           p.save()
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
示例#11
0
    def add(self):
        """ Add a pool.
        """

        # Adding to NIPAP
        if request.method == 'POST':
            p = Pool()
            p.name = request.params.get('name')
            p.description = request.params.get('description')
            p.default_type = request.params.get('default_type')

            if request.params['ipv4_default_prefix_length'].strip() != '':
                p.ipv4_default_prefix_length = request.params[
                    'ipv4_default_prefix_length']

            if request.params['ipv6_default_prefix_length'].strip() != '':
                p.ipv6_default_prefix_length = request.params[
                    'ipv6_default_prefix_length']

            p.save()
            redirect(url(controller='pool', action='list'))

        return render("/pool_add.html")
示例#12
0
文件: convert.py 项目: Cougar/NIPAP
    pynipap.xmlrpc_uri = nipapd_xmlrpc_uri


    #
    # Create pools
    #
    print "Creating pools... ",
    sql = "SELECT * FROM ip_net_pool"
    curs_pg_old.execute(sql)
    pools = {}
    for r in curs_pg_old:
        p = Pool()
        p.name = r['name']
        p.description = r['description']
        p.default_type = r['default_type']
        p.ipv4_default_prefix_length = r['ipv4_default_prefix_length']
        p.ipv6_default_prefix_length = r['ipv6_default_prefix_length']
        try:
            p.save()
        except NipapError, e:
            print "ERR: %s" % str(e)
        pools[r['id']] = p

        # remove new audit log entries
        sql = "DELETE FROM ip_net_log WHERE pool_id = %s"
        curs_pg_new.execute(sql, ( p.id, ))

        # fetch old audit log entries
        sql = "SELECT * FROM ip_net_log WHERE pool = %s AND prefix IS NULL"
        curs_pg_old2.execute(sql, ( r['id'], ))
        for ar in curs_pg_old2:
示例#13
0
    aopts = pynipap.AuthOptions({'authoritative_source': 'nipap'})
    pynipap.xmlrpc_uri = nipapd_xmlrpc_uri

    #
    # Create pools
    #
    print "Creating pools... ",
    sql = "SELECT * FROM ip_net_pool"
    curs_pg_old.execute(sql)
    pools = {}
    for r in curs_pg_old:
        p = Pool()
        p.name = r['name']
        p.description = r['description']
        p.default_type = r['default_type']
        p.ipv4_default_prefix_length = r['ipv4_default_prefix_length']
        p.ipv6_default_prefix_length = r['ipv6_default_prefix_length']
        try:
            p.save()
        except NipapError, e:
            print "ERR: %s" % str(e)
        pools[r['id']] = p

        # remove new audit log entries
        sql = "DELETE FROM ip_net_log WHERE pool_id = %s"
        curs_pg_new.execute(sql, (p.id, ))

        # fetch old audit log entries
        sql = "SELECT * FROM ip_net_log WHERE pool = %s AND prefix IS NULL"
        curs_pg_old2.execute(sql, (r['id'], ))
        for ar in curs_pg_old2:
示例#14
0
文件: xhr.py 项目: tobbakko/NIPAP
        """

        try:
            c.schema = Schema.get(int(request.params.get('schema')))
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})

        # extract attributes
        p = Pool()
        p.schema = c.schema
        p.name = request.params.get('name')
        p.description = request.params.get('description')
        p.default_type = request.params.get('default_type')
        if 'ipv4_default_prefix_length' in request.params:
            if request.params['ipv4_default_prefix_length'].strip() != '':
                p.ipv4_default_prefix_length = request.params['ipv4_default_prefix_length']
        if 'ipv6_default_prefix_length' in request.params:
            if request.params['ipv6_default_prefix_length'].strip() != '':
                p.ipv6_default_prefix_length = request.params['ipv6_default_prefix_length']

        try:
           p.save()
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})

        return json.dumps(p, cls=NipapJSONEncoder)



    def edit_pool(self, id):
        """ Edit a pool.