From eb3da6588672247696be90d3f4a9aa4dd678184d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Fri, 22 Nov 2019 21:17:30 -0500 Subject: [PATCH] vmware_rest_client: pass object to get_tags_for_dynamic_obj (#65156) This patch fix the `vmware_cluster_info` functional-tests. `get_tags_for_dynamic_obj()` expects an object, not the object ID in a string. Without this patch, the `vmware_cluster_info` module fails. `get_tags_for_object()` raises the following exception: ``` vmware.vapi.exception.CoreException: Expected VapiStruct instance or python dictionary, but received str ``` The patch partially reverts changes introduce in: https://github.com/ansible/ansible/commit/35cc26f8c0447ab1ad4427eafcc7283c4356370d See: http://vmware.github.io/vsphere-automation-sdk-rest/6.5/operations/com/vmware/cis/tagging/tag_association.list_attached_tags-operation.html --- lib/ansible/module_utils/vmware_rest_client.py | 15 +++++++++------ .../modules/cloud/vmware/vmware_tag_manager.py | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/ansible/module_utils/vmware_rest_client.py b/lib/ansible/module_utils/vmware_rest_client.py index dbe0a621c09..77ad4a50c1c 100644 --- a/lib/ansible/module_utils/vmware_rest_client.py +++ b/lib/ansible/module_utils/vmware_rest_client.py @@ -162,7 +162,7 @@ class VmwareRestClient(object): return tags - def get_tags_for_dynamic_obj(self, mid=None): + def get_tags_for_dynamic_obj(self, dobj=None): """ Return list of tag object details associated with object Args: @@ -172,10 +172,10 @@ class VmwareRestClient(object): """ tags = [] - if mid is None: + if dobj is None: return tags - temp_tags_model = self.get_tags_for_object(dobj=mid) + temp_tags_model = self.get_tags_for_object(dobj) category_service = self.api_client.tagging.Category @@ -199,7 +199,8 @@ class VmwareRestClient(object): Returns: List of tag object associated with the given cluster """ - return self.get_tags_for_dynamic_obj(mid=cluster_mid) + dobj = DynamicID(type='cluster', id=cluster_mid) + return self.get_tags_for_dynamic_obj(dobj) def get_tags_for_hostsystem(self, hostsystem_mid=None): """ @@ -210,7 +211,8 @@ class VmwareRestClient(object): Returns: List of tag object associated with the given host system """ - return self.get_tags_for_dynamic_obj(mid=hostsystem_mid) + dobj = DynamicID(type='HostSystem', id=hostsystem_mid) + return self.get_tags_for_dynamic_obj(dobj) def get_tags_for_vm(self, vm_mid=None): """ @@ -221,7 +223,8 @@ class VmwareRestClient(object): Returns: List of tag object associated with the given virtual machine """ - return self.get_tags_for_dynamic_obj(mid=vm_mid) + dobj = DynamicID(type='VirtualMachine', id=vm_mid) + return self.get_tags_for_dynamic_obj(dobj) def get_vm_tags(self, tag_service=None, tag_association_svc=None, vm_mid=None): """ diff --git a/lib/ansible/modules/cloud/vmware/vmware_tag_manager.py b/lib/ansible/modules/cloud/vmware/vmware_tag_manager.py index 48b5c2e87f8..fa4a523a189 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_tag_manager.py +++ b/lib/ansible/modules/cloud/vmware/vmware_tag_manager.py @@ -210,7 +210,7 @@ class VmwareTagManager(VmwareRestClient): tag_assoc_svc=self.tag_association_svc, dobj=self.dynamic_managed_object) - _temp_prev_tags = ["%s:%s" % (tag['category_name'], tag['name']) for tag in self.get_tags_for_dynamic_obj(mid=self.dynamic_managed_object)] + _temp_prev_tags = ["%s:%s" % (tag['category_name'], tag['name']) for tag in self.get_tags_for_dynamic_obj(self.dynamic_managed_object)] results['tag_status']['previous_tags'] = _temp_prev_tags results['tag_status']['desired_tags'] = self.tag_names @@ -265,7 +265,7 @@ class VmwareTagManager(VmwareRestClient): except Error as error: self.module.fail_json(msg="%s" % self.get_error_message(error)) - _temp_curr_tags = ["%s:%s" % (tag['category_name'], tag['name']) for tag in self.get_tags_for_dynamic_obj(mid=self.dynamic_managed_object)] + _temp_curr_tags = ["%s:%s" % (tag['category_name'], tag['name']) for tag in self.get_tags_for_dynamic_obj(self.dynamic_managed_object)] results['tag_status']['current_tags'] = _temp_curr_tags results['changed'] = changed self.module.exit_json(**results)