コード例 #1
0
ファイル: xhr.py プロジェクト: fredsod/NIPAP
    def edit_vrf(self, id):
        """ Edit a VRF.
        """

        try:
            v = VRF.get(int(id))
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
コード例 #2
0
ファイル: vrf.py プロジェクト: genokan/NIPAP
    def remove(self, id):
        """ Removes a VRF.
        """

        v = VRF.get(int(id))
        v.remove()

        redirect(url(controller="vrf", action="list"))
コード例 #3
0
ファイル: vrf.py プロジェクト: scoffers/NIPAPP
    def remove(self, id):
        """ Removes a VRF.
        """

        v = VRF.get(int(id))
        v.remove()

        redirect(url(controller='vrf', action='list'))
コード例 #4
0
ファイル: nipap-ro.py プロジェクト: dkhenderson2/NIPAP
 def test_find_free_prefix(self):
     """ We should be able to execute find_free_prefix as read-only user
     """
     v = VRF.get(0)
     p = Prefix.find_free(v, {
         'from-prefix': ['1.3.3.0/24'],
         'prefix_length': 27
     })
コード例 #5
0
ファイル: xhr.py プロジェクト: fredsod/NIPAP
    def edit_prefix(self, id):
        """ Edit a prefix.
        """

        try:
            p = Prefix.get(int(id))

            # extract attributes
            if 'prefix' in request.json:
                p.prefix = validate_string(request.json, 'prefix')
            if 'type' in request.json:
                p.type = validate_string(request.json, 'type')
            if 'description' in request.json:
                p.description = validate_string(request.json, 'description')
            if 'expires' in request.json:
                p.expires = validate_string(request.json, 'expires')
            if 'comment' in request.json:
                p.comment = validate_string(request.json, 'comment')
            if 'node' in request.json:
                p.node = validate_string(request.json, 'node')
            if 'status' in request.json:
                p.status = validate_string(request.json, 'status')

            if 'pool' in request.json:
                if request.json['pool'] is None:
                    p.pool = None
                else:
                    try:
                        p.pool = Pool.get(int(request.json['pool']))
                    except NipapError, e:
                        return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})

            if 'alarm_priority' in request.json:
                p.alarm_priority = validate_string(request.json, 'alarm_priority')
            if 'monitor' in request.json:
                if request.json['monitor'] == 'true':
                    p.monitor = True
                else:
                    p.monitor = False

            if 'country' in request.json:
                p.country = validate_string(request.json, 'country')
            if 'order_id' in request.json:
                p.order_id = validate_string(request.json, 'order_id')
            if 'customer_id' in request.json:
                p.customer_id = validate_string(request.json, 'customer_id')

            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__})
コード例 #6
0
ファイル: xhr.py プロジェクト: fredsod/NIPAP
    def remove_vrf(self, id):
        """ Remove a VRF.
        """

        try:
            vrf = VRF.get(int(id))
            vrf.remove()

        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
コード例 #7
0
    def edit_vrf(self, id):
        """ Edit a VRF.
        """

        try:
            v = VRF.get(int(id))
        except NipapError, e:
            return json.dumps({
                'error': 1,
                'message': e.args,
                'type': type(e).__name__
            })
コード例 #8
0
ファイル: nipaptest.py プロジェクト: Cougar/NIPAP
    def test_stats1(self):
        """ Check stats are correct when adding and removing prefixes
        """
        th = TestHelper()

        # add some top level prefixes to the default VRF
        p1 = th.add_prefix('1.0.0.0/24', 'reservation', 'test')
        p2 = th.add_prefix('2.0.0.0/24', 'reservation', 'test')
        p3 = th.add_prefix('2001:db8:1::/48', 'reservation', 'test')
        p4 = th.add_prefix('2001:db8:2::/48', 'reservation', 'test')

        # check stats for VRF
        res = VRF.get(0)
        # ipv4
        self.assertEqual(2, res.num_prefixes_v4)
        self.assertEqual(512, res.total_addresses_v4)
        self.assertEqual(0, res.used_addresses_v4)
        self.assertEqual(512, res.free_addresses_v4)
        # ipv6
        self.assertEqual(2, res.num_prefixes_v6)
        self.assertEqual(2417851639229258349412352, res.total_addresses_v6)
        self.assertEqual(0, res.used_addresses_v6)
        self.assertEqual(2417851639229258349412352, res.free_addresses_v6)

        # remove some prefixes
        p1.remove()
        p3.remove()

        # check stats for VRF
        res = VRF.get(0)
        # ipv4
        self.assertEqual(1, res.num_prefixes_v4)
        self.assertEqual(256, res.total_addresses_v4)
        self.assertEqual(0, res.used_addresses_v4)
        self.assertEqual(256, res.free_addresses_v4)
        # ipv6
        self.assertEqual(1, res.num_prefixes_v6)
        self.assertEqual(1208925819614629174706176, res.total_addresses_v6)
        self.assertEqual(0, res.used_addresses_v6)
        self.assertEqual(1208925819614629174706176, res.free_addresses_v6)
コード例 #9
0
ファイル: nipaptest.py プロジェクト: Cougar/NIPAP
    def test_stats2(self):
        """ Check stats are correct when adding and removing prefixes
        """
        th = TestHelper()

        # add some top level prefixes to the default VRF
        p1 = th.add_prefix('1.0.0.0/24', 'reservation', 'test')
        p2 = th.add_prefix('1.0.0.128/25', 'assignment', 'test')
        p3 = th.add_prefix('2001:db8:1::/48', 'reservation', 'test')
        p4 = th.add_prefix('2001:db8:1:1::/64', 'reservation', 'test')

        # check stats for VRF
        res = VRF.get(0)
        # ipv4
        self.assertEqual(2, res.num_prefixes_v4)
        self.assertEqual(256, res.total_addresses_v4)
        self.assertEqual(128, res.used_addresses_v4)
        self.assertEqual(128, res.free_addresses_v4)
        # ipv6
        self.assertEqual(2, res.num_prefixes_v6)
        self.assertEqual(1208925819614629174706176, res.total_addresses_v6)
        self.assertEqual(18446744073709551616, res.used_addresses_v6)
        self.assertEqual(1208907372870555465154560, res.free_addresses_v6)

        # remove some prefixes
        p1.remove()
        p3.remove()

        # check stats for VRF
        res = VRF.get(0)
        # ipv4
        self.assertEqual(1, res.num_prefixes_v4)
        self.assertEqual(128, res.total_addresses_v4)
        self.assertEqual(0, res.used_addresses_v4)
        self.assertEqual(128, res.free_addresses_v4)
        # ipv6
        self.assertEqual(1, res.num_prefixes_v6)
        self.assertEqual(18446744073709551616, res.total_addresses_v6)
        self.assertEqual(0, res.used_addresses_v6)
        self.assertEqual(18446744073709551616, res.free_addresses_v6)
コード例 #10
0
    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__
                })
コード例 #11
0
    def remove_vrf(self, id):
        """ Remove a VRF.
        """

        try:
            vrf = VRF.get(int(id))
            vrf.remove()

        except NipapError, e:
            return json.dumps({
                'error': 1,
                'message': e.args,
                'type': type(e).__name__
            })
コード例 #12
0
    def remove_vrf(self, id):
        """ Remove a VRF.
        """

        try:
            vrf = VRF.get(int(id))
            name = vrf.name
            vrf.remove()
            log.info('remove_vrf (%s) %s' % (session['user'], name))

        except NipapError, e:
            return json.dumps({
                'error': 1,
                'message': e.args,
                'type': type(e).__name__
            })
コード例 #13
0
ファイル: xhr.py プロジェクト: AlfredArouna/NIPAP
    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', {}))
コード例 #14
0
ファイル: xhr.py プロジェクト: fredsod/NIPAP
    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__})
コード例 #15
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', {}))
コード例 #16
0
ファイル: vrf.py プロジェクト: genokan/NIPAP
    def edit(self, id):
        """ Edit a VRF
        """

        c.action = "edit"
        c.edit_vrf = VRF.get(int(id))

        # Did we have any action passed to us?
        if "action" in request.params:

            if request.params["action"] == "edit":
                if request.params["rt"].strip() == "":
                    c.edit_vrf.rt = None
                else:
                    c.edit_vrf.rt = request.params["rt"].strip()

                if request.params["name"].strip() == "":
                    c.edit_vrf.name = None
                else:
                    c.edit_vrf.name = request.params["name"].strip()
                c.edit_vrf.description = request.params["description"]
                c.edit_vrf.save()

        return render("/vrf_edit.html")
コード例 #17
0
ファイル: vrf.py プロジェクト: scoffers/NIPAPP
    def edit(self, id):
        """ Edit a VRF
        """

        c.action = 'edit'
        c.edit_vrf = VRF.get(int(id))

        # Did we have any action passed to us?
        if 'action' in request.params:

            if request.params['action'] == 'edit':
                if request.params['rt'].strip() == '':
                    c.edit_vrf.rt = None
                else:
                    c.edit_vrf.rt = request.params['rt'].strip()

                if request.params['name'].strip() == '':
                    c.edit_vrf.name = None
                else:
                    c.edit_vrf.name = request.params['name'].strip()
                c.edit_vrf.description = request.params['description']
                c.edit_vrf.save()

        return render('/vrf_edit.html')
コード例 #18
0
    def edit_prefix(self, id):
        """ Edit a prefix.
        """

        try:
            p = Prefix.get(int(id))

            # extract attributes
            if 'prefix' in request.json:
                p.prefix = validate_string(request.json, 'prefix')
            if 'type' in request.json:
                p.type = validate_string(request.json, 'type')
            if 'description' in request.json:
                p.description = validate_string(request.json, 'description')
            if 'expires' in request.json:
                p.expires = validate_string(request.json, 'expires')
            if 'comment' in request.json:
                p.comment = validate_string(request.json, 'comment')
            if 'node' in request.json:
                p.node = validate_string(request.json, 'node')
            if 'status' in request.json:
                p.status = validate_string(request.json, 'status')

            if 'pool' in request.json:
                if request.json['pool'] is None:
                    p.pool = None
                else:
                    try:
                        p.pool = Pool.get(int(request.json['pool']))
                    except NipapError, e:
                        return json.dumps({
                            'error': 1,
                            'message': e.args,
                            'type': type(e).__name__
                        })

            if 'alarm_priority' in request.json:
                p.alarm_priority = validate_string(request.json,
                                                   'alarm_priority')
            if 'monitor' in request.json:
                if request.json['monitor'] == 'true':
                    p.monitor = True
                else:
                    p.monitor = False

            if 'country' in request.json:
                p.country = validate_string(request.json, 'country')
            if 'order_id' in request.json:
                p.order_id = validate_string(request.json, 'order_id')
            if 'customer_id' in request.json:
                p.customer_id = validate_string(request.json, 'customer_id')

            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__
                    })
コード例 #19
0
ファイル: nipap-ro.py プロジェクト: AlfredArouna/NIPAP
 def test_find_free_prefix(self):
     """ We should be able to execute find_free_prefix as read-only user
     """
     v = VRF.get(0)
     p = Prefix.find_free(v, { 'from-prefix': ['1.3.3.0/24'],
         'prefix_length': 27 })
コード例 #20
0
    def edit_prefix(self, id):
        """ Edit a prefix.
        """

        try:
            p = Prefix.get(int(id))

            # extract attributes
            if 'prefix' in request.params:
                p.prefix = request.params['prefix']

            if 'type' in request.params:
                p.type = request.params['type'].strip()

            if 'description' in request.params:
                if request.params['description'].strip() == '':
                    p.description = None
                else:
                    p.description = request.params['description'].strip()

            if 'comment' in request.params:
                if request.params['comment'].strip() == '':
                    p.comment = None
                else:
                    p.comment = request.params['comment'].strip()

            if 'node' in request.params:
                if request.params['node'].strip() == '':
                    p.node = None
                else:
                    p.node = request.params['node'].strip()

            if 'pool' in request.params:
                if request.params['pool'].strip() == '':
                    p.pool = None
                else:
                    try:
                        p.pool = Pool.get(int(request.params['pool']))
                    except NipapError, e:
                        return json.dumps({
                            'error': 1,
                            'message': e.args,
                            'type': type(e).__name__
                        })

            if 'alarm_priority' in request.params:
                p.alarm_priority = request.params['alarm_priority'].strip()

            if 'monitor' in request.params:
                if request.params['monitor'] == 'true':
                    p.monitor = True
                else:
                    p.monitor = False

            if 'country' in request.params:
                if request.params['country'].strip() == '':
                    p.country = None
                else:
                    p.country = request.params['country'].strip()

            if 'order_id' in request.params:
                if request.params['order_id'].strip() == '':
                    p.order_id = None
                else:
                    p.order_id = request.params['order_id'].strip()

            if 'customer_id' in request.params:
                if request.params['customer_id'].strip() == '':
                    p.customer_id = None
                else:
                    p.customer_id = request.params['customer_id'].strip()

            if 'vrf' in request.params:

                try:
                    if request.params['vrf'] is None or len(
                            request.params['vrf']) == 0:
                        p.vrf = None
                    else:
                        p.vrf = VRF.get(int(request.params['vrf']))
                except ValueError:
                    return json.dumps({
                        'error':
                        1,
                        'message':
                        "Invalid VRF ID '%s'" % request.params['vrf']
                    })
                except NipapError, e:
                    return json.dumps({
                        'error': 1,
                        'message': e.args,
                        'type': type(e).__name__
                    })
コード例 #21
0
ファイル: xhr.py プロジェクト: AlfredArouna/NIPAP
    def edit_prefix(self, id):
        """ Edit a prefix.
        """

        try:
            p = Prefix.get(int(id))

            # extract attributes
            if 'prefix' in request.params:
                p.prefix = request.params['prefix']

            if 'type' in request.params:
                p.type = request.params['type'].strip()

            if 'description' in request.params:
                if request.params['description'].strip() == '':
                    p.description = None
                else:
                    p.description = request.params['description'].strip()

            if 'expires' in request.params:
                if request.params['expires'].strip() == '':
                    p.expires = None
                else:
                    p.expires = request.params['expires'].strip(' "')

            if 'comment' in request.params:
                if request.params['comment'].strip() == '':
                    p.comment = None
                else:
                    p.comment = request.params['comment'].strip()

            if 'node' in request.params:
                if request.params['node'].strip() == '':
                    p.node = None
                else:
                    p.node = request.params['node'].strip()

            if 'status' in request.params:
                p.status = request.params['status'].strip()

            if 'pool' in request.params:
                if request.params['pool'].strip() == '':
                    p.pool = None
                else:
                    try:
                        p.pool = Pool.get(int(request.params['pool']))
                    except NipapError, e:
                        return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})

            if 'alarm_priority' in request.params:
                p.alarm_priority = request.params['alarm_priority'].strip()

            if 'monitor' in request.params:
                if request.params['monitor'] == 'true':
                    p.monitor = True
                else:
                    p.monitor = False

            if 'country' in request.params:
                if request.params['country'].strip() == '':
                    p.country = None
                else:
                    p.country = request.params['country'].strip()

            if 'order_id' in request.params:
                if request.params['order_id'].strip() == '':
                    p.order_id = None
                else:
                    p.order_id = request.params['order_id'].strip()

            if 'customer_id' in request.params:
                if request.params['customer_id'].strip() == '':
                    p.customer_id = None
                else:
                    p.customer_id = request.params['customer_id'].strip()

            if 'vrf' in request.params:

                try:
                    if request.params['vrf'] is None or len(request.params['vrf']) == 0:
                        p.vrf = None
                    else:
                        p.vrf = VRF.get(int(request.params['vrf']))
                except ValueError:
                    return json.dumps({'error': 1, 'message': "Invalid VRF ID '%s'" % request.params['vrf']})
                except NipapError, e:
                    return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
コード例 #22
0
ファイル: nipap-ro.py プロジェクト: scoffers/NIPAPP
 def test_list_vrf(self):
     """ We should be able to execute list_vrf as read-only user
     """
     v = VRF.get(0)
     self.assertEqual(v.id, 0)