VMware: Fix file operation to work with ESXi directly (#40148)

Now, file_operation module can be used with both vCenter and Standalone ESXi server.
pull/40535/head
Stéphane Travassac 7 years ago committed by Abhijeet Kasurde
parent da79989e70
commit c29b03e77b

@ -277,6 +277,7 @@ class VmwareGuestFileManager(PyVmomi):
result = dict(changed=True, uuid=self.vm.summary.config.uuid) result = dict(changed=True, uuid=self.vm.summary.config.uuid)
vm_username = self.module.params['vm_username'] vm_username = self.module.params['vm_username']
vm_password = self.module.params['vm_password'] vm_password = self.module.params['vm_password']
hostname = self.module.params['hostname']
dest = self.module.params["fetch"]['dest'] dest = self.module.params["fetch"]['dest']
src = self.module.params['fetch']['src'] src = self.module.params['fetch']['src']
creds = vim.vm.guest.NamePasswordAuthentication(username=vm_username, password=vm_password) creds = vim.vm.guest.NamePasswordAuthentication(username=vm_username, password=vm_password)
@ -286,6 +287,7 @@ class VmwareGuestFileManager(PyVmomi):
fileTransferInfo = file_manager.InitiateFileTransferFromGuest(vm=self.vm, auth=creds, fileTransferInfo = file_manager.InitiateFileTransferFromGuest(vm=self.vm, auth=creds,
guestFilePath=src) guestFilePath=src)
url = fileTransferInfo.url url = fileTransferInfo.url
url = url.replace("*", hostname)
resp, info = urls.fetch_url(self.module, url, method="GET") resp, info = urls.fetch_url(self.module, url, method="GET")
try: try:
with open(dest, "wb") as local_file: with open(dest, "wb") as local_file:
@ -316,6 +318,7 @@ class VmwareGuestFileManager(PyVmomi):
result = dict(changed=True, uuid=self.vm.summary.config.uuid) result = dict(changed=True, uuid=self.vm.summary.config.uuid)
vm_username = self.module.params['vm_username'] vm_username = self.module.params['vm_username']
vm_password = self.module.params['vm_password'] vm_password = self.module.params['vm_password']
hostname = self.module.params['hostname']
overwrite = self.module.params["copy"]["overwrite"] overwrite = self.module.params["copy"]["overwrite"]
dest = self.module.params["copy"]['dest'] dest = self.module.params["copy"]['dest']
src = self.module.params['copy']['src'] src = self.module.params['copy']['src']
@ -340,6 +343,7 @@ class VmwareGuestFileManager(PyVmomi):
url = file_manager.InitiateFileTransferToGuest(vm=self.vm, auth=creds, guestFilePath=dest, url = file_manager.InitiateFileTransferToGuest(vm=self.vm, auth=creds, guestFilePath=dest,
fileAttributes=file_attributes, overwrite=overwrite, fileAttributes=file_attributes, overwrite=overwrite,
fileSize=file_size) fileSize=file_size)
url = url.replace("*", hostname)
resp, info = urls.fetch_url(self.module, url, data=data, method="PUT") resp, info = urls.fetch_url(self.module, url, data=data, method="PUT")
status_code = info["status"] status_code = info["status"]

Loading…
Cancel
Save