summaryrefslogtreecommitdiff
path: root/openstackclient/common/utils.py
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2013-07-25 18:00:33 -0500
committerDean Troyer <dtroyer@gmail.com>2013-07-29 18:57:02 -0500
commit65d2a14e3e834ce0c57c879ec7d42715058254bf (patch)
treed1f2f8bb0051b4086237c3ef1cd0c80db1de9ab8 /openstackclient/common/utils.py
parent3cc313a60db6d1a5a89c572ed10bca11402912d4 (diff)
downloadpython-openstackclient-65d2a14e3e834ce0c57c879ec7d42715058254bf.tar.gz
Add server resize command
* add server resize * update --wait handling for server create, reboot, rebuild * move _wait_for_status to utils Blueprint: nova-client Rebased after https://review.openstack.org/38162 was committed Change-Id: I7a43b996feecadc7628fcfe20cd5b17333762739
Diffstat (limited to 'openstackclient/common/utils.py')
-rw-r--r--openstackclient/common/utils.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py
index 2f2f5718..fd504ea1 100644
--- a/openstackclient/common/utils.py
+++ b/openstackclient/common/utils.py
@@ -17,6 +17,7 @@
import os
import sys
+import time
import uuid
from openstackclient.common import exceptions
@@ -155,3 +156,35 @@ def get_client_class(api_name, version, version_map):
raise exceptions.UnsupportedVersion(msg)
return import_class(client_path)
+
+
+def wait_for_status(status_f,
+ res_id,
+ status_field='status',
+ success_status=['active'],
+ sleep_time=5,
+ callback=None):
+ """Wait for status change on a resource during a long-running operation
+
+ :param status_f: a status function that takes a single id argument
+ :param res_id: the resource id to watch
+ :param success_status: a list of status strings for successful completion
+ :param status_field: the status attribute in the returned resource object
+ :param sleep_time: wait this long (seconds)
+ :param callback: called per sleep cycle, useful to display progress
+ :rtype: True on success
+ """
+ while True:
+ res = status_f(res_id)
+ status = getattr(res, status_field, '').lower()
+ if status in success_status:
+ retval = True
+ break
+ elif status == 'error':
+ retval = False
+ break
+ if callback:
+ progress = getattr(res, 'progress', None) or 0
+ callback(progress)
+ time.sleep(sleep_time)
+ return retval