diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-02-25 13:47:52 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-02-25 13:47:52 +0000 |
commit | 7887beafe6cf3edd016f6753ff23181ac9c6cf0e (patch) | |
tree | 8be8b2734a3c9367716d989aaff5e11ecc54f71c /heatclient/v1/shell.py | |
parent | 06b2ef0e3ccd0e224c85b6d49a1ff7aa475c581d (diff) | |
parent | 302040c759e13ac93c9bf8a6b1acd14c73faaad7 (diff) | |
download | python-heatclient-7887beafe6cf3edd016f6753ff23181ac9c6cf0e.tar.gz |
Merge "Move poll_for_events to event_utils"
Diffstat (limited to 'heatclient/v1/shell.py')
-rw-r--r-- | heatclient/v1/shell.py | 47 |
1 files changed, 11 insertions, 36 deletions
diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 1c613af..d530958 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -19,7 +19,6 @@ from oslo_serialization import jsonutils from oslo_utils import strutils import six from six.moves.urllib import request -import time import yaml from heatclient.common import deployment_utils @@ -137,8 +136,17 @@ def do_stack_create(hc, args): hc.stacks.create(**fields) do_stack_list(hc) - if args.poll is not None: - _poll_for_events(hc, args.name, 'CREATE', args.poll) + if not args.poll: + return + + show_fields = {'stack_id': args.name} + _do_stack_show(hc, show_fields) + stack_status, msg = event_utils.poll_for_events( + hc, args.name, action='CREATE', poll_period=args.poll) + _do_stack_show(hc, show_fields) + if stack_status == 'CREATE_FAILED': + raise exc.StackFailure(msg) + print(msg) @utils.arg('-e', '--environment-file', metavar='<FILE or URL>', @@ -1557,36 +1565,3 @@ def _do_stack_show(hc, fields): 'tags': utils.json_formatter } utils.print_dict(stack.to_dict(), formatters=formatters) - - -def _poll_for_events(hc, stack_name, action, poll_period): - """Continuously poll events and logs for performed action on stack.""" - - fields = {'stack_id': stack_name} - _do_stack_show(hc, fields) - marker = None - while True: - events = event_utils.get_events(hc, stack_id=stack_name, - event_args={'sort_dir': 'asc', - 'marker': marker}) - - if len(events) >= 1: - # set marker to last event that was received. - marker = getattr(events[-1], 'id', None) - events_log = utils.event_log_formatter(events) - print(events_log) - for event in events: - # check if stack event was also received - if getattr(event, 'resource_name', '') == stack_name: - stack_status = getattr(event, 'resource_status', '') - msg = _("\n Stack %(name)s %(status)s \n") % dict( - name=stack_name, status=stack_status) - if stack_status == '%s_COMPLETE' % action: - _do_stack_show(hc, fields) - print(msg) - return - elif stack_status == '%s_FAILED' % action: - _do_stack_show(hc, fields) - raise exc.StackFailure(msg) - - time.sleep(poll_period) |