From 990623cf41183e05fdc4e1d730c7d89e761dbaac Mon Sep 17 00:00:00 2001 From: Klaas Demter Date: Thu, 8 Feb 2024 14:57:59 +0100 Subject: [PATCH 1/5] Add possiblity to tell vsphere_copy which diskformat is being uploaded --- plugins/modules/vsphere_copy.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/plugins/modules/vsphere_copy.py b/plugins/modules/vsphere_copy.py index 3fe227e68..3e7b74d17 100644 --- a/plugins/modules/vsphere_copy.py +++ b/plugins/modules/vsphere_copy.py @@ -45,6 +45,11 @@ - The timeout in seconds for the upload to the datastore. default: 10 type: int + diskformat: + description: + - Optional argument - Set a diskformat for certain uploads like stream optimized vmdks + - Example "StreamVmdk" needs to be set for stream optimized vmdks that are uploaded to vSAN storage + type: str notes: - "This module ought to be run from a system that can access the vCenter or the ESXi directly and has the file to transfer. @@ -87,6 +92,19 @@ datastore: datastore2 path: other/remote/file delegate_to: other_system + +- name: Copy file to datastore using other_system + community.vmware.vsphere_copy: + hostname: '{{ vcenter_hostname }}' + username: '{{ vcenter_username }}' + password: '{{ vcenter_password }}' + src: /other/local/streamOptimized.vmdk + datacenter: DC2 Someplace + datastore: datastore2 + path: disk_imports/streamOptimized.vmdk + timeout: 360 + diskformat: StreamVmdk + delegate_to: other_system ''' import atexit @@ -103,7 +121,7 @@ from ansible_collections.community.vmware.plugins.module_utils.vmware import vmware_argument_spec -def vmware_path(datastore, datacenter, path): +def vmware_path(datastore, datacenter, path, diskformat): ''' Constructs a URL path that vSphere accepts reliably ''' path = "/folder/%s" % quote(path.lstrip("/")) # Due to a software bug in vSphere, it fails to handle ampersand in datacenter names @@ -114,6 +132,8 @@ def vmware_path(datastore, datacenter, path): if datacenter: datacenter = datacenter.replace('&', '%26') params["dcPath"] = datacenter + if diskformat: + params["diskFormat"] = diskformat params = urlencode(params) return "%s?%s" % (path, params) @@ -125,7 +145,8 @@ def main(): datacenter=dict(required=False), datastore=dict(required=True), path=dict(required=True, aliases=['dest'], type='str'), - timeout=dict(default=10, type='int')) + timeout=dict(default=10, type='int'), + diskformat=dict(required=False, type='str')) ) module = AnsibleModule( @@ -141,6 +162,7 @@ def main(): datacenter = module.params.get('datacenter') datastore = module.params.get('datastore') path = module.params.get('path') + diskformat = module.params.get('diskformat') validate_certs = module.params.get('validate_certs') timeout = module.params.get('timeout') @@ -156,7 +178,7 @@ def main(): data = mmap.mmap(fd.fileno(), 0, access=mmap.ACCESS_READ) atexit.register(data.close) - remote_path = vmware_path(datastore, datacenter, path) + remote_path = vmware_path(datastore, datacenter, path, diskformat) if not all([hostname, username, password]): module.fail_json(msg="One of following parameter is missing - hostname, username, password") From 6d4adad539976d4f528d85dc0f67620ceee7680e Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Mon, 12 Feb 2024 13:41:03 +0100 Subject: [PATCH 2/5] Add version_added --- plugins/modules/vsphere_copy.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/vsphere_copy.py b/plugins/modules/vsphere_copy.py index 3e7b74d17..80767b809 100644 --- a/plugins/modules/vsphere_copy.py +++ b/plugins/modules/vsphere_copy.py @@ -46,6 +46,7 @@ default: 10 type: int diskformat: + version_added: 4.2.0 description: - Optional argument - Set a diskformat for certain uploads like stream optimized vmdks - Example "StreamVmdk" needs to be set for stream optimized vmdks that are uploaded to vSAN storage From 3cdcc39a736b4d6bb2bfa7ff93932f97b61c04e7 Mon Sep 17 00:00:00 2001 From: Alexander Nikitin Date: Mon, 12 Feb 2024 17:41:52 +0300 Subject: [PATCH 3/5] Update plugins/modules/vsphere_copy.py Co-authored-by: Mario Lenz --- plugins/modules/vsphere_copy.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/modules/vsphere_copy.py b/plugins/modules/vsphere_copy.py index 80767b809..51c4e4cdb 100644 --- a/plugins/modules/vsphere_copy.py +++ b/plugins/modules/vsphere_copy.py @@ -48,8 +48,10 @@ diskformat: version_added: 4.2.0 description: - - Optional argument - Set a diskformat for certain uploads like stream optimized vmdks - - Example "StreamVmdk" needs to be set for stream optimized vmdks that are uploaded to vSAN storage + - Optional argument - Set a diskformat for certain uploads like stream optimized VMDKs + - There is no official documentation, but it looks like V(StreamVmdk) needs to be set for stream optimized VMDKs that are uploaded to vSAN storage + - Setting this for non-VMDK files might lead to undefined behavior and is not supported. + choices: ["streamVmdk"] type: str notes: From f6b8fcbcab30252b2d82e557decff35f11e0d00f Mon Sep 17 00:00:00 2001 From: Alexander Nikitin Date: Mon, 12 Feb 2024 17:42:02 +0300 Subject: [PATCH 4/5] Update plugins/modules/vsphere_copy.py Co-authored-by: Mario Lenz --- plugins/modules/vsphere_copy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/vsphere_copy.py b/plugins/modules/vsphere_copy.py index 51c4e4cdb..4fde785ed 100644 --- a/plugins/modules/vsphere_copy.py +++ b/plugins/modules/vsphere_copy.py @@ -149,7 +149,7 @@ def main(): datastore=dict(required=True), path=dict(required=True, aliases=['dest'], type='str'), timeout=dict(default=10, type='int'), - diskformat=dict(required=False, type='str')) + diskformat=dict(required=False, type='str', choices=['streamVmdk'])) ) module = AnsibleModule( From 2f632141abb19bf88190179e664f661cc54ae5d1 Mon Sep 17 00:00:00 2001 From: Klaas Demter Date: Thu, 15 Feb 2024 03:24:46 +0100 Subject: [PATCH 5/5] Add changelog fragment for vsphere_copy diskformat --- changelogs/fragments/1995-vsphere_copy.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/1995-vsphere_copy.yml diff --git a/changelogs/fragments/1995-vsphere_copy.yml b/changelogs/fragments/1995-vsphere_copy.yml new file mode 100644 index 000000000..df77a0e1f --- /dev/null +++ b/changelogs/fragments/1995-vsphere_copy.yml @@ -0,0 +1,2 @@ +minor_changes: + - vsphere_copy - Add parameter to tell vsphere_copy which diskformat is being uploaded (https://github.com/ansible-collections/community.vmware/pull/1995). \ No newline at end of file