Skip to content

Commit 990623c

Browse files
authored
Add possiblity to tell vsphere_copy which diskformat is being uploaded
1 parent 7632a2f commit 990623c

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

plugins/modules/vsphere_copy.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
- The timeout in seconds for the upload to the datastore.
4646
default: 10
4747
type: int
48+
diskformat:
49+
description:
50+
- Optional argument - Set a diskformat for certain uploads like stream optimized vmdks
51+
- Example "StreamVmdk" needs to be set for stream optimized vmdks that are uploaded to vSAN storage
52+
type: str
4853
4954
notes:
5055
- "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 @@
8792
datastore: datastore2
8893
path: other/remote/file
8994
delegate_to: other_system
95+
96+
- name: Copy file to datastore using other_system
97+
community.vmware.vsphere_copy:
98+
hostname: '{{ vcenter_hostname }}'
99+
username: '{{ vcenter_username }}'
100+
password: '{{ vcenter_password }}'
101+
src: /other/local/streamOptimized.vmdk
102+
datacenter: DC2 Someplace
103+
datastore: datastore2
104+
path: disk_imports/streamOptimized.vmdk
105+
timeout: 360
106+
diskformat: StreamVmdk
107+
delegate_to: other_system
90108
'''
91109

92110
import atexit
@@ -103,7 +121,7 @@
103121
from ansible_collections.community.vmware.plugins.module_utils.vmware import vmware_argument_spec
104122

105123

106-
def vmware_path(datastore, datacenter, path):
124+
def vmware_path(datastore, datacenter, path, diskformat):
107125
''' Constructs a URL path that vSphere accepts reliably '''
108126
path = "/folder/%s" % quote(path.lstrip("/"))
109127
# 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):
114132
if datacenter:
115133
datacenter = datacenter.replace('&', '%26')
116134
params["dcPath"] = datacenter
135+
if diskformat:
136+
params["diskFormat"] = diskformat
117137
params = urlencode(params)
118138
return "%s?%s" % (path, params)
119139

@@ -125,7 +145,8 @@ def main():
125145
datacenter=dict(required=False),
126146
datastore=dict(required=True),
127147
path=dict(required=True, aliases=['dest'], type='str'),
128-
timeout=dict(default=10, type='int'))
148+
timeout=dict(default=10, type='int'),
149+
diskformat=dict(required=False, type='str'))
129150
)
130151

131152
module = AnsibleModule(
@@ -141,6 +162,7 @@ def main():
141162
datacenter = module.params.get('datacenter')
142163
datastore = module.params.get('datastore')
143164
path = module.params.get('path')
165+
diskformat = module.params.get('diskformat')
144166
validate_certs = module.params.get('validate_certs')
145167
timeout = module.params.get('timeout')
146168

@@ -156,7 +178,7 @@ def main():
156178
data = mmap.mmap(fd.fileno(), 0, access=mmap.ACCESS_READ)
157179
atexit.register(data.close)
158180

159-
remote_path = vmware_path(datastore, datacenter, path)
181+
remote_path = vmware_path(datastore, datacenter, path, diskformat)
160182

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

0 commit comments

Comments
 (0)