From 8a5d988a4916612f3e062f9e9abe0842dea3bd2e Mon Sep 17 00:00:00 2001 From: Liran Rotenberg Date: Thu, 13 Jun 2024 18:10:49 +0300 Subject: [PATCH] Build the VM with OS from the VM's status Since we now have the Operation System from virt-v2v in the VM's status, use it in order to get the right preference or template when building and creating a VM. Signed-off-by: Liran Rotenberg --- .../plan/adapter/vsphere/builder.go | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/pkg/controller/plan/adapter/vsphere/builder.go b/pkg/controller/plan/adapter/vsphere/builder.go index da23058be..2c866941f 100644 --- a/pkg/controller/plan/adapter/vsphere/builder.go +++ b/pkg/controller/plan/adapter/vsphere/builder.go @@ -756,12 +756,14 @@ func (r *Builder) Tasks(vmRef ref.Ref) (list []*plan.Task, err error) { } func (r *Builder) PreferenceName(vmRef ref.Ref, configMap *core.ConfigMap) (name string, err error) { - vm := &model.Workload{} - if err = r.Source.Inventory.Find(vm, vmRef); err != nil { - err = liberr.Wrap(err, "vm", vmRef.String()) - return + var os string + for _, vmConf := range r.Migration.Status.VMs { + if vmConf.ID == vmRef.ID { + os = vmConf.OperationSystem + break + } } - name, ok := configMap.Data[vm.GuestID] + name, ok := configMap.Data[os] if !ok { err = liberr.Wrap(err, "vm", vmRef.String()) } @@ -769,19 +771,19 @@ func (r *Builder) PreferenceName(vmRef ref.Ref, configMap *core.ConfigMap) (name } func (r *Builder) TemplateLabels(vmRef ref.Ref) (labels map[string]string, err error) { - vm := &model.VM{} - err = r.Source.Inventory.Find(vm, vmRef) - if err != nil { - err = liberr.Wrap(err, "vm", vmRef.String()) - return + var os string + for _, vmConf := range r.Migration.Status.VMs { + if vmConf.ID == vmRef.ID { + os = vmConf.OperationSystem + break + } } - var os string - if vm.GuestID != "" { - os = osMap[vm.GuestID] - } else if strings.Contains(vm.GuestName, "linux") || strings.Contains(vm.GuestName, "rhel") { + if os != "" { + os = osMap[os] + } else if strings.Contains(os, "linux") || strings.Contains(os, "rhel") { os = DefaultLinux - } else if strings.Contains(vm.GuestName, WindowsPrefix) { + } else if strings.Contains(os, WindowsPrefix) { os = DefaultWindows } else { os = Unknown