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 committed Jun 16, 2024
1 parent 95e059b commit 8a5d988
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 @@ -756,32 +756,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.OperationSystem
break

Check warning on line 763 in pkg/controller/plan/adapter/vsphere/builder.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/adapter/vsphere/builder.go#L759-L763

Added lines #L759 - L763 were not covered by tests
}
}
name, ok := configMap.Data[vm.GuestID]
name, ok := configMap.Data[os]

Check warning on line 766 in pkg/controller/plan/adapter/vsphere/builder.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/adapter/vsphere/builder.go#L766

Added line #L766 was not covered by tests
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.OperationSystem
break

Check warning on line 778 in pkg/controller/plan/adapter/vsphere/builder.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/adapter/vsphere/builder.go#L774-L778

Added lines #L774 - L778 were not covered by tests
}
}

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") {

Check warning on line 784 in pkg/controller/plan/adapter/vsphere/builder.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/adapter/vsphere/builder.go#L782-L784

Added lines #L782 - L784 were not covered by tests
os = DefaultLinux
} else if strings.Contains(vm.GuestName, WindowsPrefix) {
} else if strings.Contains(os, WindowsPrefix) {

Check warning on line 786 in pkg/controller/plan/adapter/vsphere/builder.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/adapter/vsphere/builder.go#L786

Added line #L786 was not covered by tests
os = DefaultWindows
} else {
os = Unknown
Expand Down

0 comments on commit 8a5d988

Please sign in to comment.