From 08edace5983f08d9c70fe628318216862f9dd6a2 Mon Sep 17 00:00:00 2001 From: vmichel95 Date: Tue, 11 May 2021 05:36:22 -0400 Subject: [PATCH] Correcting VMWare resource reference value lookup order for ResourcePool and VMHomeStorage since they are dependent on the original input values for Cluster and Host (#58) --- builder/vsphere/driver/vm.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/builder/vsphere/driver/vm.go b/builder/vsphere/driver/vm.go index 3b6e1a79..4fb9fa4f 100644 --- a/builder/vsphere/driver/vm.go +++ b/builder/vsphere/driver/vm.go @@ -783,6 +783,21 @@ func (vm *VirtualMachineDriver) ImportToContentLibrary(template vcenter.Template template.Library = l.library.ID template.SourceVM = vm.vm.Reference().Value + if template.Placement.ResourcePool != "" { + rp, err := vm.driver.FindResourcePool(template.Placement.Cluster, template.Placement.Host, template.Placement.ResourcePool) + if err != nil { + return err + } + template.Placement.ResourcePool = rp.pool.Reference().Value + } + if template.VMHomeStorage != nil { + d, err := vm.driver.FindDatastore(template.VMHomeStorage.Datastore, template.Placement.Host) + if err != nil { + return err + } + template.VMHomeStorage.Datastore = d.Reference().Value + } + if template.Placement.Cluster != "" { c, err := vm.driver.FindCluster(template.Placement.Cluster) if err != nil { @@ -804,21 +819,6 @@ func (vm *VirtualMachineDriver) ImportToContentLibrary(template vcenter.Template } template.Placement.Host = h.host.Reference().Value } - if template.Placement.ResourcePool != "" { - rp, err := vm.driver.FindResourcePool(template.Placement.Cluster, template.Placement.Host, template.Placement.ResourcePool) - if err != nil { - return err - } - template.Placement.ResourcePool = rp.pool.Reference().Value - } - - if template.VMHomeStorage != nil { - d, err := vm.driver.FindDatastore(template.VMHomeStorage.Datastore, template.Placement.Host) - if err != nil { - return err - } - template.VMHomeStorage.Datastore = d.Reference().Value - } vcm := vcenter.NewManager(vm.driver.restClient.client) _, err = vcm.CreateTemplate(vm.driver.ctx, template)