Skip to content

Commit

Permalink
Build the VM with OS from the VM's status
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
liranr23 authored and ahadas committed Jun 18, 2024
1 parent 22b53b1 commit d107ae1
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions pkg/controller/plan/adapter/vsphere/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,32 +720,34 @@ 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.OperatingSystem
break
}
}
name, ok := configMap.Data[vm.GuestID]
name, ok := configMap.Data[os]
if !ok {
err = liberr.Wrap(err, "vm", vmRef.String())
}
return
}

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.OperatingSystem
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
Expand Down

0 comments on commit d107ae1

Please sign in to comment.