From de74a79bd310ed70aae35ea545afb98c9190b3ee Mon Sep 17 00:00:00 2001 From: abregman Date: Thu, 13 Dec 2018 12:29:49 +0200 Subject: [PATCH] Allow to run playbooks in delete mode In order to remove resources created by playbooks. It can be executed with tobiko-delete command. Change-Id: I97774a52acdcb820b308a3b477d2340b67d582fa --- tobiko/cmd/delete.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tobiko/cmd/delete.py b/tobiko/cmd/delete.py index aa8cf0c7a..69d332ee3 100644 --- a/tobiko/cmd/delete.py +++ b/tobiko/cmd/delete.py @@ -40,6 +40,9 @@ class DeleteUtil(base.TobikoCMD): parser.add_argument( '--wait', '-w', action='store_true', dest='wait', help="Wait for stack to be deleted before exiting.") + parser.add_argument( + '--playbook', '-p', + help="The name of the playbook to execute in delete mode.") return parser def delete_stack(self, stack_name=None, all_stacks=False, wait=False): @@ -53,13 +56,21 @@ class DeleteUtil(base.TobikoCMD): self.stackManager.delete_stack(stack_name, wait=wait) LOG.info("Deleted stack: %s", stack_name) + def run_playbook(self, playbook): + """Executes given playbook.""" + self.ansibleManager.run_playbook(playbook, mode='delete') + def main(): """Delete CLI main entry.""" delete_cmd = DeleteUtil() - delete_cmd.delete_stack(stack_name=delete_cmd.args.stack, - all_stacks=delete_cmd.args.all, - wait=delete_cmd.args.wait) + + if delete_cmd.args.playbook: + delete_cmd.run_playbook(delete_cmd.args.playbook) + else: + delete_cmd.delete_stack(stack_name=delete_cmd.args.stack, + all_stacks=delete_cmd.args.all, + wait=delete_cmd.args.wait) if __name__ == '__main__':