Beispiel #1
0
def add_image(request):
    """Add a new virtual machine image

    Described in:
    3.6. Adding a New Virtual Machine Image

    Implementation notes:
      * The implementation is very inefficient as it loads the whole image
        in memory.

    Limitations:
      * x-image-meta-id is not supported. Will always return 409 Conflict.

    Extensions:
      * An x-image-meta-location header can be passed with a link to file,
        instead of uploading the data.
    """

    params = headers_to_image_params(request)
    log.debug('add_image %s', params)

    if not set(params.keys()).issubset(set(ADD_FIELDS)):
        raise faults.BadRequest("Invalid parameters")

    name = params.pop('name', None)
    if name is None:
        raise faults.BadRequest("Image 'name' parameter is required")
    elif len(smart_unicode(name, encoding="utf-8")) == 0:
        raise faults.BadRequest("Invalid image name")
    location = params.pop('location', None)
    if location is None:
        raise faults.BadRequest("'location' parameter is required")

    try:
        split_url(location)
    except AssertionError:
        raise faults.BadRequest("Invalid location '%s'" % location)

    validate_fields(params)

    if location:
        with PlanktonBackend(request.user_uniq) as backend:
            image = backend.register(name, location, params)
    else:
        # f = StringIO(request.body)
        # image = backend.put(name, f, params)
        return HttpResponse(status=501)  # Not Implemented

    if not image:
        return HttpResponse('Registration failed', status=500)

    return _create_image_response(image)
Beispiel #2
0
def add_image(request):
    """Add a new virtual machine image

    Described in:
    3.6. Adding a New Virtual Machine Image

    Implementation notes:
      * The implementation is very inefficient as it loads the whole image
        in memory.

    Limitations:
      * x-image-meta-id is not supported. Will always return 409 Conflict.

    Extensions:
      * An x-image-meta-location header can be passed with a link to file,
        instead of uploading the data.
    """

    params = headers_to_image_params(request)
    log.debug('add_image %s', params)

    if not set(params.keys()).issubset(set(ADD_FIELDS)):
        raise faults.BadRequest("Invalid parameters")

    name = params.pop('name', None)
    if name is None:
        raise faults.BadRequest("Image 'name' parameter is required")
    elif len(smart_unicode(name, encoding="utf-8")) == 0:
        raise faults.BadRequest("Invalid image name")
    location = params.pop('location', None)
    if location is None:
        raise faults.BadRequest("'location' parameter is required")

    try:
        split_url(location)
    except AssertionError:
        raise faults.BadRequest("Invalid location '%s'" % location)

    validate_fields(params)

    if location:
        with PlanktonBackend(request.user_uniq) as backend:
            image = backend.register(name, location, params)
    else:
        # f = StringIO(request.body)
        # image = backend.put(name, f, params)
        return HttpResponse(status=501)     # Not Implemented

    if not image:
        return HttpResponse('Registration failed', status=500)

    return _create_image_response(image)
Beispiel #3
0
def add_image(request):
    """Add a new virtual machine image

    Described in:
    3.6. Adding a New Virtual Machine Image

    Implementation notes:
      * The implementation is very inefficient as it loads the whole image
        in memory.

    Limitations:
      * x-image-meta-id is not supported. Will always return 409 Conflict.

    Extensions:
      * An x-image-meta-location header can be passed with a link to file,
        instead of uploading the data.
    """

    params = _get_image_headers(request)
    log.debug('add_image %s', params)

    assert 'name' in params
    assert set(params.keys()).issubset(set(ADD_FIELDS))

    name = params.pop('name')
    location = params.pop('location', None)
    try:
        split_url(location)
    except AssertionError:
        raise faults.BadRequest("Invalid location '%s'" % location)

    if location:
        with image_backend(request.user_uniq) as backend:
            image = backend.register(name, location, params)
    else:
        #f = StringIO(request.raw_post_data)
        #image = backend.put(name, f, params)
        return HttpResponse(status=501)     # Not Implemented

    if not image:
        return HttpResponse('Registration failed', status=500)

    return _create_image_response(image)
Beispiel #4
0
def add_image(request):
    """Add a new virtual machine image

    Described in:
    3.6. Adding a New Virtual Machine Image

    Implementation notes:
      * The implementation is very inefficient as it loads the whole image
        in memory.

    Limitations:
      * x-image-meta-id is not supported. Will always return 409 Conflict.

    Extensions:
      * An x-image-meta-location header can be passed with a link to file,
        instead of uploading the data.
    """

    params = _get_image_headers(request)
    log.debug('add_image %s', params)

    assert 'name' in params
    assert set(params.keys()).issubset(set(ADD_FIELDS))

    name = params.pop('name')
    location = params.pop('location', None)
    try:
        split_url(location)
    except AssertionError:
        raise faults.BadRequest("Invalid location '%s'" % location)

    if location:
        with image_backend(request.user_uniq) as backend:
            image = backend.register(name, location, params)
    else:
        #f = StringIO(request.raw_post_data)
        #image = backend.put(name, f, params)
        return HttpResponse(status=501)  # Not Implemented

    if not image:
        return HttpResponse('Registration failed', status=500)

    return _create_image_response(image)