Commit 15df0740 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Fix white space

parent 8c79976a
......@@ -73,7 +73,7 @@ log = getLogger('synnefo.plankton')
def _create_image_response(image):
response = HttpResponse()
for key in DETAIL_FIELDS:
if key == 'properties':
for k, v in image.get('properties', {}).items():
......@@ -82,21 +82,21 @@ def _create_image_response(image):
name = 'x-image-meta-' + key.replace('_', '-')
response[name] = image.get(key, '')
return response
def _get_image_headers(request):
def normalize(s):
return ''.join('_' if c in punctuation else c.lower() for c in s)
headers = {'properties': {}}
for key, val in request.META.items():
if key.startswith(META_PROPERTY_PREFIX):
name = normalize(key[META_PROPERTY_PREFIX_LEN:])
......@@ -104,69 +104,69 @@ def _get_image_headers(request):
elif key.startswith(META_PREFIX):
name = normalize(key[META_PREFIX_LEN:])
headers[unquote(name)] = unquote(val)
is_public = headers.get('is_public', None)
if is_public is not None:
headers['is_public'] = True if is_public.lower() == 'true' else False
if not headers['properties']:
del headers['properties']
return headers
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.
* x-image-meta-id is not supported. Will always return 409 Conflict.
* 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)
if location:
image = request.backend.register(name, location, params)
#f = StringIO(request.raw_post_data)
#image = request.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)
def add_image_member(request, image_id, member):
"""Add a member to an image
Described in:
3.9. Adding a Member to an Image
* Passing a body to enable `can_share` is not supported.
log.debug('add_image_member %s %s', image_id, member)
request.backend.add_user(image_id, member)
return HttpResponse(status=204)
......@@ -175,15 +175,15 @@ def add_image_member(request, image_id, member):
def get_image(request, image_id):
"""Retrieve a virtual machine image
Described in:
3.5. Retrieving a Virtual Machine Image
Implementation notes:
* The implementation is very inefficient as it loads the whole image
in memory.
#image = request.backend.get_image(image_id)
#if not image:
# return HttpResponseNotFound()
......@@ -201,7 +201,7 @@ def get_image(request, image_id):
def get_image_meta(request, image_id):
"""Return detailed metadata on a specific image
Described in:
3.4. Requesting Detailed Metadata on a Specific Image
......@@ -219,7 +219,7 @@ def list_image_members(request, image_id):
Described in:
3.7. Requesting Image Memberships
members = [{'member_id': user, 'can_share': False}
for user in request.backend.list_users(image_id)]
data = json.dumps({'members': members}, indent=settings.DEBUG)
......@@ -229,12 +229,12 @@ def list_image_members(request, image_id):
def list_public_images(request, detail=False):
"""Return a list of public VM images.
Described in:
3.1. Requesting a List of Public VM Images
3.2. Requesting Detailed Metadata on Public VM Images
3.3. Filtering Images Returned via GET /images andGET /images/detail
* Image ID is returned in both compact and detail listings
......@@ -259,7 +259,7 @@ def list_public_images(request, detail=False):
assert params['sort_dir'] in SORT_DIR_OPTIONS
images = request.backend.list_public(filters, params)
# Remove keys that should not be returned
fields = DETAIL_FIELDS if detail else LIST_FIELDS
for image in images:
......@@ -274,21 +274,21 @@ def list_public_images(request, detail=False):
def list_shared_images(request, member):
"""Request shared images
Described in:
3.8. Requesting Shared Images
Implementation notes:
* It is not clear what this method should do. We return the IDs of
the users's images that are accessible by `member`.
log.debug('list_shared_images %s', member)
images = []
for image_id in request.backend.iter_shared(member):
images.append({'image_id': image_id, 'can_share': False})
data = json.dumps({'shared_images': images}, indent=settings.DEBUG)
return HttpResponse(data)
......@@ -309,21 +309,21 @@ def remove_image_member(request, image_id, member):
def update_image(request, image_id):
"""Update an image
Described in:
3.6.2. Updating an Image
Implementation notes:
* It is not clear which metadata are allowed to be updated. We support:
name, disk_format, container_format, is_public, owner, properties
and status.
meta = _get_image_headers(request)
log.debug('update_image %s', meta)
assert set(meta.keys()).issubset(set(UPDATE_FIELDS))
image = request.backend.update(image_id, meta)
return _create_image_response(image)
......@@ -331,14 +331,14 @@ def update_image(request, image_id):
def update_image_members(request, image_id):
"""Replace a membership list for an image
Described in:
3.11. Replacing a Membership List for an Image
* can_share value is ignored
log.debug('update_image_members %s', image_id)
members = []
......@@ -347,6 +347,6 @@ def update_image_members(request, image_id):
except (ValueError, KeyError, TypeError):
return HttpResponse(status=400)
request.backend.replace_users(image_id, members)
return HttpResponse(status=204)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment