Skip to content

getDstVmxFile and readVMXContents functions incorrectly treat file path with spacesΒ #124

@drbolsen

Description

@drbolsen

Summary

Another bug related to incorrect assumption that a value, in this case a file path, doesn't contain spaces.

A have legacy VM that has the following path for vmx file

/vmfs/volumes/datastore-ssd-1/Storage\ Windows\ Server\ 2012\ R2/Storage\ Windows\ Server\ 2012\ R2.vmx

Both getDstVmxFile and readVMXContents functions have quite similar code:

	command = fmt.Sprintf("vim-cmd vmsvc/get.config %s | grep vmPathName|awk '{print $NF}'|sed 's/[\"|,]//g'", vm.Id)
	stdout, _ = esxi.Execute(command, "get dst_vmx")
	dstVmx := stdout

awk '{print $NF}' prints the last column, where columns are sliced by space/tab.

The next command sed 's/[\"|,]//g' removes trailing double quote and comma.

Therefore in my case the output would be just R2.vmx.

Obviously, the downstream code is not able to find and read the file, resulting in some garbage values.

Also, I noticed that both functions are calling remote command execution vim-cmd vmsvc/get.config %s | grep vmPathName twice, first one to get the datastore name and the second to get vmx file path.

This seems unnecessary and expensive as a single call already returns a string that can be parsed by the plugin itself to extract required values therefore saving on a second remote call and execution.

Diagnostics

What version of the provider are you running?

The plugin version is 1.0.0


Message from the maintainers:

Impacted by this bug? Give it a πŸ‘. We prioritise the issues with the most πŸ‘.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions