Skip to content

Commit

Permalink
bug fix for esxi5.5 U3
Browse files Browse the repository at this point in the history
  • Loading branch information
kota.nakamoto committed Apr 8, 2016
1 parent 84b913b commit f0b41c1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 55 deletions.
69 changes: 14 additions & 55 deletions builtin/providers/vsphere/resource_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ func getDatastoreObject(client *govmomi.Client, f *object.DatacenterFolders, nam
}

// buildStoragePlacementSpecCreate builds StoragePlacementSpec for create action.
func buildStoragePlacementSpecCreate(f *object.DatacenterFolders, rp *object.ResourcePool, storagePod object.StoragePod, configSpec types.VirtualMachineConfigSpec) types.StoragePlacementSpec {
func buildStoragePlacementSpecCreate(f *object.DatacenterFolders, rp *object.ResourcePool, storagePod *object.StoragePod, configSpec types.VirtualMachineConfigSpec) types.StoragePlacementSpec {
vmfr := f.VmFolder.Reference()
rpr := rp.Reference()
spr := storagePod.Reference()
Expand All @@ -774,30 +774,16 @@ func buildStoragePlacementSpecCreate(f *object.DatacenterFolders, rp *object.Res
}

// buildStoragePlacementSpecClone builds StoragePlacementSpec for clone action.
func buildStoragePlacementSpecClone(c *govmomi.Client, f *object.DatacenterFolders, vm *object.VirtualMachine, rp *object.ResourcePool, storagePod object.StoragePod) types.StoragePlacementSpec {
func buildStoragePlacementSpecClone(c *govmomi.Client, f *object.DatacenterFolders, vm *object.VirtualMachine, storagePod *object.StoragePod) types.StoragePlacementSpec {
vmr := vm.Reference()
vmfr := f.VmFolder.Reference()
rpr := rp.Reference()
spr := storagePod.Reference()

var o mo.VirtualMachine
err := vm.Properties(context.TODO(), vmr, []string{"datastore"}, &o)
if err != nil {
return types.StoragePlacementSpec{}
}
ds := object.NewDatastore(c.Client, o.Datastore[0])
log.Printf("[DEBUG] findDatastore: datastore: %#v\n", ds)

devices, err := vm.Device(context.TODO())
if err != nil {
return types.StoragePlacementSpec{}
}

var key int
for _, d := range devices.SelectByType((*types.VirtualDisk)(nil)) {
key = d.GetVirtualDevice().Key
log.Printf("[DEBUG] findDatastore: virtual devices: %#v\n", d.GetVirtualDevice())
}

sps := types.StoragePlacementSpec{
Type: "clone",
Expand All @@ -806,16 +792,7 @@ func buildStoragePlacementSpecClone(c *govmomi.Client, f *object.DatacenterFolde
StoragePod: &spr,
},
CloneSpec: &types.VirtualMachineCloneSpec{
Location: types.VirtualMachineRelocateSpec{
Disk: []types.VirtualMachineRelocateSpecDiskLocator{
types.VirtualMachineRelocateSpecDiskLocator{
Datastore: ds.Reference(),
DiskBackingInfo: &types.VirtualDiskFlatVer2BackingInfo{},
DiskId: key,
},
},
Pool: &rpr,
},
Location: types.VirtualMachineRelocateSpec{},
PowerOn: false,
Template: false,
},
Expand Down Expand Up @@ -944,23 +921,14 @@ func (vm *virtualMachine) createVirtualMachine(c *govmomi.Client) error {
} else {
datastore, err = finder.Datastore(context.TODO(), vm.datastore)
if err != nil {
// TODO: datastore cluster support in govmomi finder function
d, err := getDatastoreObject(c, dcFolders, vm.datastore)
sp, err := finder.DatastoreCluster(context.TODO(), vm.datastore)
if err != nil {
return err
}

if d.Type == "StoragePod" {
sp := object.StoragePod{
Folder: object.NewFolder(c.Client, d),
}
sps := buildStoragePlacementSpecCreate(dcFolders, resourcePool, sp, configSpec)
datastore, err = findDatastore(c, sps)
if err != nil {
return err
}
} else {
datastore = object.NewDatastore(c.Client, d)
sps := buildStoragePlacementSpecCreate(dcFolders, resourcePool, sp, configSpec)
datastore, err = findDatastore(c, sps)
if err != nil {
return err
}
}
}
Expand Down Expand Up @@ -1076,24 +1044,15 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
} else {
datastore, err = finder.Datastore(context.TODO(), vm.datastore)
if err != nil {
// TODO: datastore cluster support in govmomi finder function
d, err := getDatastoreObject(c, dcFolders, vm.datastore)
// search datastore cluster
sp, err := finder.DatastoreCluster(context.TODO(), vm.datastore)
if err != nil {
return err
}

if d.Type == "StoragePod" {
sp := object.StoragePod{
Folder: object.NewFolder(c.Client, d),
}
sps := buildStoragePlacementSpecClone(c, dcFolders, template, resourcePool, sp)

datastore, err = findDatastore(c, sps)
if err != nil {
return err
}
} else {
datastore = object.NewDatastore(c.Client, d)
sps := buildStoragePlacementSpecClone(c, dcFolders, template, sp)
datastore, err = findDatastore(c, sps)
if err != nil {
return err
}
}
}
Expand Down
57 changes: 57 additions & 0 deletions vendor/github.com/vmware/govmomi/find/finder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions vendor/github.com/vmware/govmomi/object/storage_pod.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f0b41c1

Please sign in to comment.