Skip to content

Commit

Permalink
Add possiblity to tell vsphere_copy which diskformat is being uploaded (
Browse files Browse the repository at this point in the history
#1995)

Add possiblity to tell vsphere_copy which diskformat is being uploaded

SUMMARY
Add possiblity to tell vsphere_copy which diskformat is being uploaded
ISSUE TYPE


Feature Pull Request

COMPONENT NAME
vsphere_copy
ADDITIONAL INFORMATION
Related issue: vmware/pyvmomi#1064
- 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

Reviewed-by: Mario Lenz <[email protected]>
Reviewed-by: Alexander Nikitin <[email protected]>
Reviewed-by: Klaas Demter
  • Loading branch information
Klaas- authored Feb 15, 2024
1 parent 4ce1264 commit 322f0c2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1995-vsphere_copy.yml
Original file line number Diff line number Diff line change
@@ -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).
31 changes: 28 additions & 3 deletions plugins/modules/vsphere_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
- The timeout in seconds for the upload to the datastore.
default: 10
type: int
diskformat:
version_added: 4.2.0
description:
- 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:
- "This module ought to be run from a system that can access the vCenter or the ESXi directly and has the file to transfer.
Expand Down Expand Up @@ -87,6 +95,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
Expand All @@ -103,7 +124,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
Expand All @@ -114,6 +135,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)

Expand All @@ -125,7 +148,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', choices=['streamVmdk']))
)

module = AnsibleModule(
Expand All @@ -141,6 +165,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')

Expand All @@ -156,7 +181,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")
Expand Down

0 comments on commit 322f0c2

Please sign in to comment.