Skip to content

Commit

Permalink
Add the OS output to the VM
Browse files Browse the repository at this point in the history
This patch will take the parsed OS from the virt-v2v XML output and
convert it to the VMWare OS. This information will be set within the VM
status.

Signed-off-by: Liran Rotenberg <[email protected]>
  • Loading branch information
liranr23 authored and ahadas committed Jun 18, 2024
1 parent a9c7f7a commit 22b53b1
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ spec:
The VM Namespace
Only relevant for an openshift source.
type: string
operatingSystem:
description: The Operating System detected by virt-v2v.
type: string
phase:
description: Phase
type: string
Expand Down
3 changes: 3 additions & 0 deletions operator/config/crd/bases/forklift.konveyor.io_plans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,9 @@ spec:
The VM Namespace
Only relevant for an openshift source.
type: string
operatingSystem:
description: The Operating System detected by virt-v2v.
type: string
phase:
description: Phase
type: string
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/forklift/v1beta1/plan/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ type VMStatus struct {
RestorePowerState VMPowerState `json:"restorePowerState,omitempty"`
// The firmware type detected from the OVF file produced by virt-v2v.
Firmware string `json:"firmware,omitempty"`
// The Operating System detected by virt-v2v.
OperatingSystem string `json:"operatingSystem,omitempty"`

// Conditions.
libcnd.Conditions `json:",inline"`
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/plan/adapter/ova/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ go_library(
"//pkg/lib/error",
"//pkg/lib/inventory/web",
"//pkg/lib/itinerary",
"//pkg/lib/logging",
"//vendor/github.com/go-logr/logr",
"//vendor/k8s.io/api/core/v1:core",
"//vendor/k8s.io/apimachinery/pkg/api/resource",
Expand Down
66 changes: 65 additions & 1 deletion pkg/controller/plan/adapter/ova/ovfparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,56 @@ package ova

import (
"encoding/xml"
"fmt"
"strings"

"github.com/konveyor/forklift-controller/pkg/lib/logging"
)

const (
// Name.
Name = "virt-v2v-parser"
)

// Package logger.
var log = logging.WithName(Name)

// Map of osinfo ids to vmware guest ids.
var osV2VMap = map[string]string{
"centos6": "centos6_64Guest",
"centos7": "centos7_64Guest",
"centos8": "centos8_64Guest",
"centos9": "centos9_64Guest",
"rhel7": "rhel7_64Guest",
"rhel8": "rhel8_64Guest",
"rhel9": "rhel9_64Guest",
"rocky": "rockylinux_64Guest",
"sles10": "sles10_64Guest",
"sles11": "sles11_64Guest",
"sles12": "sles12_64Guest",
"sles15": "sles15_64Guest",
"sles16": "sles16_64Guest",
"opensuse": "opensuse64Guest",
"debian4": "debian4_64Guest",
"debian5": "debian5_64Guest",
"debian6": "debian6_64Guest",
"debian7": "debian7_64Guest",
"debian8": "debian8_64Guest",
"debian9": "debian9_64Guest",
"debian10": "debian10_64Guest",
"debian11": "debian11_64Guest",
"debian12": "debian12_64Guest",
"ubuntu": "ubuntu64Guest",
"fedora": "fedora64Guest",
"win7": "windows7Server64Guest",
"win8": "windows8Server64Guest",
"win10": "windows9Server64Guest",
"win11": "windows11_64Guest",
"win12": "windows12_64Guest",
"win2k19": "windows2019srv_64Guest",
"win2k22": "windows2022srvNext_64Guest",
}

type OvaVmconfig struct {
XMLName xml.Name `xml:"domain"`
Name string `xml:"name"`
Expand Down Expand Up @@ -78,5 +125,22 @@ func GetOperationSystemFromConfig(vmConfigXML string) (os string, err error) {
if err != nil {
return
}
return xmlConf.Metadata.LibOsInfo.V2VOS.ID, nil
return mapOs(xmlConf.Metadata.LibOsInfo.V2VOS.ID), nil
}

func mapOs(xmlOs string) (os string) {
split := strings.Split(xmlOs, "/")
distro := split[3]
switch distro {
case "rocky", "opensuse", "ubuntu", "fedora":
os = distro
default:
os = split[3] + strings.Split(split[4], ".")[0]
}
os, ok := osV2VMap[os]
if !ok {
log.Info(fmt.Sprintf("Received %s, mapped to: %s", xmlOs, os))
os = "otherGuest64"
}
return
}
88 changes: 46 additions & 42 deletions pkg/controller/plan/adapter/vsphere/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,48 +79,52 @@ const (

// Map of vmware guest ids to osinfo ids.
var osMap = map[string]string{
"centos64Guest": "centos5.11",
"centos6_64Guest": "centos6.10",
"centos6Guest": "centos6.10",
"centos7_64Guest": "centos7.0",
"centos7Guest": "centos7.0",
"centos8_64Guest": "centos8",
"centos8Guest": "centos8",
"debian4_64Guest": "debian4",
"debian4Guest": "debian4",
"debian5_64Guest": "debian5",
"debian5Guest": "debian5",
"debian6_64Guest": "debian6",
"debian6Guest": "debian6",
"debian7_64Guest": "debian7",
"debian7Guest": "debian7",
"debian8_64Guest": "debian8",
"debian8Guest": "debian8",
"debian9_64Guest": "debian9",
"debian9Guest": "debian9",
"debian10_64Guest": "debian10",
"debian10Guest": "debian10",
"fedora64Guest": "fedora31",
"fedoraGuest": "fedora31",
"genericLinuxGuest": "linux",
"rhel6_64Guest": "rhel6.10",
"rhel6Guest": "rhel6.10",
"rhel7_64Guest": "rhel7.7",
"rhel7Guest": "rhel7.7",
"rhel8_64Guest": "rhel8.1",
"ubuntu64Guest": "ubuntu18.04",
"ubuntuGuest": "ubuntu18.04",
"win2000AdvServGuest": "win2k",
"win2000ProGuest": "win2k",
"win2000ServGuest": "win2k",
"windows7Guest": "win7",
"windows7Server64Guest": "win2k8r2",
"windows8_64Guest": "win8",
"windows8Guest": "win8",
"windows8Server64Guest": "win2k12r2",
"windows9_64Guest": "win10",
"windows9Guest": "win10",
"windows9Server64Guest": "win2k19",
"centos64Guest": "centos5.11",
"centos6_64Guest": "centos6.10",
"centos6Guest": "centos6.10",
"centos7_64Guest": "centos7.0",
"centos7Guest": "centos7.0",
"centos8_64Guest": "centos8",
"centos8Guest": "centos8",
"debian4_64Guest": "debian4",
"debian4Guest": "debian4",
"debian5_64Guest": "debian5",
"debian5Guest": "debian5",
"debian6_64Guest": "debian6",
"debian6Guest": "debian6",
"debian7_64Guest": "debian7",
"debian7Guest": "debian7",
"debian8_64Guest": "debian8",
"debian8Guest": "debian8",
"debian9_64Guest": "debian9",
"debian9Guest": "debian9",
"debian10_64Guest": "debian10",
"debian10Guest": "debian10",
"fedora64Guest": "fedora31",
"fedoraGuest": "fedora31",
"genericLinuxGuest": "linux",
"rhel6_64Guest": "rhel6.10",
"rhel6Guest": "rhel6.10",
"rhel7_64Guest": "rhel7.7",
"rhel7Guest": "rhel7.7",
"rhel8_64Guest": "rhel8.1",
"rhel9_64Guest": "rhel9.4",
"ubuntu64Guest": "ubuntu18.04",
"ubuntuGuest": "ubuntu18.04",
"win2000AdvServGuest": "win2k",
"win2000ProGuest": "win2k",
"win2000ServGuest": "win2k",
"windows7Guest": "win7",
"windows7Server64Guest": "win2k8r2",
"windows8_64Guest": "win8",
"windows8Guest": "win8",
"windows8Server64Guest": "win2k12r2",
"windows9_64Guest": "win10",
"windows9Guest": "win10",
"windows9Server64Guest": "win2k19",
"windows2019srv_64Guest": "win2k19",
"windows2019srvNext_64Guest": "win2k19",
"windows2022srvNext_64Guest": "win2k22",
}

// Regex which matches the snapshot identifier suffix of a
Expand Down
21 changes: 16 additions & 5 deletions pkg/controller/plan/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,12 +929,23 @@ func (r *KubeVirt) UpdateVmByConvertedConfig(vm *plan.VMStatus, pod *core.Pod, s
return
}

firmware, err := ovfparser.GetFirmwareFromConfig(string(vmConfigXML))
if err != nil {
return
}
switch r.Source.Provider.Type() {
case api.Ova:
firmware, erro := ovfparser.GetFirmwareFromConfig(string(vmConfigXML))
if erro != nil {
err = erro
return
}

vm.Firmware = firmware
vm.Firmware = firmware
case api.VSphere:
os, erro := ovfparser.GetOperationSystemFromConfig(string(vmConfigXML))
if erro != nil {
err = erro
return
}
vm.OperatingSystem = os
}

shutdownURL := fmt.Sprintf("http://%s:8080/shutdown", pod.Status.PodIP)
resp, err = http.Post(shutdownURL, "application/json", nil)
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/plan/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 +1125,9 @@ func (r *Migration) execute(vm *plan.VMStatus) (err error) {
return
}

// only for OVA, fetch config from the conversion pod
if r.Source.Provider.Type() == v1beta1.Ova {
switch r.Source.Provider.Type() {
case v1beta1.Ova, v1beta1.VSphere:
// fetch config from the conversion pod
pod, err := r.kubevirt.GetGuestConversionPod(vm)
if err != nil {
return err
Expand Down

0 comments on commit 22b53b1

Please sign in to comment.