summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/views/images.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py
index 67364b115..8eaf0ca6a 100644
--- a/nova/api/openstack/views/images.py
+++ b/nova/api/openstack/views/images.py
@@ -37,6 +37,10 @@ class ViewBuilder(object):
def _format_status(self, image):
"""Update the status field to standardize format."""
+
+ if 'status' not in image:
+ return
+
status_mapping = {
'active': 'ACTIVE',
'queued': 'SAVING',
@@ -51,6 +55,14 @@ class ViewBuilder(object):
except KeyError:
image['status'] = 'UNKNOWN'
+ def _get_progress_for_status(self, status):
+ progress_map = {
+ 'queued': 25,
+ 'saving': 50,
+ 'active': 100,
+ }
+ return progress_map.get(status, 0)
+
def _build_server(self, image, image_obj):
"""Indicates that you must use a ViewBuilder subclass."""
raise NotImplementedError()
@@ -72,8 +84,8 @@ class ViewBuilder(object):
"""Return a standardized image structure for display by the API."""
self._format_dates(image_obj)
- if "status" in image_obj:
- self._format_status(image_obj)
+ orig_status = image_obj.get('status', '').lower()
+ self._format_status(image_obj)
image = {
"id": image_obj.get("id"),
@@ -89,11 +101,7 @@ class ViewBuilder(object):
"updated": image_obj.get("updated_at"),
"status": image_obj.get("status"),
})
-
- if image["status"].upper() == "ACTIVE":
- image["progress"] = 100
- else:
- image["progress"] = 0
+ image["progress"] = self._get_progress_for_status(orig_status)
return image