Ejemplo n.º 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()
Ejemplo n.º 2
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')

        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.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()
Ejemplo n.º 3
0
    def add_vrf(self):
        """ Add a new VRF to NIPAP and return its data.
        """

        v = VRF()
        if 'rt' in request.json:
            v.rt = validate_string(request.json, 'rt')
        if 'name' in request.json:
            v.name = validate_string(request.json, 'name')
        if 'description' in request.json:
            v.description = validate_string(request.json, 'description')
        if 'tags' in request.json:
            v.tags = request.json['tags']
        if 'avps' in request.json:
            v.avps = request.json['avps']

        try:
            v.save()
            log.info('add_vrf (%s) %s' % (session['user'], request.json))
        except NipapError, e:
            return json.dumps({
                'error': 1,
                'message': e.args,
                'type': type(e).__name__
            })
Ejemplo n.º 4
0
    def add_vrf(self):
        """ Add a new VRF to NIPAP and return its data.
        """

        v = VRF()
        if 'rt' in request.params:
            if request.params['rt'].strip() != '':
                v.rt = request.params['rt'].strip()
        if 'name' in request.params:
            if request.params['name'].strip() != '':
                v.name = request.params['name'].strip()
        if 'description' in request.params:
            v.description = request.params['description']
        if 'tags' in request.params:
            v.tags = json.loads(request.params['tags'])

        if 'avps' in request.params:
            v.avps = json.loads(request.params['avps'])

        try:
            v.save()
        except NipapError, e:
            return json.dumps({
                'error': 1,
                'message': e.args,
                'type': type(e).__name__
            })
Ejemplo n.º 5
0
 def test_add_vrf(self):
     """ We should NOT be able to execute add_vrf as read-only user
     """
     v = VRF()
     v.rt = '123:456'
     v.name = 'test'
     with self.assertRaises(NipapAuthorizationError):
         v.save()
Ejemplo n.º 6
0
    def add_vrf(self, name, rt, description, tags=[]):

        try:
            vrf = VRF()
            vrf.rt = rt
            vrf.name = name
            vrf.description = description
            vrf.tags = tags
            vrf.save()
            return vrf
        except NipapError as exc:
            print("Error: could not add vrf to NIPAP: %s" % str(exc))
            return None
Ejemplo n.º 7
0
Archivo: xhr.py Proyecto: sohonet/NIPAP
    def add_vrf(self):
        """ Add a new VRF to NIPAP and return its data.
        """

        v = VRF()
        if 'rt' in request.params:
            if request.params['rt'].strip() != '':
                v.rt = request.params['rt'].strip()
        if 'name' in request.params:
            if request.params['name'].strip() != '':
                v.name = request.params['name'].strip()
        if 'description' in request.params:
            v.description = request.params['description']

        try:
            v.save()
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
Ejemplo n.º 8
0
Archivo: vrf.py Proyecto: genokan/NIPAP
    def add(self):
        """ Add a new VRF.
        """

        c.action = "add"

        if "action" in request.params:
            if request.params["action"] == "add":
                v = VRF()
                if request.params["rt"].strip() != "":
                    v.rt = request.params["rt"]
                if request.params["name"].strip() != "":
                    v.name = request.params["name"]
                v.description = request.params["description"]

                v.save()
                redirect(url(controller="vrf", action="list"))

        return render("/vrf_add.html")
Ejemplo n.º 9
0
    def add(self):
        """ Add a new VRF.
        """

        c.action = 'add'

        if 'action' in request.params:
            if request.params['action'] == 'add':
                v = VRF()
                if request.params['rt'].strip() != '':
                    v.rt = request.params['rt']
                if request.params['name'].strip() != '':
                    v.name = request.params['name']
                v.description = request.params['description']

                v.save()
                redirect(url(controller='vrf', action='list'))

        return render('/vrf_add.html')
Ejemplo n.º 10
0
Archivo: xhr.py Proyecto: fredsod/NIPAP
    def add_vrf(self):
        """ Add a new VRF to NIPAP and return its data.
        """

        v = VRF()
        if 'rt' in request.json:
            v.rt = validate_string(request.json, 'rt')
        if 'name' in request.json:
            v.name = validate_string(request.json, 'name')
        if 'description' in request.json:
            v.description = validate_string(request.json, 'description')
        if 'tags' in request.json:
            v.tags = request.json['tags']
        if 'avps' in request.json:
            v.avps = request.json['avps']

        try:
            v.save()
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
Ejemplo n.º 11
0
    print "done"

    # Create VRFs from Schemas
    print "Creating VRFs from Schemas... ",
    sql = "SELECT * FROM ip_net_schema"
    curs_pg_old.execute(sql)
    vrfs = {}
    s_vrfs = {}
    for r in curs_pg_old:
        if r['vrf'] is None:
            continue

        if re.match('\d+:\d+', r['vrf'].strip()):
            v = VRF()
            v.rt = r['vrf'].strip()
            v.name = r['name'].strip()
            try:
                v.save()
            except NipapError, e:
                print "ERR: %s" % str(e)
            vrfs[v.rt] = v
            s_vrfs[r['id']] = v
    print "done"


    # Create VRFs from prefixes
    print "Creating VRFs from Prefixes... ",
    sql = "SELECT DISTINCT(vrf) FROM ip_net_plan WHERE vrf IS NOT NULL"
    curs_pg_old.execute(sql)
    for r in curs_pg_old:
Ejemplo n.º 12
0
    print "done"

    # Create VRFs from Schemas
    print "Creating VRFs from Schemas... ",
    sql = "SELECT * FROM ip_net_schema"
    curs_pg_old.execute(sql)
    vrfs = {}
    s_vrfs = {}
    for r in curs_pg_old:
        if r['vrf'] is None:
            continue

        if re.match('\d+:\d+', r['vrf'].strip()):
            v = VRF()
            v.rt = r['vrf'].strip()
            v.name = r['name'].strip()
            try:
                v.save()
            except NipapError, e:
                print "ERR: %s" % str(e)
            vrfs[v.rt] = v
            s_vrfs[r['id']] = v
    print "done"

    # Create VRFs from prefixes
    print "Creating VRFs from Prefixes... ",
    sql = "SELECT DISTINCT(vrf) FROM ip_net_plan WHERE vrf IS NOT NULL"
    curs_pg_old.execute(sql)
    for r in curs_pg_old:
        if re.match('^\d+:\d+$', r['vrf'].strip()):