Skip to content

Commit

Permalink
VMware: vmware_export_ovf fix timeout and export path issue (ansible#…
Browse files Browse the repository at this point in the history
…60062)

* fix timeout and export path issue

* change path type
  • Loading branch information
Tomorrow9 authored and ansibot committed Aug 7, 2019
1 parent 279617a commit d5bff7a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/ansible/modules/cloud/vmware/vmware_export_ovf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@
- Absolute path to place the exported files on the server running this task, must have write permission.
- If folder not exist will create it, also create a folder under this path named with VM name.
required: yes
type: str
type: path
export_with_images:
default: false
description:
- Export an ISO image of the media mounted on the CD/DVD Drive within the virtual machine.
type: bool
download_timeout:
description:
- The user defined timeout in minute of exporting file.
- If the vmdk file is too large to export in 10 minutes, specify the value larger than 10, the maximum value is 60.
default: 10
type: int
version_added: '2.9'
extends_documentation_fragment: vmware.documentation
'''

Expand Down Expand Up @@ -156,6 +163,7 @@ def __init__(self, module):
# set lease progress update interval to 15 seconds
self.lease_interval = 15
self.facts = {'device_files': []}
self.download_timeout = 10

def create_export_dir(self, vm_obj):
self.ovf_dir = os.path.join(self.params['export_dir'], vm_obj.name)
Expand All @@ -175,7 +183,7 @@ def download_device_files(self, headers, temp_target_disk, device_url, lease_upd
with open(self.mf_file, 'a') as mf_handle:
with open(temp_target_disk, 'wb') as handle:
try:
response = open_url(device_url, headers=headers, validate_certs=False)
response = open_url(device_url, headers=headers, validate_certs=False, timeout=self.download_timeout)
except Exception as err:
lease_updater.httpNfcLease.HttpNfcLeaseAbort()
lease_updater.stop()
Expand Down Expand Up @@ -208,6 +216,9 @@ def export_to_ovf_files(self, vm_obj):
export_with_iso = False
if 'export_with_images' in self.params and self.params['export_with_images']:
export_with_iso = True
if 60 > self.params['download_timeout'] > 10:
self.download_timeout = self.params['download_timeout']

ovf_files = []
# get http nfc lease firstly
http_nfc_lease = vm_obj.ExportVm()
Expand Down Expand Up @@ -318,8 +329,9 @@ def main():
moid=dict(type='str'),
folder=dict(type='str'),
datacenter=dict(type='str', default='ha-datacenter'),
export_dir=dict(type='str'),
export_dir=dict(type='path', required=True),
export_with_images=dict(type='bool', default=False),
download_timeout=dict(type='int', default=10),
)

module = AnsibleModule(argument_spec=argument_spec,
Expand Down

0 comments on commit d5bff7a

Please sign in to comment.