From b84d71c6bcca04a47407ea8491911b8584e395bb Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Thu, 29 Sep 2011 14:45:50 -0400 Subject: 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. Change-Id: Ic5de9d4404c8903bc2a6027697905f92374f8af7 --- nova/api/openstack/views/images.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'nova/api') 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 -- cgit