Fixing hard disk path when specifying only size (#6400)

We were passing in a disk path of `[datastore] `, which the createDisk
call would create a file named `.vmdk` on the datastore, which is not
the expected behavior.  This make sure that if the user did not pass in
a vmdk path, that we call CreateDisk with an empty string like it
expects.
This commit is contained in:
dkalleg 2016-04-28 16:44:30 -07:00 committed by Paul Stack
parent 64c1280951
commit 6e5da78f79
1 changed files with 9 additions and 2 deletions

View File

@ -811,8 +811,15 @@ func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, d
}
log.Printf("[DEBUG] disk controller: %#v\n", controller)
// TODO Check if diskPath & datastore exist
disk := devices.CreateDisk(controller, fmt.Sprintf("[%v] %v", datastore.Name(), diskPath))
// If diskPath is not specified, pass empty string to CreateDisk()
var newDiskPath string
if diskPath == "" {
newDiskPath = ""
} else {
// TODO Check if diskPath & datastore exist
newDiskPath = fmt.Sprintf("[%v] %v", datastore.Name(), diskPath)
}
disk := devices.CreateDisk(controller, newDiskPath)
existing := devices.SelectByBackingInfo(disk.Backing)
log.Printf("[DEBUG] disk: %#v\n", disk)