Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possiblity to tell vsphere_copy which diskformat is being uploaded #1995

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions plugins/modules/vsphere_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
- The timeout in seconds for the upload to the datastore.
default: 10
type: int
diskformat:
version_added: 4.2.0
description:
mariolenz marked this conversation as resolved.
Show resolved Hide resolved
- 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
ihumster marked this conversation as resolved.
Show resolved Hide resolved

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 +93,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 +122,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 +133,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 +146,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'))
mariolenz marked this conversation as resolved.
Show resolved Hide resolved
mariolenz marked this conversation as resolved.
Show resolved Hide resolved
ihumster marked this conversation as resolved.
Show resolved Hide resolved
)

module = AnsibleModule(
Expand All @@ -141,6 +163,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 +179,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
Loading