From 950c34ae6c2d809dc785192b9896898dbcb79b92 Mon Sep 17 00:00:00 2001 From: Victor Michel Date: Thu, 29 Apr 2021 11:15:30 -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 --- 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)