List prefixes matching the `spec`.

            * `auth` [BaseAuth]
                AAA options.
            * `spec` [prefix_spec]
                Specifies prefixes to list. If omitted, all will be listed.

            Returns a list of dicts.

            This is a quite blunt tool for finding prefixes, mostly useful for
            fetching data about a single prefix. For more capable alternatives,
            see the :func:`search_prefix` or :func:`smart_search_prefix` functions.

            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.list_prefix` for full
            understanding.

def list_prefix(self, auth, spec = None):
        """ List prefixes matching the `spec`.

            * `auth` [BaseAuth]
                AAA options.
            * `spec` [prefix_spec]
                Specifies prefixes to list. If omitted, all will be listed.

            Returns a list of dicts.

            This is a quite blunt tool for finding prefixes, mostly useful for
            fetching data about a single prefix. For more capable alternatives,
            see the :func:`search_prefix` or :func:`smart_search_prefix` functions.

            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.list_prefix` for full
            understanding.
        """

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


        if type(spec) is dict:
            where, params = self._expand_prefix_spec(spec.copy(), 'inp.')
        else:
            raise NipapError("invalid prefix specification")

        if where != '':
            where = ' WHERE ' + where

        sql = """SELECT
            inp.id,
            vrf.id AS vrf_id,
            vrf.rt AS vrf_rt,
            vrf.name AS vrf_name,
            family(prefix) AS family,
            inp.prefix,
            inp.display_prefix,
            inp.description,
            COALESCE(inp.inherited_tags, '{}') AS inherited_tags,
            COALESCE(inp.tags, '{}') AS tags,
            inp.node,
            inp.comment,
            pool.id AS pool_id,
            pool.name AS pool_name,
            inp.type,
            inp.indent,
            inp.country,
            inp.order_id,
            inp.customer_id,
            inp.external_key,
            inp.authoritative_source,
            inp.alarm_priority,
            inp.monitor,
            inp.vlan,
            inp.added,
            inp.last_modified,
            inp.total_addresses,
            inp.used_addresses,
            inp.free_addresses,
            inp.status,
            inp.avps,
            inp.expires
            FROM ip_net_plan inp
            JOIN ip_net_vrf vrf ON (inp.vrf_id = vrf.id)
            LEFT JOIN ip_net_pool pool ON (inp.pool_id = pool.id) %s
            ORDER BY vrf.rt NULLS FIRST, prefix""" % where

        self._execute(sql, params)

        res = list()
        for row in self._curs_pg:
            pref = dict(row)
            pref['display_prefix'] = unicode(pref['display_prefix'])
            res.append(pref)

        return res