Skip to content

Commit 322f0c2

Browse files
authored
Add possiblity to tell vsphere_copy which diskformat is being uploaded (#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 <m@riolenz.de> Reviewed-by: Alexander Nikitin <ihumster@ihumster.ru> Reviewed-by: Klaas Demter
1 parent 4ce1264 commit 322f0c2

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- vsphere_copy - Add parameter to tell vsphere_copy which diskformat is being uploaded (https://github.com/ansible-collections/community.vmware/pull/1995).

plugins/modules/vsphere_copy.py

+28-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@
4545
- The timeout in seconds for the upload to the datastore.
4646
default: 10
4747
type: int
48+
diskformat:
49+
version_added: 4.2.0
50+
description:
51+
- Optional argument - Set a diskformat for certain uploads like stream optimized VMDKs
52+
- 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
53+
- Setting this for non-VMDK files might lead to undefined behavior and is not supported.
54+
choices: ["streamVmdk"]
55+
type: str
4856
4957
notes:
5058
- "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 +95,19 @@
8795
datastore: datastore2
8896
path: other/remote/file
8997
delegate_to: other_system
98+
99+
- name: Copy file to datastore using other_system
100+
community.vmware.vsphere_copy:
101+
hostname: '{{ vcenter_hostname }}'
102+
username: '{{ vcenter_username }}'
103+
password: '{{ vcenter_password }}'
104+
src: /other/local/streamOptimized.vmdk
105+
datacenter: DC2 Someplace
106+
datastore: datastore2
107+
path: disk_imports/streamOptimized.vmdk
108+
timeout: 360
109+
diskformat: StreamVmdk
110+
delegate_to: other_system
90111
'''
91112

92113
import atexit
@@ -103,7 +124,7 @@
103124
from ansible_collections.community.vmware.plugins.module_utils.vmware import vmware_argument_spec
104125

105126

106-
def vmware_path(datastore, datacenter, path):
127+
def vmware_path(datastore, datacenter, path, diskformat):
107128
''' Constructs a URL path that vSphere accepts reliably '''
108129
path = "/folder/%s" % quote(path.lstrip("/"))
109130
# Due to a software bug in vSphere, it fails to handle ampersand in datacenter names
@@ -114,6 +135,8 @@ def vmware_path(datastore, datacenter, path):
114135
if datacenter:
115136
datacenter = datacenter.replace('&', '%26')
116137
params["dcPath"] = datacenter
138+
if diskformat:
139+
params["diskFormat"] = diskformat
117140
params = urlencode(params)
118141
return "%s?%s" % (path, params)
119142

@@ -125,7 +148,8 @@ def main():
125148
datacenter=dict(required=False),
126149
datastore=dict(required=True),
127150
path=dict(required=True, aliases=['dest'], type='str'),
128-
timeout=dict(default=10, type='int'))
151+
timeout=dict(default=10, type='int'),
152+
diskformat=dict(required=False, type='str', choices=['streamVmdk']))
129153
)
130154

131155
module = AnsibleModule(
@@ -141,6 +165,7 @@ def main():
141165
datacenter = module.params.get('datacenter')
142166
datastore = module.params.get('datastore')
143167
path = module.params.get('path')
168+
diskformat = module.params.get('diskformat')
144169
validate_certs = module.params.get('validate_certs')
145170
timeout = module.params.get('timeout')
146171

@@ -156,7 +181,7 @@ def main():
156181
data = mmap.mmap(fd.fileno(), 0, access=mmap.ACCESS_READ)
157182
atexit.register(data.close)
158183

159-
remote_path = vmware_path(datastore, datacenter, path)
184+
remote_path = vmware_path(datastore, datacenter, path, diskformat)
160185

161186
if not all([hostname, username, password]):
162187
module.fail_json(msg="One of following parameter is missing - hostname, username, password")

0 commit comments

Comments
 (0)