Skip to content

Commit

Permalink
Correcting VMWare resource reference value lookup order for ResourceP…
Browse files Browse the repository at this point in the history
…ool and VMHomeStorage since they are dependent on the original input values for Cluster and Host (#58)
  • Loading branch information
vmichel95 authored May 11, 2021
1 parent 355dd0c commit 08edace
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions builder/vsphere/driver/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 08edace

Please sign in to comment.