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.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 __HOLE__:
                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__})

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

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

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

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

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

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

        if 'pool' in request.params:
            if request.params['pool'].strip() != '':
                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 'country' in request.params:
            if request.params['country'].strip() != '':
                p.country = request.params['country'].strip()

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

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

        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 'vlan' in request.params:
            if request.params['vlan'].strip() != '':
                p.vlan = request.params['vlan']

        if 'tags' in request.params:
            p.tags = json.loads(request.params['tags'])

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

        # arguments
        args = {}
        if 'from_prefix[]' in request.params:
            args['from-prefix'] = request.params.getall('from_prefix[]')
        if 'from_pool' in request.params:
            try:
                args['from-pool'] = Pool.get(int(request.params['from_pool']))
            except NipapError, e:
                return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
        if 'family' in request.params:
            args['family'] = request.params['family']
        if 'prefix_length' in request.params:
            args['prefix_length'] = request.params['prefix_length']

        # manual allocation?
        if args == {}:
            if 'prefix' in request.params:
                p.prefix = request.params['prefix']

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

        return json.dumps(p, cls=NipapJSONEncoder)
dataset/ETHPy150Open SpriteLink/NIPAP/nipap-www/nipapwww/controllers/xhr.py/XhrController.add_prefix