From 2777059b6bf217f4a1b0ae296f0f8ae6e4922453 Mon Sep 17 00:00:00 2001 From: Dmitriy Smirnov Date: Thu, 30 May 2024 16:06:25 +0300 Subject: [PATCH] Add logic for virtual image renaming in decort_osimage class --- library/decort_osimage.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/library/decort_osimage.py b/library/decort_osimage.py index e93009c..f607769 100644 --- a/library/decort_osimage.py +++ b/library/decort_osimage.py @@ -313,7 +313,14 @@ class decort_osimage(DecortController): amodule.fail_json(**self.result) - if amodule.params['image_id'] != 0 and amodule.params['image_name']: + if amodule.params['virt_id'] != 0 and amodule.params['virt_name']: + self.validated_virt_image_id, image_facts =\ + self.decort_virt_image_find(amodule) + if (self.validated_virt_image_id and + amodule.params['virt_name'] != image_facts['name']): + self.decort_virt_image_rename(amodule) + self.result['msg'] = 'Virtual image renamed successfully' + elif amodule.params['image_id'] != 0 and amodule.params['image_name']: self.validated_image_id, image_facts = self.decort_image_find(amodule) if (self.validated_image_id and amodule.params['image_name'] != image_facts['name']): @@ -390,6 +397,12 @@ class decort_osimage(DecortController): image_id, image_facts = decort_osimage.decort_image_find(self, amodule) return image_id, image_facts + def decort_virt_image_rename(self, amodule): + image_facts = self.image_rename(imageId=self.validated_virt_image_id, + name=amodule.params['virt_name']) + self.result['msg'] = ("Virtual image renamed successfully") + image_id, image_facts = self.decort_virt_image_find(amodule) + return image_id, image_facts def decort_osimage_package_facts(arg_osimage_facts, arg_check_mode=False): """Package a dictionary of OS image according to the decort_osimage module specification. This