Commit 5dc49413 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Update the status of images

Update the 'status' of images as returned in the Compute and Plankton
API.
parent dc40be43
......@@ -103,13 +103,22 @@ def metadata_item_demux(request, image_id, key):
'DELETE'])
API_STATUS_FROM_IMAGE_STATUS = {
"CREATING": "SAVING",
"AVAILABLE": "ACTIVE",
"ERROR": "ERROR",
"DELETED": "DELETED"}
def image_to_dict(image, detail=True):
d = dict(id=image['id'], name=image['name'])
if detail:
d['updated'] = utils.isoformat(date_parse(image['updated_at']))
d['created'] = utils.isoformat(date_parse(image['created_at']))
d['status'] = 'DELETED' if image['deleted_at'] else 'ACTIVE'
d['progress'] = 100 if image['status'] == 'available' else 0
img_status = image.get("status", "").upper()
status = API_STATUS_FROM_IMAGE_STATUS.get(img_status, "UNKNOWN")
d['status'] = status
d['progress'] = 100 if status == 'ACTIVE' else 0
d['user_id'] = image['owner']
d['tenant_id'] = image['owner']
d['links'] = util.image_to_links(image["id"])
......
......@@ -536,6 +536,8 @@ def image_to_dict(location, metadata, permissions):
key = key.replace(PLANKTON_PREFIX, "")
# Keep only those in plankton metadata
if key in PLANKTON_META:
if key == "status":
image["status"] = val.upper()
if key != "created_at":
# created timestamp is return in 'created_at' field
image[key] = val
......
......@@ -62,7 +62,8 @@ LIST_FIELDS = ('status', 'name', 'disk_format', 'container_format', 'size',
DETAIL_FIELDS = ('name', 'disk_format', 'container_format', 'size', 'checksum',
'location', 'created_at', 'updated_at', 'deleted_at',
'status', 'is_public', 'owner', 'properties', 'id', "is_snapshot")
'status', 'is_public', 'owner', 'properties', 'id',
"is_snapshot")
ADD_FIELDS = ('name', 'id', 'store', 'disk_format', 'container_format', 'size',
'checksum', 'is_public', 'owner', 'properties', 'location')
......@@ -80,6 +81,12 @@ STORE_TYPES = ('pithos')
log = getLogger('synnefo.plankton')
API_STATUS_FROM_IMAGE_STATUS = {
"CREATING": "SAVING",
"AVAILABLE": "ACTIVE",
"DELETED": "DELETED"}
def _create_image_response(image):
response = HttpResponse()
......@@ -89,8 +96,14 @@ def _create_image_response(image):
name = 'x-image-meta-property-' + k.replace('_', '-')
response[name] = uenc(v)
else:
name = 'x-image-meta-' + key.replace('_', '-')
response[name] = uenc(image.get(key, ''))
if key == "status":
img_status = image.get(key, "").upper()
status = API_STATUS_FROM_IMAGE_STATUS.get(img_status,
"UNKNOWN")
response["x-image-meta-status"] = status
else:
name = 'x-image-meta-' + key.replace('_', '-')
response[name] = uenc(image.get(key, ''))
return response
......
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