From 219aa4d99dd04349b2ea2845fcbdc382d149d155 Mon Sep 17 00:00:00 2001 From: Konrad Gawda Date: Mon, 20 Jun 2022 11:51:58 +0200 Subject: [PATCH] Move logic out of except block Signed-off-by: Konrad Gawda --- modules/vcd_vapp.py | 15 ++++++++++++--- modules/vcd_vapp_vm.py | 5 ++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/vcd_vapp.py b/modules/vcd_vapp.py index 9f9219b..e9fa475 100644 --- a/modules/vcd_vapp.py +++ b/modules/vcd_vapp.py @@ -327,8 +327,11 @@ def instantiate(self): response['changed'] = False try: - self.vdc.get_vapp(vapp_name) + found = self.vdc.get_vapp(vapp_name) except EntityNotFoundException: + found = None + + if not found: create_vapp_task = self.vdc.instantiate_vapp( name=vapp_name, catalog=catalog_name, @@ -377,8 +380,11 @@ def create(self): response['changed'] = False try: - self.vdc.get_vapp(vapp_name) + found = self.vdc.get_vapp(vapp_name) except EntityNotFoundException: + found = None + + if not found: create_vapp_task = self.vdc.create_vapp( name=vapp_name, description=description, @@ -402,8 +408,11 @@ def delete(self): response['changed'] = False try: - self.vdc.get_vapp(vapp_name) + found = self.vdc.get_vapp(vapp_name) except EntityNotFoundException: + found = None + + if not found: response['warnings'] = "Vapp {} is not present.".format(vapp_name) else: delete_vapp_task = self.vdc.delete_vapp( diff --git a/modules/vcd_vapp_vm.py b/modules/vcd_vapp_vm.py index b98d6c2..05c9a9d 100644 --- a/modules/vcd_vapp_vm.py +++ b/modules/vcd_vapp_vm.py @@ -384,8 +384,11 @@ def add_vm(self): response['changed'] = False try: - self.get_vm() + found = self.get_vm() except EntityNotFoundException: + found = None + + if not found: spec = { 'source_vm_name': source_vm_name, 'vapp': source_vapp_resource,