'Get all instances filtered by one of the given parameters.
If there is no filter and the context is an admin, it will retrieve
all instances in the system.
Deleted instances will be returned by default, unless there is a
search option that says otherwise.
The results will be sorted based on the list of sort keys in the
\'sort_keys\' parameter (first value is primary sort key, second value is
secondary sort ket, etc.). For each sort key, the associated sort
direction is based on the list of sort directions in the \'sort_dirs\'
parameter.'

def get_all(self, context, search_opts=None, limit=None, marker=None, expected_attrs=None, sort_keys=None, sort_dirs=None):

    if (search_opts is None):
        search_opts = {}
    LOG.debug('Searching    by:    %s', str(search_opts))
    filters = {}
    def _remap_flavor_filter(flavor_id):
        flavor = objects.Flavor.get_by_flavor_id(context, flavor_id)
        filters['instance_type_id'] = flavor.id
    def _remap_fixed_ip_filter(fixed_ip):
        filters['ip'] = ('^%s$' % fixed_ip.replace('.', '\\.'))
    def _remap_metadata_filter(metadata):
        filters['metadata'] = jsonutils.loads(metadata)
    def _remap_system_metadata_filter(metadata):
        filters['system_metadata'] = jsonutils.loads(metadata)
    filter_mapping = {'image': 'image_ref', 'name': 'display_name', 'tenant_id': 'project_id', 'flavor': _remap_flavor_filter, 'fixed_ip': _remap_fixed_ip_filter, 'metadata': _remap_metadata_filter, 'system_metadata': _remap_system_metadata_filter}
    for (opt, value) in search_opts.items():
        try:
            remap_object = filter_mapping[opt]
        except KeyError:
            filters[opt] = value
        else:
            if isinstance(remap_object, six.string_types):
                filters[remap_object] = value
            else:
                try:
                    remap_object(value)
                except ValueError:
                    return objects.InstanceList()
    filter_ip = (('ip6' in filters) or ('ip' in filters))
    orig_limit = limit
    if (filter_ip and limit):
        LOG.debug('Removing    limit    for    DB    query    due    to    IP    filter')
        limit = None
    build_requests = objects.BuildRequestList.get_by_filters(context, filters, limit=limit, marker=marker, sort_keys=sort_keys, sort_dirs=sort_dirs)
    build_req_instances = objects.InstanceList(objects=[build_req.instance for build_req in build_requests])
    limit = ((limit - len(build_req_instances)) if limit else limit)
    try:
        cell0_mapping = objects.CellMapping.get_by_uuid(context, objects.CellMapping.CELL0_UUID)
    except exception.CellMappingNotFound:
        cell0_instances = objects.InstanceList(objects=[])
    else:
        with nova_context.target_cell(context, cell0_mapping) as cctxt:
            try:
                cell0_instances = self._get_instances_by_filters(cctxt, filters, limit=limit, marker=marker, expected_attrs=expected_attrs, sort_keys=sort_keys, sort_dirs=sort_dirs)
                marker = None
            except exception.MarkerNotFound:
                cell0_instances = objects.InstanceList(objects=[])
    limit = ((limit - len(cell0_instances)) if limit else limit)
    if ((limit is None) or (limit > 0)):
        if (not CONF.cells.enable):
            cell_instances = self._get_instances_by_filters_all_cells(context, filters, limit=limit, marker=marker, expected_attrs=expected_attrs, sort_keys=sort_keys, sort_dirs=sort_dirs)
        else:
            cell_instances = self._get_instances_by_filters(context, filters, limit=limit, marker=marker, expected_attrs=expected_attrs, sort_keys=sort_keys, sort_dirs=sort_dirs)
    else:
        LOG.debug('Limit    excludes    any    results    from    real    cells')
        cell_instances = objects.InstanceList(objects=[])
    def _get_unique_filter_method():
        seen_uuids = set()
        def _filter(instance):
            if (instance.uuid in seen_uuids):
                return False
            seen_uuids.add(instance.uuid)
            return True
        return _filter
    filter_method = _get_unique_filter_method()
    limit = ((limit - len(cell_instances)) if limit else limit)
    instances = objects.InstanceList(objects=list(filter(filter_method, ((build_req_instances.objects + cell0_instances.objects) + cell_instances.objects))))
    if filter_ip:
        instances = self._ip_filter(instances, filters, orig_limit)
    return instances
