summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2011-10-12 01:19:16 +0000
committerGerrit Code Review <review@openstack.org>2011-10-12 01:19:16 +0000
commite95e923f2bee1fa3e5005bb99ec0d41e4931cec8 (patch)
tree92632cc0ddc54e2f0de2a6bc8ed73ffcc2b4c4eb /nova/api
parent5ac67d89eb0f3484f78c61f471e72a42972fe4ff (diff)
parentb84d71c6bcca04a47407ea8491911b8584e395bb (diff)
downloadnova-e95e923f2bee1fa3e5005bb99ec0d41e4931cec8.tar.gz
nova-e95e923f2bee1fa3e5005bb99ec0d41e4931cec8.tar.xz
nova-e95e923f2bee1fa3e5005bb99ec0d41e4931cec8.zip
Merge "Updating image progress to be more granular. Before, the image progress had only 2 states, 0 and 100. Now it can be 0, 25, 50 or 100."
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