Quantcast
Channel: VMware Communities : All Content - vSphere Management SDK
Viewing all articles
Browse latest Browse all 1860

InitiateFileTransferToGuest copies file filled with NULL to vm

$
0
0

Hi,

I am using pyvmomi to automate some of our testing activities. There are several threads which read a single configuration file(ending with py), make some changes and then write this file with overwrite enabled to some vms. The configuration file is read with 'rb' mode in python. In most of the cases, if I open the configuration file on the vm, it is filled with NULLs due to which tests dont kick start on the vm. For my reference I am writing the modified file contents to the local disk of the system from where I am triggering the pyvmomi script. All the times, these local files will contain valid text, but on the corresponding vm, the file will be filled with NULL.

Following is the some part of the code which I am using.

self.creds = vim.vm.guest.NamePasswordAuthentication(username=vmusername, password=vmpassword)
self.si = SmartConnect(host=esx_ip, user=esx_user, pwd=esx_password)
self.vm = search_index.FindByUuid(None, self.targethost, True, False)
self.content = self.si.RetrieveContent()
filecontent = myfile.read().replace(some_string,some_other_string)

some code..

try:    fileattrib = vim.vm.guest.FileManager.FileAttributes()    url = self.content.guestOperationsManager.fileManager.InitiateFileTransferToGuest(self.vm, self.creds, hostfilename, fileattrib, len(filecontent), True)    resp = requests.put(url, data=filecontent, verify=False)    if not resp.status_code == 200:        self.logger.error("Error uploading config")        sys.exit(1)    else:        self.logger.info("Successfully uploaded the config")except Exception as e:    self.logger.error(e)    sys.exit(1)

Is there anything wrong in what I am doing? 


Viewing all articles
Browse latest Browse all 1860

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>