Skip to content

Commit

Permalink
Fix unable to access the virtual machine configuration error
Browse files Browse the repository at this point in the history
  • Loading branch information
sneal committed Aug 25, 2022
1 parent 019c800 commit efdd3e9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/vcenter/relocate_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/vim25/types"
"sort"
)

type RelocateSpec struct {
Expand Down Expand Up @@ -91,6 +92,15 @@ func (rs *RelocateSpec) Build(ctx context.Context) (*types.VirtualMachineRelocat
})
}

if len(diskMappings) == 0 {
return nil, fmt.Errorf("found 0 disk mappings for VM %s", rs.srcVM.Name)
}

// ensure first device is first in list - below we use that as the default datastore for the VM
sort.Slice(diskMappings, func(i, j int) bool {
return diskMappings[i].DiskId < diskMappings[j].DiskId
})

adapterUpdater := NewAdapterUpdater(destinationFinder)
var devicesToChange []types.BaseVirtualDeviceConfigSpec
for sourceNetName, targetNetName := range rs.vmTargetSpec.Networks {
Expand All @@ -113,6 +123,7 @@ func (rs *RelocateSpec) Build(ctx context.Context) (*types.VirtualMachineRelocat
spec := &types.VirtualMachineRelocateSpec{}
spec.Host = &hostRef
spec.Pool = poolRef
spec.Datastore = &diskMappings[0].Datastore
spec.Disk = diskMappings
spec.DeviceChange = devicesToChange

Expand Down

0 comments on commit efdd3e9

Please sign in to comment.