def get_all(self, context, search_opts=None):
    check_policy(context, 'get_all')
    if (search_opts is None):
        search_opts = {}
    if (context.is_admin and ('all_tenants' in search_opts)):
        del search_opts['all_tenants']
        volumes = self.db.volume_get_all(context)
    else:
        volumes = self.db.volume_get_all_by_project(context, context.project_id)
    if search_opts:
        LOG.debug((_('Searching by: %s') % str(search_opts)))

        def _check_metadata_match(volume, searchdict):
            volume_metadata = {}
            for i in volume.get('volume_metadata'):
                volume_metadata[i['key']] = i['value']
            for (k, v) in searchdict.iteritems():
                if ((k not in volume_metadata.keys()) or (volume_metadata[k] != v)):
                    return False
            return True
        filter_mapping = {'metadata': _check_metadata_match}
        result = []
        for volume in volumes:
            for (opt, values) in search_opts.iteritems():
                try:
                    filter_func = filter_mapping[opt]
                except KeyError:
                    continue
                else:
                    if filter_func(volume, values):
                        result.append(volume)
                        break
        volumes = result
    return volumes
def get_all(self, context, search_opts=None):
    check_policy(context, 'get_all')
    if (search_opts is None):
        search_opts = {}
    if (context.is_admin and ('all_tenants' in search_opts)):
        del search_opts['all_tenants']
        volumes = self.db.volume_get_all(context)
    else:
        volumes = self.db.volume_get_all_by_project(context, context.project_id)
    if search_opts:
        LOG.debug((_('Searching by: %s') % str(search_opts)))

        def _check_metadata_match(volume, searchdict):
            volume_metadata = {}
            for i in volume.get('volume_metadata'):
                volume_metadata[i['key']] = i['value']
            for (k, v) in searchdict.iteritems():
                if ((k not in volume_metadata.keys()) or (volume_metadata[k] != v)):
                    return False
            return True
        filter_mapping = {'metadata': _check_metadata_match}
        result = []
        for volume in volumes:
            for (opt, values) in search_opts.iteritems():
                try:
                    filter_func = filter_mapping[opt]
                except KeyError:
                    continue
                else:
                    if filter_func(volume, values):
                        result.append(volume)
                        break
        volumes = result
    return volumes