Remove prefix matching `spec`.

            * `auth` [BaseAuth]
                AAA options.
            * `spec` [prefix_spec]
                Specifies prefixe to remove.
            * `recursive` [bool]
                When set to True, also remove child prefixes.

            This is the documentation of the internal backend function. It's
            exposed over XML-RPC, please also see the XML-RPC documentation for
            :py:func:`nipap.xmlrpc.NipapXMLRPC.remove_prefix` for full
            understanding.

def remove_prefix(self, auth, spec, recursive = False):
        """ Remove prefix matching `spec`.

            * `auth` [BaseAuth]
                AAA options.
            * `spec` [prefix_spec]
                Specifies prefixe to remove.
            * `recursive` [bool]
                When set to True, also remove child prefixes.

            This is the documentation of the internal backend function. It's
            exposed over XML-RPC, please also see the XML-RPC documentation for
            :py:func:`nipap.xmlrpc.NipapXMLRPC.remove_prefix` for full
            understanding.
        """

        self._logger.debug("remove_prefix called; spec: %s" % unicode(spec))

        # sanity check - do we have all attributes?
        if 'id' in spec:
            # recursive requires a prefix, so translate id to prefix
            p = self.list_prefix(auth, spec)[0]
            del spec['id']
            spec['prefix'] = p['prefix']
            spec['vrf_id'] = p['vrf_id']
        elif 'prefix' in spec:
            pass
        else:
            raise NipapMissingInputError('missing prefix or id of prefix')

        prefixes = self.list_prefix(auth, spec)

        if recursive:
            spec['type'] = 'host'
            self._db_remove_prefix(spec, recursive)
            del spec['type']
            self._db_remove_prefix(spec, recursive)
        else:
            self._db_remove_prefix(spec)

        # write to audit table
        audit_params = {
            'username': auth.username,
            'authenticated_as': auth.authenticated_as,
            'full_name': auth.full_name,
            'authoritative_source': auth.authoritative_source
        }
        for p in prefixes:
            audit_params['prefix_id'] = p['id']
            audit_params['prefix_prefix'] = p['prefix']
            audit_params['description'] = 'Removed prefix %s' % p['prefix']
            audit_params['vrf_id'] = p['vrf_id']
            audit_params['vrf_rt'] = p['vrf_rt']
            audit_params['vrf_name'] = p['vrf_name']
            sql, params = self._sql_expand_insert(audit_params)
            self._execute('INSERT INTO ip_net_log %s' % sql, params)

            if p['pool_id'] is not None:
                pool = self._get_pool(auth, { 'id': p['pool_id'] })
                audit_params2 = {
                    'pool_id': pool['id'],
                    'pool_name': pool['name'],
                    'prefix_id': p['id'],
                    'prefix_prefix': p['prefix'],
                    'description': 'Prefix %s removed from pool %s' % (p['prefix'], pool['name']),
                    'username': auth.username,
                    'authenticated_as': auth.authenticated_as,
                    'full_name': auth.full_name,
                    'authoritative_source': auth.authoritative_source
                }
                sql, params = self._sql_expand_insert(audit_params2)
                self._execute('INSERT INTO ip_net_log %s' % sql, params)