diff options
Diffstat (limited to 'heatclient/osc/v1/stack.py')
-rw-r--r-- | heatclient/osc/v1/stack.py | 122 |
1 files changed, 80 insertions, 42 deletions
diff --git a/heatclient/osc/v1/stack.py b/heatclient/osc/v1/stack.py index cd67ace..2943ebe 100644 --- a/heatclient/osc/v1/stack.py +++ b/heatclient/osc/v1/stack.py @@ -941,7 +941,7 @@ class StackActionBase(lister.Lister): def _take_action(self, parsed_args, action, good_status, bad_status): self.log.debug("take_action(%s)", parsed_args) heat_client = self.app.client_manager.orchestration - return _stack_action( + return _stacks_action( parsed_args, heat_client, action, @@ -950,34 +950,39 @@ class StackActionBase(lister.Lister): ) -def _stack_action(parsed_args, heat_client, action, good_status, bad_status): +def _stacks_action(parsed_args, heat_client, action, good_status, bad_status): rows = [] + columns = [ + 'ID', + 'Stack Name', + 'Stack Status', + 'Creation Time', + 'Updated Time' + ] for stack in parsed_args.stack: - try: - action(stack) - except heat_exc.HTTPNotFound: - msg = _('Stack not found: %s') % stack - raise exc.CommandError(msg) + data = _stack_action(stack, parsed_args, heat_client, action, + good_status, bad_status) + rows += [utils.get_dict_properties(data.to_dict(), columns)] + return (columns, rows) - if parsed_args.wait: - if not utils.wait_for_status(heat_client.stacks.get, stack, - status_field='stack_status', - success_status=good_status, - error_status=bad_status): - err = _("Error waiting for status from stack %s") % stack - raise exc.CommandError(err) - data = heat_client.stacks.get(stack) - columns = [ - 'ID', - 'Stack Name', - 'Stack Status', - 'Creation Time', - 'Updated Time' - ] - rows += [utils.get_dict_properties(data.to_dict(), columns)] +def _stack_action(stack, parsed_args, heat_client, action, + good_status, bad_status): + try: + action(stack) + except heat_exc.HTTPNotFound: + msg = _('Stack not found: %s') % stack + raise exc.CommandError(msg) - return (columns, rows) + if parsed_args.wait: + if not utils.wait_for_status(heat_client.stacks.get, stack, + status_field='stack_status', + success_status=good_status, + error_status=bad_status): + err = _("Error waiting for status from stack %s") % stack + raise exc.CommandError(err) + + return heat_client.stacks.get(stack) class SuspendStack(StackActionBase): @@ -1022,46 +1027,79 @@ class ResumeStack(StackActionBase): ) -class UpdateCancelStack(StackActionBase): - """Cancel update for a stack.""" +class CheckStack(StackActionBase): + """Check a stack.""" - log = logging.getLogger(__name__ + '.UpdateCancelStack') + log = logging.getLogger(__name__ + '.CheckStack') def get_parser(self, prog_name): return self._get_parser( prog_name, - _('Stack(s) to cancel update (name or ID)'), - _('Wait for cancel update to complete') + _('Stack(s) to check update (name or ID)'), + _('Wait for check to complete') ) def take_action(self, parsed_args): return self._take_action( parsed_args, - self.app.client_manager.orchestration.actions.cancel_update, - ['cancel_update_complete'], - ['cancel_update_failed'] + self.app.client_manager.orchestration.actions.check, + ['check_complete'], + ['check_failed'] ) -class CheckStack(StackActionBase): - """Check a stack.""" +class CancelStack(StackActionBase): + """Cancel current task for a stack. - log = logging.getLogger(__name__ + '.CheckStack') + Supported tasks for cancellation: + * update + """ + + log = logging.getLogger(__name__ + '.CancelStack') def get_parser(self, prog_name): return self._get_parser( prog_name, - _('Stack(s) to check update (name or ID)'), + _('Stack(s) to cancel (name or ID)'), _('Wait for check to complete') ) def take_action(self, parsed_args): - return self._take_action( - parsed_args, - self.app.client_manager.orchestration.actions.check, - ['check_complete'], - ['check_failed'] - ) + self.log.debug("take_action(%s)", parsed_args) + rows = [] + columns = [ + 'ID', + 'Stack Name', + 'Stack Status', + 'Creation Time', + 'Updated Time' + ] + heat_client = self.app.client_manager.orchestration + + for stack in parsed_args.stack: + try: + data = heat_client.stacks.get(stack_id=stack) + except heat_exc.HTTPNotFound: + raise exc.CommandError('Stack not found: %s' % stack) + + status = getattr(data, 'stack_status').lower() + if status == 'update_in_progress': + data = _stack_action( + stack, + parsed_args, + heat_client, + heat_client.actions.cancel_update, + ['cancel_update_complete'], + ['cancel_update_failed'] + ) + rows += [utils.get_dict_properties(data.to_dict(), columns)] + else: + err = _("Stack %(id)s with status \'%(status)s\' " + "not in cancelable state") % { + 'id': stack, 'status': status} + raise exc.CommandError(err) + + return (columns, rows) class StackHookPoll(lister.Lister): |