We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Missing Quotation mark in vmware_object_rename error message
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
A question mark before `object type` is missing

https://github.com/ansible-collections/community.vmware/blob/b5eb08db178ead605a0f233f8a88ef6435b5c709/plugins/modules/vmware_object_rename.py#L275

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
vmware_object_rename


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `plugins/modules/vmware_object_rename.py`
Content:
```
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 
4 # Copyright: (c) 2019, Ansible Project
5 # Copyright: (c) 2019, Abhijeet Kasurde <akasurde@redhat.com>
6 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
7 # SPDX-License-Identifier: GPL-3.0-or-later
8 
9 from __future__ import absolute_import, division, print_function
10 __metaclass__ = type
11 
12 DOCUMENTATION = r'''
13 ---
14 module: vmware_object_rename
15 short_description: Renames VMware objects
16 description:
17 - This module can be used to rename VMware objects.
18 - All variables and VMware object names are case sensitive.
19 - Renaming Host and Network is not supported by VMware APIs.
20 author:
21 - Abhijeet Kasurde (@Akasurde)
22 requirements:
23 - vSphere Automation SDK
24 options:
25     object_type:
26       description:
27       - Type of object to work with.
28       - Valid options are Cluster, ClusterComputeResource, Datacenter, Datastore, Folder, ResourcePool, VM or VirtualMachine.
29       required: True
30       type: str
31       choices:
32         - 'ClusterComputeResource'
33         - 'Cluster'
34         - 'Datacenter'
35         - 'Datastore'
36         - 'Folder'
37         - 'Network'
38         - 'ResourcePool'
39         - 'VM'
40         - 'VirtualMachine'
41     object_name:
42       description:
43       - Name of the object to work with.
44       - Mutually exclusive with C(object_moid).
45       type: str
46     object_moid:
47       description:
48       - Managed object id of the VMware object to work with.
49       - Mutually exclusive with C(object_name).
50       type: str
51     new_name:
52       description:
53       - New name for VMware object.
54       required: True
55       aliases: ['object_new_name']
56       type: str
57 extends_documentation_fragment:
58 - community.vmware.vmware_rest_client.documentation
59 '''
60 
61 EXAMPLES = r'''
62 - name: Rename a virtual machine
63   community.vmware.vmware_object_rename:
64     hostname: '{{ vcenter_hostname }}'
65     username: '{{ vcenter_username }}'
66     password: '{{ vcenter_password }}'
67     new_name: Fedora_31
68     object_name: Fedora_VM
69     object_type: VirtualMachine
70   delegate_to: localhost
71 
72 - name: Rename a virtual machine using moid
73   community.vmware.vmware_object_rename:
74     hostname: '{{ vcenter_hostname }}'
75     username: '{{ vcenter_username }}'
76     password: '{{ vcenter_password }}'
77     new_name: Fedora_31
78     object_moid: vm-14
79     object_type: VirtualMachine
80   delegate_to: localhost
81 
82 - name: Rename a datacenter
83   community.vmware.vmware_object_rename:
84     hostname: '{{ vcenter_hostname }}'
85     username: '{{ vcenter_username }}'
86     password: '{{ vcenter_password }}'
87     new_name: Asia_Datacenter
88     object_name: dc1
89     object_type: Datacenter
90   delegate_to: localhost
91 
92 - name: Rename a folder with moid
93   community.vmware.vmware_object_rename:
94     hostname: '{{ vcenter_hostname }}'
95     username: '{{ vcenter_username }}'
96     password: '{{ vcenter_password }}'
97     new_name: backup
98     object_moid: group-v46
99     object_type: Folder
100   delegate_to: localhost
101 
102 - name: Rename a cluster with moid
103   community.vmware.vmware_object_rename:
104     hostname: '{{ vcenter_hostname }}'
105     username: '{{ vcenter_username }}'
106     password: '{{ vcenter_password }}'
107     new_name: CCR_1
108     object_moid: domain-c33
109     object_type: Cluster
110   delegate_to: localhost
111 '''
112 
113 RETURN = r'''
114 rename_status:
115     description: metadata about VMware object rename operation
116     returned: on success
117     type: dict
118     sample: {
119         "current_name": "Fedora_31",
120         "desired_name": "Fedora_31",
121         "previous_name": "Fedora_VM",
122     }
123 '''
124 
125 from ansible.module_utils.basic import AnsibleModule
126 from ansible.module_utils._text import to_native
127 from ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient
128 from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi, wait_for_task
129 try:
130     from pyVmomi import vim
131 except ImportError:
132     pass
133 
134 
135 class VmwareObjectRename(VmwareRestClient):
136     def __init__(self, module):
137         """
138         Constructor
139         """
140         super(VmwareObjectRename, self).__init__(module)
141         self.pyv = PyVmomi(module=module)
142         self.soap_stub = self.pyv.si._stub
143 
144         self.object_type = self.params.get('object_type')
145         self.object_name = self.params.get('object_name')
146         self.object_new_name = self.params.get('new_name')
147         self.object_moid = self.params.get('object_moid')
148 
149         self.managed_object = None
150 
151     def ensure_state(self):
152         """
153         Manage the internal state of object rename operation
154 
155         """
156         results = dict(
157             changed=False,
158             rename_status=dict(),
159         )
160 
161         results['rename_status']['desired_name'] = self.object_new_name
162         changed = False
163 
164         vcenter_obj = self.api_client.vcenter
165         available_object_types = [i for i in dir(vcenter_obj) if hasattr(getattr(vcenter_obj, i), 'list') and i != 'Host']
166         available_object_types += ['ClusterComputeResource', 'VirtualMachine']
167 
168         if self.object_type not in available_object_types:
169             self.module.fail_json(msg="Object type can be any"
170                                   " one of [%s]" % ", ".join(available_object_types))
171 
172         valid_object_types = {
173             'ClusterComputeResource': [
174                 vcenter_obj.Cluster,
175                 vim.ClusterComputeResource,
176                 'cluster',
177             ],
178             'Cluster': [
179                 vcenter_obj.Cluster,
180                 vim.ClusterComputeResource,
181                 'cluster',
182             ],
183             'Datacenter': [
184                 vcenter_obj.Datacenter,
185                 vim.Datacenter,
186                 'datacenter',
187             ],
188             'Datastore': [
189                 vcenter_obj.Datastore,
190                 vim.Datastore,
191                 'datastore',
192             ],
193             'Folder': [
194                 vcenter_obj.Folder,
195                 vim.Folder,
196                 'folder',
197             ],
198             'Network': [
199                 vcenter_obj.Network,
200                 vim.ClusterComputeResource,
201                 'network',
202             ],
203             'ResourcePool': [
204                 vcenter_obj.ResourcePool,
205                 vim.ResourcePool,
206                 'resource_pool'
207             ],
208             'VM': [
209                 vcenter_obj.VM,
210                 vim.VirtualMachine,
211                 'vm',
212             ],
213             'VirtualMachine': [
214                 vcenter_obj.VM,
215                 vim.VirtualMachine,
216                 'vm',
217             ],
218         }
219 
220         target_object = valid_object_types[self.object_type][0]
221 
222         # Generate filter spec.
223         # List method will be used in getting objects.
224         # List method can get only up to a max of 1,000 objects.
225         # If VCSA has than 1,000 objects with the specified object_type, the following error will occur.
226         # Error: Too many virtual machines. Add more filter criteria to reduce the number.
227         # To resolve the error, the list method should use the filter spec, to be less than 1,000 objects.
228         filter_spec = target_object.FilterSpec()
229         if self.object_moid:
230             # Make a filter for moid if you specify object_moid.
231             # The moid is a unique id, so get one object if target moid object exists in the vSphere environment.
232             if target_object is vcenter_obj.Datacenter:
233                 filter_spec.datacenters = set([self.object_moid])
234 
235             if target_object is vcenter_obj.Cluster:
236                 filter_spec.clusters = set([self.object_moid])
237 
238             if target_object is vcenter_obj.ResourcePool:
239                 filter_spec.resource_pools = set([self.object_moid])
240 
241             if target_object is vcenter_obj.Folder:
242                 filter_spec.folders = set([self.object_moid])
243 
244             if target_object is vcenter_obj.VM:
245                 filter_spec.vms = set([self.object_moid])
246 
247             if target_object is vcenter_obj.Network:
248                 filter_spec.networks = set([self.object_moid])
249 
250             if target_object is vcenter_obj.Datastore:
251                 filter_spec.datastores = set([self.object_moid])
252         else:
253             # If you use object_name parameter, an object will filter with names.
254             filter_spec.names = set([self.object_name])
255 
256         # Get an object for changing the object name.
257         all_vmware_objs = target_object.list(filter_spec)
258 
259         # Ensure whether already exists an object in the same object_new_name name.
260         existing_obj_moid = None
261         if self.object_moid:
262             if all_vmware_objs:
263                 # Ensure whether the same object name as object_new_name.
264                 if all_vmware_objs[0].name == self.object_new_name:
265                     existing_obj_moid = all_vmware_objs
266         else:
267             existing_obj_moid = target_object.list(target_object.FilterSpec(names=set([self.object_new_name])))
268         if existing_obj_moid:
269             # Object with same name already exists
270             results['rename_status']['current_name'] = results['rename_status']['previous_name'] = self.object_new_name
271             results['changed'] = False
272             self.module.exit_json(**results)
273 
274         if not all_vmware_objs:
275             msg = "Failed to find object with %s '%s' and %s' object type"
276             if self.object_name:
277                 msg = msg % ('name', self.object_name, self.object_type)
278             elif self.object_moid:
279                 msg = msg % ('moid', self.object_moid, self.object_type)
280             self.module.fail_json(msg=msg)
281 
282         obj_moid = getattr(all_vmware_objs[0], valid_object_types[self.object_type][2])
283         vmware_obj = valid_object_types[self.object_type][1](obj_moid, self.soap_stub)
284 
285         if not vmware_obj:
286             msg = "Failed to create VMware object with object %s %s"
287             if self.object_name:
288                 msg = msg % ('name', self.object_name)
289             elif self.object_moid:
290                 msg = msg % ('moid', self.object_moid)
291             self.module.fail_json(msg=msg)
292 
293         try:
294             results['rename_status']['previous_name'] = vmware_obj.name
295             if not self.module.check_mode:
296                 task = vmware_obj.Rename_Task(self.object_new_name)
297                 wait_for_task(task)
298             changed = True
299             results['rename_status']['current_name'] = vmware_obj.name
300         except Exception as e:
301             msg = to_native(e)
302             if hasattr(e, 'msg'):
303                 msg = to_native(e.msg)
304             self.module.fail_json(msg=msg)
305 
306         results['changed'] = changed
307         self.module.exit_json(**results)
308 
309 
310 def main():
311     argument_spec = VmwareRestClient.vmware_client_argument_spec()
312     argument_spec.update(
313         object_name=dict(),
314         object_moid=dict(),
315         new_name=dict(aliases=['object_new_name'], required=True),
316         object_type=dict(type='str', required=True, choices=['ClusterComputeResource', 'Cluster', 'Datacenter',
317                                                              'Datastore', 'Folder', 'Network', 'ResourcePool', 'VM',
318                                                              'VirtualMachine'])
319     )
320     module = AnsibleModule(
321         argument_spec=argument_spec,
322         mutually_exclusive=[
323             ['object_name', 'object_moid'],
324         ]
325     )
326 
327     vmware_object_rename = VmwareObjectRename(module)
328     vmware_object_rename.ensure_state()
329 
330 
331 if __name__ == '__main__':
332     main()
333
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/plugins/modules/vmware_object_rename.py b/plugins/modules/vmware_object_rename.py
--- a/plugins/modules/vmware_object_rename.py
+++ b/plugins/modules/vmware_object_rename.py
@@ -272,7 +272,7 @@
             self.module.exit_json(**results)
 
         if not all_vmware_objs:
-            msg = "Failed to find object with %s '%s' and %s' object type"
+            msg = "Failed to find object with %s '%s' and '%s' object type"
             if self.object_name:
                 msg = msg % ('name', self.object_name, self.object_type)
             elif self.object_moid:

{"golden_diff": "diff --git a/plugins/modules/vmware_object_rename.py b/plugins/modules/vmware_object_rename.py\n--- a/plugins/modules/vmware_object_rename.py\n+++ b/plugins/modules/vmware_object_rename.py\n@@ -272,7 +272,7 @@\n             self.module.exit_json(**results)\n \n         if not all_vmware_objs:\n-            msg = \"Failed to find object with %s '%s' and %s' object type\"\n+            msg = \"Failed to find object with %s '%s' and '%s' object type\"\n             if self.object_name:\n                 msg = msg % ('name', self.object_name, self.object_type)\n             elif self.object_moid:\n", "issue": "Missing Quotation mark in vmware_object_rename error message\n<!--- Verify first that your issue is not already reported on GitHub -->\r\n<!--- Also test if the latest release and devel branch are affected too -->\r\n<!--- Complete *all* sections as described, this form is processed automatically -->\r\n\r\n##### SUMMARY\r\nA question mark before `object type` is missing\r\n\r\nhttps://github.com/ansible-collections/community.vmware/blob/b5eb08db178ead605a0f233f8a88ef6435b5c709/plugins/modules/vmware_object_rename.py#L275\r\n\r\n##### ISSUE TYPE\r\n- Bug Report\r\n\r\n##### COMPONENT NAME\r\nvmware_object_rename\r\n\n", "before_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n# Copyright: (c) 2019, Ansible Project\n# Copyright: (c) 2019, Abhijeet Kasurde <akasurde@redhat.com>\n# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)\n# SPDX-License-Identifier: GPL-3.0-or-later\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\nDOCUMENTATION = r'''\n---\nmodule: vmware_object_rename\nshort_description: Renames VMware objects\ndescription:\n- This module can be used to rename VMware objects.\n- All variables and VMware object names are case sensitive.\n- Renaming Host and Network is not supported by VMware APIs.\nauthor:\n- Abhijeet Kasurde (@Akasurde)\nrequirements:\n- vSphere Automation SDK\noptions:\n    object_type:\n      description:\n      - Type of object to work with.\n      - Valid options are Cluster, ClusterComputeResource, Datacenter, Datastore, Folder, ResourcePool, VM or VirtualMachine.\n      required: True\n      type: str\n      choices:\n        - 'ClusterComputeResource'\n        - 'Cluster'\n        - 'Datacenter'\n        - 'Datastore'\n        - 'Folder'\n        - 'Network'\n        - 'ResourcePool'\n        - 'VM'\n        - 'VirtualMachine'\n    object_name:\n      description:\n      - Name of the object to work with.\n      - Mutually exclusive with C(object_moid).\n      type: str\n    object_moid:\n      description:\n      - Managed object id of the VMware object to work with.\n      - Mutually exclusive with C(object_name).\n      type: str\n    new_name:\n      description:\n      - New name for VMware object.\n      required: True\n      aliases: ['object_new_name']\n      type: str\nextends_documentation_fragment:\n- community.vmware.vmware_rest_client.documentation\n'''\n\nEXAMPLES = r'''\n- name: Rename a virtual machine\n  community.vmware.vmware_object_rename:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    new_name: Fedora_31\n    object_name: Fedora_VM\n    object_type: VirtualMachine\n  delegate_to: localhost\n\n- name: Rename a virtual machine using moid\n  community.vmware.vmware_object_rename:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    new_name: Fedora_31\n    object_moid: vm-14\n    object_type: VirtualMachine\n  delegate_to: localhost\n\n- name: Rename a datacenter\n  community.vmware.vmware_object_rename:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    new_name: Asia_Datacenter\n    object_name: dc1\n    object_type: Datacenter\n  delegate_to: localhost\n\n- name: Rename a folder with moid\n  community.vmware.vmware_object_rename:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    new_name: backup\n    object_moid: group-v46\n    object_type: Folder\n  delegate_to: localhost\n\n- name: Rename a cluster with moid\n  community.vmware.vmware_object_rename:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    new_name: CCR_1\n    object_moid: domain-c33\n    object_type: Cluster\n  delegate_to: localhost\n'''\n\nRETURN = r'''\nrename_status:\n    description: metadata about VMware object rename operation\n    returned: on success\n    type: dict\n    sample: {\n        \"current_name\": \"Fedora_31\",\n        \"desired_name\": \"Fedora_31\",\n        \"previous_name\": \"Fedora_VM\",\n    }\n'''\n\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible.module_utils._text import to_native\nfrom ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient\nfrom ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi, wait_for_task\ntry:\n    from pyVmomi import vim\nexcept ImportError:\n    pass\n\n\nclass VmwareObjectRename(VmwareRestClient):\n    def __init__(self, module):\n        \"\"\"\n        Constructor\n        \"\"\"\n        super(VmwareObjectRename, self).__init__(module)\n        self.pyv = PyVmomi(module=module)\n        self.soap_stub = self.pyv.si._stub\n\n        self.object_type = self.params.get('object_type')\n        self.object_name = self.params.get('object_name')\n        self.object_new_name = self.params.get('new_name')\n        self.object_moid = self.params.get('object_moid')\n\n        self.managed_object = None\n\n    def ensure_state(self):\n        \"\"\"\n        Manage the internal state of object rename operation\n\n        \"\"\"\n        results = dict(\n            changed=False,\n            rename_status=dict(),\n        )\n\n        results['rename_status']['desired_name'] = self.object_new_name\n        changed = False\n\n        vcenter_obj = self.api_client.vcenter\n        available_object_types = [i for i in dir(vcenter_obj) if hasattr(getattr(vcenter_obj, i), 'list') and i != 'Host']\n        available_object_types += ['ClusterComputeResource', 'VirtualMachine']\n\n        if self.object_type not in available_object_types:\n            self.module.fail_json(msg=\"Object type can be any\"\n                                  \" one of [%s]\" % \", \".join(available_object_types))\n\n        valid_object_types = {\n            'ClusterComputeResource': [\n                vcenter_obj.Cluster,\n                vim.ClusterComputeResource,\n                'cluster',\n            ],\n            'Cluster': [\n                vcenter_obj.Cluster,\n                vim.ClusterComputeResource,\n                'cluster',\n            ],\n            'Datacenter': [\n                vcenter_obj.Datacenter,\n                vim.Datacenter,\n                'datacenter',\n            ],\n            'Datastore': [\n                vcenter_obj.Datastore,\n                vim.Datastore,\n                'datastore',\n            ],\n            'Folder': [\n                vcenter_obj.Folder,\n                vim.Folder,\n                'folder',\n            ],\n            'Network': [\n                vcenter_obj.Network,\n                vim.ClusterComputeResource,\n                'network',\n            ],\n            'ResourcePool': [\n                vcenter_obj.ResourcePool,\n                vim.ResourcePool,\n                'resource_pool'\n            ],\n            'VM': [\n                vcenter_obj.VM,\n                vim.VirtualMachine,\n                'vm',\n            ],\n            'VirtualMachine': [\n                vcenter_obj.VM,\n                vim.VirtualMachine,\n                'vm',\n            ],\n        }\n\n        target_object = valid_object_types[self.object_type][0]\n\n        # Generate filter spec.\n        # List method will be used in getting objects.\n        # List method can get only up to a max of 1,000 objects.\n        # If VCSA has than 1,000 objects with the specified object_type, the following error will occur.\n        # Error: Too many virtual machines. Add more filter criteria to reduce the number.\n        # To resolve the error, the list method should use the filter spec, to be less than 1,000 objects.\n        filter_spec = target_object.FilterSpec()\n        if self.object_moid:\n            # Make a filter for moid if you specify object_moid.\n            # The moid is a unique id, so get one object if target moid object exists in the vSphere environment.\n            if target_object is vcenter_obj.Datacenter:\n                filter_spec.datacenters = set([self.object_moid])\n\n            if target_object is vcenter_obj.Cluster:\n                filter_spec.clusters = set([self.object_moid])\n\n            if target_object is vcenter_obj.ResourcePool:\n                filter_spec.resource_pools = set([self.object_moid])\n\n            if target_object is vcenter_obj.Folder:\n                filter_spec.folders = set([self.object_moid])\n\n            if target_object is vcenter_obj.VM:\n                filter_spec.vms = set([self.object_moid])\n\n            if target_object is vcenter_obj.Network:\n                filter_spec.networks = set([self.object_moid])\n\n            if target_object is vcenter_obj.Datastore:\n                filter_spec.datastores = set([self.object_moid])\n        else:\n            # If you use object_name parameter, an object will filter with names.\n            filter_spec.names = set([self.object_name])\n\n        # Get an object for changing the object name.\n        all_vmware_objs = target_object.list(filter_spec)\n\n        # Ensure whether already exists an object in the same object_new_name name.\n        existing_obj_moid = None\n        if self.object_moid:\n            if all_vmware_objs:\n                # Ensure whether the same object name as object_new_name.\n                if all_vmware_objs[0].name == self.object_new_name:\n                    existing_obj_moid = all_vmware_objs\n        else:\n            existing_obj_moid = target_object.list(target_object.FilterSpec(names=set([self.object_new_name])))\n        if existing_obj_moid:\n            # Object with same name already exists\n            results['rename_status']['current_name'] = results['rename_status']['previous_name'] = self.object_new_name\n            results['changed'] = False\n            self.module.exit_json(**results)\n\n        if not all_vmware_objs:\n            msg = \"Failed to find object with %s '%s' and %s' object type\"\n            if self.object_name:\n                msg = msg % ('name', self.object_name, self.object_type)\n            elif self.object_moid:\n                msg = msg % ('moid', self.object_moid, self.object_type)\n            self.module.fail_json(msg=msg)\n\n        obj_moid = getattr(all_vmware_objs[0], valid_object_types[self.object_type][2])\n        vmware_obj = valid_object_types[self.object_type][1](obj_moid, self.soap_stub)\n\n        if not vmware_obj:\n            msg = \"Failed to create VMware object with object %s %s\"\n            if self.object_name:\n                msg = msg % ('name', self.object_name)\n            elif self.object_moid:\n                msg = msg % ('moid', self.object_moid)\n            self.module.fail_json(msg=msg)\n\n        try:\n            results['rename_status']['previous_name'] = vmware_obj.name\n            if not self.module.check_mode:\n                task = vmware_obj.Rename_Task(self.object_new_name)\n                wait_for_task(task)\n            changed = True\n            results['rename_status']['current_name'] = vmware_obj.name\n        except Exception as e:\n            msg = to_native(e)\n            if hasattr(e, 'msg'):\n                msg = to_native(e.msg)\n            self.module.fail_json(msg=msg)\n\n        results['changed'] = changed\n        self.module.exit_json(**results)\n\n\ndef main():\n    argument_spec = VmwareRestClient.vmware_client_argument_spec()\n    argument_spec.update(\n        object_name=dict(),\n        object_moid=dict(),\n        new_name=dict(aliases=['object_new_name'], required=True),\n        object_type=dict(type='str', required=True, choices=['ClusterComputeResource', 'Cluster', 'Datacenter',\n                                                             'Datastore', 'Folder', 'Network', 'ResourcePool', 'VM',\n                                                             'VirtualMachine'])\n    )\n    module = AnsibleModule(\n        argument_spec=argument_spec,\n        mutually_exclusive=[\n            ['object_name', 'object_moid'],\n        ]\n    )\n\n    vmware_object_rename = VmwareObjectRename(module)\n    vmware_object_rename.ensure_state()\n\n\nif __name__ == '__main__':\n    main()\n", "path": "plugins/modules/vmware_object_rename.py"}], "after_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n# Copyright: (c) 2019, Ansible Project\n# Copyright: (c) 2019, Abhijeet Kasurde <akasurde@redhat.com>\n# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)\n# SPDX-License-Identifier: GPL-3.0-or-later\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\nDOCUMENTATION = r'''\n---\nmodule: vmware_object_rename\nshort_description: Renames VMware objects\ndescription:\n- This module can be used to rename VMware objects.\n- All variables and VMware object names are case sensitive.\n- Renaming Host and Network is not supported by VMware APIs.\nauthor:\n- Abhijeet Kasurde (@Akasurde)\nrequirements:\n- vSphere Automation SDK\noptions:\n    object_type:\n      description:\n      - Type of object to work with.\n      - Valid options are Cluster, ClusterComputeResource, Datacenter, Datastore, Folder, ResourcePool, VM or VirtualMachine.\n      required: True\n      type: str\n      choices:\n        - 'ClusterComputeResource'\n        - 'Cluster'\n        - 'Datacenter'\n        - 'Datastore'\n        - 'Folder'\n        - 'Network'\n        - 'ResourcePool'\n        - 'VM'\n        - 'VirtualMachine'\n    object_name:\n      description:\n      - Name of the object to work with.\n      - Mutually exclusive with C(object_moid).\n      type: str\n    object_moid:\n      description:\n      - Managed object id of the VMware object to work with.\n      - Mutually exclusive with C(object_name).\n      type: str\n    new_name:\n      description:\n      - New name for VMware object.\n      required: True\n      aliases: ['object_new_name']\n      type: str\nextends_documentation_fragment:\n- community.vmware.vmware_rest_client.documentation\n'''\n\nEXAMPLES = r'''\n- name: Rename a virtual machine\n  community.vmware.vmware_object_rename:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    new_name: Fedora_31\n    object_name: Fedora_VM\n    object_type: VirtualMachine\n  delegate_to: localhost\n\n- name: Rename a virtual machine using moid\n  community.vmware.vmware_object_rename:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    new_name: Fedora_31\n    object_moid: vm-14\n    object_type: VirtualMachine\n  delegate_to: localhost\n\n- name: Rename a datacenter\n  community.vmware.vmware_object_rename:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    new_name: Asia_Datacenter\n    object_name: dc1\n    object_type: Datacenter\n  delegate_to: localhost\n\n- name: Rename a folder with moid\n  community.vmware.vmware_object_rename:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    new_name: backup\n    object_moid: group-v46\n    object_type: Folder\n  delegate_to: localhost\n\n- name: Rename a cluster with moid\n  community.vmware.vmware_object_rename:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    new_name: CCR_1\n    object_moid: domain-c33\n    object_type: Cluster\n  delegate_to: localhost\n'''\n\nRETURN = r'''\nrename_status:\n    description: metadata about VMware object rename operation\n    returned: on success\n    type: dict\n    sample: {\n        \"current_name\": \"Fedora_31\",\n        \"desired_name\": \"Fedora_31\",\n        \"previous_name\": \"Fedora_VM\",\n    }\n'''\n\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible.module_utils._text import to_native\nfrom ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient\nfrom ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi, wait_for_task\ntry:\n    from pyVmomi import vim\nexcept ImportError:\n    pass\n\n\nclass VmwareObjectRename(VmwareRestClient):\n    def __init__(self, module):\n        \"\"\"\n        Constructor\n        \"\"\"\n        super(VmwareObjectRename, self).__init__(module)\n        self.pyv = PyVmomi(module=module)\n        self.soap_stub = self.pyv.si._stub\n\n        self.object_type = self.params.get('object_type')\n        self.object_name = self.params.get('object_name')\n        self.object_new_name = self.params.get('new_name')\n        self.object_moid = self.params.get('object_moid')\n\n        self.managed_object = None\n\n    def ensure_state(self):\n        \"\"\"\n        Manage the internal state of object rename operation\n\n        \"\"\"\n        results = dict(\n            changed=False,\n            rename_status=dict(),\n        )\n\n        results['rename_status']['desired_name'] = self.object_new_name\n        changed = False\n\n        vcenter_obj = self.api_client.vcenter\n        available_object_types = [i for i in dir(vcenter_obj) if hasattr(getattr(vcenter_obj, i), 'list') and i != 'Host']\n        available_object_types += ['ClusterComputeResource', 'VirtualMachine']\n\n        if self.object_type not in available_object_types:\n            self.module.fail_json(msg=\"Object type can be any\"\n                                  \" one of [%s]\" % \", \".join(available_object_types))\n\n        valid_object_types = {\n            'ClusterComputeResource': [\n                vcenter_obj.Cluster,\n                vim.ClusterComputeResource,\n                'cluster',\n            ],\n            'Cluster': [\n                vcenter_obj.Cluster,\n                vim.ClusterComputeResource,\n                'cluster',\n            ],\n            'Datacenter': [\n                vcenter_obj.Datacenter,\n                vim.Datacenter,\n                'datacenter',\n            ],\n            'Datastore': [\n                vcenter_obj.Datastore,\n                vim.Datastore,\n                'datastore',\n            ],\n            'Folder': [\n                vcenter_obj.Folder,\n                vim.Folder,\n                'folder',\n            ],\n            'Network': [\n                vcenter_obj.Network,\n                vim.ClusterComputeResource,\n                'network',\n            ],\n            'ResourcePool': [\n                vcenter_obj.ResourcePool,\n                vim.ResourcePool,\n                'resource_pool'\n            ],\n            'VM': [\n                vcenter_obj.VM,\n                vim.VirtualMachine,\n                'vm',\n            ],\n            'VirtualMachine': [\n                vcenter_obj.VM,\n                vim.VirtualMachine,\n                'vm',\n            ],\n        }\n\n        target_object = valid_object_types[self.object_type][0]\n\n        # Generate filter spec.\n        # List method will be used in getting objects.\n        # List method can get only up to a max of 1,000 objects.\n        # If VCSA has than 1,000 objects with the specified object_type, the following error will occur.\n        # Error: Too many virtual machines. Add more filter criteria to reduce the number.\n        # To resolve the error, the list method should use the filter spec, to be less than 1,000 objects.\n        filter_spec = target_object.FilterSpec()\n        if self.object_moid:\n            # Make a filter for moid if you specify object_moid.\n            # The moid is a unique id, so get one object if target moid object exists in the vSphere environment.\n            if target_object is vcenter_obj.Datacenter:\n                filter_spec.datacenters = set([self.object_moid])\n\n            if target_object is vcenter_obj.Cluster:\n                filter_spec.clusters = set([self.object_moid])\n\n            if target_object is vcenter_obj.ResourcePool:\n                filter_spec.resource_pools = set([self.object_moid])\n\n            if target_object is vcenter_obj.Folder:\n                filter_spec.folders = set([self.object_moid])\n\n            if target_object is vcenter_obj.VM:\n                filter_spec.vms = set([self.object_moid])\n\n            if target_object is vcenter_obj.Network:\n                filter_spec.networks = set([self.object_moid])\n\n            if target_object is vcenter_obj.Datastore:\n                filter_spec.datastores = set([self.object_moid])\n        else:\n            # If you use object_name parameter, an object will filter with names.\n            filter_spec.names = set([self.object_name])\n\n        # Get an object for changing the object name.\n        all_vmware_objs = target_object.list(filter_spec)\n\n        # Ensure whether already exists an object in the same object_new_name name.\n        existing_obj_moid = None\n        if self.object_moid:\n            if all_vmware_objs:\n                # Ensure whether the same object name as object_new_name.\n                if all_vmware_objs[0].name == self.object_new_name:\n                    existing_obj_moid = all_vmware_objs\n        else:\n            existing_obj_moid = target_object.list(target_object.FilterSpec(names=set([self.object_new_name])))\n        if existing_obj_moid:\n            # Object with same name already exists\n            results['rename_status']['current_name'] = results['rename_status']['previous_name'] = self.object_new_name\n            results['changed'] = False\n            self.module.exit_json(**results)\n\n        if not all_vmware_objs:\n            msg = \"Failed to find object with %s '%s' and '%s' object type\"\n            if self.object_name:\n                msg = msg % ('name', self.object_name, self.object_type)\n            elif self.object_moid:\n                msg = msg % ('moid', self.object_moid, self.object_type)\n            self.module.fail_json(msg=msg)\n\n        obj_moid = getattr(all_vmware_objs[0], valid_object_types[self.object_type][2])\n        vmware_obj = valid_object_types[self.object_type][1](obj_moid, self.soap_stub)\n\n        if not vmware_obj:\n            msg = \"Failed to create VMware object with object %s %s\"\n            if self.object_name:\n                msg = msg % ('name', self.object_name)\n            elif self.object_moid:\n                msg = msg % ('moid', self.object_moid)\n            self.module.fail_json(msg=msg)\n\n        try:\n            results['rename_status']['previous_name'] = vmware_obj.name\n            if not self.module.check_mode:\n                task = vmware_obj.Rename_Task(self.object_new_name)\n                wait_for_task(task)\n            changed = True\n            results['rename_status']['current_name'] = vmware_obj.name\n        except Exception as e:\n            msg = to_native(e)\n            if hasattr(e, 'msg'):\n                msg = to_native(e.msg)\n            self.module.fail_json(msg=msg)\n\n        results['changed'] = changed\n        self.module.exit_json(**results)\n\n\ndef main():\n    argument_spec = VmwareRestClient.vmware_client_argument_spec()\n    argument_spec.update(\n        object_name=dict(),\n        object_moid=dict(),\n        new_name=dict(aliases=['object_new_name'], required=True),\n        object_type=dict(type='str', required=True, choices=['ClusterComputeResource', 'Cluster', 'Datacenter',\n                                                             'Datastore', 'Folder', 'Network', 'ResourcePool', 'VM',\n                                                             'VirtualMachine'])\n    )\n    module = AnsibleModule(\n        argument_spec=argument_spec,\n        mutually_exclusive=[\n            ['object_name', 'object_moid'],\n        ]\n    )\n\n    vmware_object_rename = VmwareObjectRename(module)\n    vmware_object_rename.ensure_state()\n\n\nif __name__ == '__main__':\n    main()\n", "path": "plugins/modules/vmware_object_rename.py"}]}