@rest_api.get('/imagefactory/<collection_type>/<image_id>')
@rest_api.get('/imagefactory/base_images/<base_image_id>/<collection_type>/<image_id>')
@rest_api.get('/imagefactory/base_images/<base_image_id>/target_images/<target_image_id>/<collection_type>/<image_id>')
@rest_api.get('/imagefactory/target_images/<target_image_id>/<collection_type>/<image_id>')
@log_request
@oauth_protect
@check_accept_header
def image_with_id(collection_type, image_id, base_image_id=None, target_image_id=None, provider_image_id=None):
    try:
        img_class = IMAGE_TYPES[collection_type]
        if img_class:
            fetch_spec = {'type': img_class, 'identifier': image_id}
            try:
                image = PersistentImageManager.default_manager().images_from_query(fetch_spec)[0]
                _type = type(image).__name__
                _response = {'_type': _type,
                             'id': image.identifier,
                             'href': request.url}
                for key in image.metadata():
                    if key not in ('identifier', 'data', 'base_image_id', 'target_image_id'):
                        _response[key] = getattr(image, key, None)

                api_url = '%s://%s/imagefactory' % (request.urlparts[0], request.urlparts[1])

                if (_type == "BaseImage"):
                    _objtype = 'base_image'
                    _response['target_images'] = list_images('target_images',
                                                             base_image_id=image.identifier,
                                                             list_url='%s/target_images' % api_url)
                elif (_type == "TargetImage"):
                    _objtype = 'target_image'
                    base_image_id = image.base_image_id
                    if (base_image_id):
                        base_image_href = '%s/base_images/%s' % (api_url, base_image_id)
                        base_image_dict = {'_type': 'BaseImage', 'id': base_image_id, 'href': base_image_href}
                        _response['base_image'] = base_image_dict
                    else:
                        _response['base_image'] = None
                    _response['provider_images'] = list_images('provider_images',
                                                               target_image_id=image.identifier,
                                                               list_url='%s/provider_images' % api_url)
                elif (_type == "ProviderImage"):
                    _objtype = 'provider_image'
                    target_image_id = image.target_image_id
                    if (target_image_id):
                        target_image_href = '%s/target_images/%s' % (api_url, target_image_id)
                        target_image_dict = {'_type': 'TargetImage', 'id': target_image_id, 'href': target_image_href}
                        _response['target_image'] = target_image_dict
                    else:
                        _response['target_image'] = None
                else:
                    log.error("Returning HTTP status 500 due to unknown image type: %s" % _type)
                    raise HTTPResponse(status=500, output='Bad type for found object: %s' % _type)

                response.status = 200
                return converted_response({_objtype: _response})

            except __HOLE__ as e:
                log.warning(e)
                raise HTTPResponse(status=404, output='No %s found with id: %s' % (img_class, image_id))
        else:
            raise HTTPResponse(status=404, output='Unknown resource type: %s' % collection_type)
    except KeyError as e:
        if collection_type == 'plugins':
            return get_plugins(plugin_id=image_id)
        else:
            log.exception(e)
            raise HTTPResponse(status=500, output=e)
    except Exception as e:
        log.exception(e)
        raise HTTPResponse(status=500, output=e)
dataset/ETHPy150Open redhat-imaging/imagefactory/imgfac/rest/RESTv2.py/image_with_id