Exemple #1
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__})
Exemple #2
0
    def remove_prefix(self, id):
        """ Remove a prefix.
        """

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

        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
Exemple #3
0
    def edit(self, id):
        """ Edit a prefix.
        """

        # find prefix
        c.prefix = Prefix.get(int(id))

        # we got a HTTP POST - edit object
        if request.method == 'POST':
            c.prefix.prefix = request.params['prefix_prefix']
            c.prefix.description = request.params['prefix_description']

            if request.params['prefix_node'].strip() == '':
                c.prefix.node = None
            else:
                c.prefix.node = request.params['prefix_node']

            if request.params['prefix_country'].strip() == '':
                c.prefix.country = None
            else:
                c.prefix.country = request.params['prefix_country']

            if request.params['prefix_comment'].strip() == '':
                c.prefix.comment = None
            else:
                c.prefix.comment = request.params['prefix_comment']

            if request.params['prefix_order_id'].strip() == '':
                c.prefix.order_id = None
            else:
                c.prefix.order_id = request.params['prefix_order_id']

            if request.params['prefix_customer_id'].strip() == '':
                c.prefix.customer_id = None
            else:
                c.prefix.customer_id = request.params['prefix_customer_id']

            if request.params['prefix_vrf'].strip() == '':
                c.prefix.vrf = None
            else:
                # TODO: handle non-existent VRF...
                c.prefix.vrf = VRF.list({ 'rt': request.params['prefix_vrf'] })[0]

            if request.params.get('prefix_monitor') is not None:
                c.prefix.monitor = True
            else:
                c.prefix.monitor = False

            c.prefix.alarm_priority = request.params['prefix_alarm_priority']
            c.prefix.save()
            redirect(url(controller='prefix', action='list'))


        return render('/prefix_edit.html')
Exemple #4
0
    def remove_prefix(self, id):
        """ Remove a prefix from pool 'id'.
        """

        if 'prefix' not in request.params:
            abort(400, 'Missing prefix.')
        prefix = Prefix.get(int(request.params['prefix']))
        prefix.pool = None
        prefix.save()

        redirect(url(controller = 'pool', action = 'edit', id = id))
Exemple #5
0
    def remove_prefix(self):
        """ Remove a prefix.
        """

        try:
            schema = Schema.get(int(request.params['schema']))
            p = Prefix.get(schema, int(request.params['id']))
            p.remove()

        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
Exemple #6
0
    def remove(self, id):
        """ Remove a prefix.
        """

        # find prefix
        c.prefix = Prefix.get(int(id))

        if 'confirmed' not in request.params:
            return render('/prefix_remove_confirm.html')

        c.prefix.remove()
        redirect(url(controller='prefix', action='list'))
Exemple #7
0
    def add_prefix(self, id):
        """ Add a prefix to pool 'id'
        """

        if 'prefix' not in request.params:
            abort(400, 'Missing prefix.')

        pool = Pool.get(int(id))

        prefix = Prefix.get(int(request.params['prefix']))
        prefix.pool = pool
        prefix.save()

        redirect(url(controller = 'pool', action = 'edit', id = id))
Exemple #8
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 '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__})
Exemple #9
0
 def test_list_prefix(self):
     """ We should be able to execute list_prefix as read-only user
     """
     with self.assertRaises(NipapNonExistentError):
         p = Prefix.get(0)
Exemple #10
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__
                    })
Exemple #11
0
    def edit_prefix(self, id):
        """ Edit a prefix.
        """

        try:
            schema = Schema.get(int(request.params['schema']))

            p = Prefix.get(schema, int(id))

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

            if 'description' in request.params:
                p.description = request.params['description']

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

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

            if 'pool' in request.params:
                if request.params['pool'].strip() == '':
                    p.pool = None
                else:
                    p.pool = Pool.get(schema, int(request.params['pool']))

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

            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']

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

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

            p.save()

        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
Exemple #12
0
        return render('/prefix_add.html')



    def edit(self, id):
        """ Edit a prefix.
        """

        # make sure we have a schema
        try:
            c.schema = Schema.get(int(request.params['schema']))
        except (KeyError, NipapNonExistentError), e:
            redirect(url(controller = 'schema', action = 'list'))

        # find prefix
        c.prefix = Prefix.get(c.schema, int(id))

        # we got a HTTP POST - edit object
        if request.method == 'POST':
            c.prefix.prefix = request.params['prefix_prefix']
            c.prefix.description = request.params['prefix_description']

            if request.params['prefix_node'].strip() == '':
                c.prefix.node = None
            else:
                c.prefix.node = request.params['prefix_node']

            if request.params['prefix_country'].strip() == '':
                c.prefix.country = None
            else:
                c.prefix.country = request.params['prefix_country']
Exemple #13
0
 def test_list_prefix(self):
     """ We should be able to execute list_prefix as read-only user
     """
     with self.assertRaises(NipapNonExistentError):
         p = Prefix.get(0)