Beispiel #1
0
def delete_image_with_id(image_id, base_image_id=None, target_image_id=None, provider_image_id=None):
    try:
        image = PersistentImageManager.default_manager().image_with_id(image_id)
        if(not image):
            raise HTTPResponse(status=404, output='No image found with id: %s' % image_id)
        builder = Builder()
        request_data = form_data_for_content_type(request.headers.get('Content-Type'))
        if(request_data and (len(request_data) > 0)):
            builder.delete_image(provider=request_data.get('provider'),
                                 credentials=request_data.get('credentials'),
                                 target=request_data.get('target'),
                                 image_object=image,
                                 parameters=request_data.get('parameters'))
        else:
            builder.delete_image(provider=None, credentials=None, target=None, image_object=image, parameters=None)
        response.status = 204
    except Exception as e:
        log.exception(e)
        raise HTTPResponse(status=500, output=e)
Beispiel #2
0
def delete_image_with_id(image_id, base_image_id=None, target_image_id=None, provider_image_id=None):
    try:
        response.status = 204
        image = PersistentImageManager.default_manager().image_with_id(image_id)
        if(not image):
            raise HTTPResponse(status=404, output='No image found with id: %s' % image_id)
        image_class = type(image).__name__
        builder = Builder()
        content_type = request.headers.get('Content-Type')
        form_data = form_data_for_content_type(content_type)
        required_values = set(['provider', 'credentials', 'target'])

        if form_data:
            root_object = form_data.get(IMAGE_TYPES.get(image_class))
            if root_object and (type(root_object) is dict):
                request_data = root_object
            else:
                request_data = form_data

            if image_class == 'ProviderImage':
                missing_values = required_values.difference(request_data)
                if len(missing_values) > 0:
                    raise HTTPResponse(status=400, output='Missing required values: %s' % missing_values)

            builder.delete_image(provider=request_data.get('provider'),
                                 credentials=request_data.get('credentials'),
                                 target=request_data.get('target'),
                                 image_object=image,
                                 parameters=request_data.get('parameters'))
        else:
            if image_class == 'ProviderImage':
                raise HTTPResponse(status=400, output='Missing required values:%s' % required_values)
            else:
                builder.delete_image(provider=None, credentials=None, target=None, image_object=image, parameters=None)
    except Exception as e:
        log.exception(e)
        raise HTTPResponse(status=500, output=e)
Beispiel #3
0
def delete_image_with_id(image_id,
                         collection_type=None,
                         base_image_id=None,
                         target_image_id=None,
                         provider_image_id=None):
    try:
        response.status = 204
        image = PersistentImageManager.default_manager().image_with_id(
            image_id)
        if (not image):
            raise HTTPResponse(status=404,
                               output='No image found with id: %s' % image_id)
        image_class = type(image).__name__
        builder = Builder()
        content_type = request.headers.get('Content-Type')
        form_data = form_data_for_content_type(content_type)
        required_values = set(['provider', 'credentials', 'target'])

        if form_data:
            root_object = form_data.get(IMAGE_TYPES.get(image_class))
            if root_object and (type(root_object) is dict):
                request_data = root_object
            else:
                request_data = form_data

            if image_class == 'ProviderImage':
                missing_values = required_values.difference(request_data)
                if len(missing_values) > 0:
                    raise HTTPResponse(status=400,
                                       output='Missing required values: %s' %
                                       missing_values)

            builder.delete_image(provider=request_data.get('provider'),
                                 credentials=request_data.get('credentials'),
                                 target=request_data.get('target'),
                                 image_object=image,
                                 parameters=request_data.get('parameters'))
        else:
            if image_class == 'ProviderImage':
                raise HTTPResponse(status=400,
                                   output='Missing required values:%s' %
                                   required_values)
            else:
                builder.delete_image(provider=None,
                                     credentials=None,
                                     target=None,
                                     image_object=image,
                                     parameters=None)
    except Exception as e:
        log.exception(e)
        raise HTTPResponse(status=500, output=e)