Beispiel #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()
Beispiel #2
0
 def test_edit_vrf(self):
     """ We should NOT be able to execute edit_vrf as read-only user
     """
     v = VRF()
     v.id = 123
     with self.assertRaises(NipapAuthorizationError):
         v.save()
Beispiel #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__
            })
Beispiel #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__
            })
Beispiel #5
0
 def test_remove_vrf(self):
     """ We should NOT be able to execute remove_vrf as read-only user
     """
     v = VRF()
     v.id = 0
     with self.assertRaises(NipapAuthorizationError):
         v.remove()
Beispiel #6
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()
Beispiel #7
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
Beispiel #8
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')
Beispiel #9
0
    def add_current_vrf(self):
        """ Add VRF to filter list session variable
        """

        vrf_id = request.params.get('vrf_id')

        if vrf_id is not None:

            if vrf_id == 'null':
                vrf = VRF()
            else:
                vrf = VRF.get(int(vrf_id))

            session['current_vrfs'][vrf_id] = {
                'id': vrf.id,
                'rt': vrf.rt,
                'name': vrf.name,
                'description': vrf.description
            }
            session.save()

        return json.dumps(session.get('current_vrfs', {}))
Beispiel #10
0
                          ar['full_name'], ar['description']))

    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: