diff options
author | Chaynika Saikia <csaikia@asu.edu> | 2017-06-19 16:27:49 -0400 |
---|---|---|
committer | Chaynika Saikia <csaikia@asu.edu> | 2017-07-24 09:06:28 -0400 |
commit | 0cb09cc560436538366cfa4c91136ba5538f5167 (patch) | |
tree | 1e2e4302399ea5bc9971f25d2fa18727ff9547c8 /cinderclient/shell_utils.py | |
parent | 72671fffe51898446c8671e122cd6ef11171fdb1 (diff) | |
download | python-cinderclient-0cb09cc560436538366cfa4c91136ba5538f5167.tar.gz |
Add cinder create --poll
Usage: It adds an optional argument --poll to the cinder
create command which waits while the creation of the volume
is completed and the volume goes to available state. In case
there is an error in volume creation, it throws an error message
and exits with a non zero status. The error message printed here
is the async error message in case it generates one.
Depends-On: Ic3ab32b95abd29e995bc071adc11b1e481b32516
Change-Id: I1a4d361d48a44a0daa830491f415be64f2e356e3
Diffstat (limited to 'cinderclient/shell_utils.py')
-rw-r--r-- | cinderclient/shell_utils.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/cinderclient/shell_utils.py b/cinderclient/shell_utils.py index 35802f8..e01b0cf 100644 --- a/cinderclient/shell_utils.py +++ b/cinderclient/shell_utils.py @@ -18,6 +18,7 @@ import sys import time from cinderclient import utils +from cinderclient import exceptions _quota_resources = ['volumes', 'snapshots', 'gigabytes', 'backups', 'backup_gigabytes', @@ -276,3 +277,36 @@ def print_qos_specs_and_associations_list(q_specs): def print_associations_list(associations): utils.print_list(associations, ['Association_Type', 'Name', 'ID']) + + +def _poll_for_status(poll_fn, obj_id, info, action, final_ok_states, + timeout_period, global_request_id=None, messages=None, + poll_period=2, status_field="status"): + """Block while an action is being performed.""" + time_elapsed = 0 + while True: + time.sleep(poll_period) + time_elapsed += poll_period + obj = poll_fn(obj_id) + status = getattr(obj, status_field) + info[status_field] = status + if status: + status = status.lower() + + if status in final_ok_states: + break + elif status == "error": + utils.print_dict(info) + if global_request_id: + search_opts = { + 'request_id': global_request_id + } + message_list = messages.list(search_opts=search_opts) + try: + fault_msg = message_list[0].user_message + except IndexError: + fault_msg = "Unknown error. Operation failed." + raise exceptions.ResourceInErrorState(obj, fault_msg) + elif time_elapsed == timeout_period: + utils.print_dict(info) + raise exceptions.TimeoutException(obj, action) |