Skip to content

Commit

Permalink
change mtv to use virt-v2v kubevirt changes
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <[email protected]>
  • Loading branch information
bkhizgiy committed Jul 28, 2024
1 parent b3f7b68 commit 6f517e5
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 130 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/plan/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ go_library(
"//pkg/controller/base",
"//pkg/controller/plan/adapter",
"//pkg/controller/plan/adapter/base",
"//pkg/controller/plan/adapter/ova",
"//pkg/controller/plan/context",
"//pkg/controller/plan/handler",
"//pkg/controller/plan/scheduler",
"//pkg/controller/plan/util",
"//pkg/controller/provider/web",
"//pkg/controller/provider/web/vsphere",
"//pkg/controller/validation",
Expand Down
3 changes: 0 additions & 3 deletions pkg/controller/plan/adapter/ova/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ go_library(
"builder.go",
"client.go",
"destinationclient.go",
"kubevirtvmparser.go",
"validator.go",
],
importpath = "github.com/konveyor/forklift-controller/pkg/controller/plan/adapter/ova",
Expand All @@ -27,9 +26,7 @@ go_library(
"//pkg/lib/error",
"//pkg/lib/inventory/web",
"//pkg/lib/itinerary",
"//pkg/lib/logging",
"//vendor/github.com/go-logr/logr",
"//vendor/gopkg.in/yaml.v2:yaml_v2",
"//vendor/k8s.io/api/core/v1:core",
"//vendor/k8s.io/apimachinery/pkg/api/resource",
"//vendor/k8s.io/utils/ptr",
Expand Down
43 changes: 0 additions & 43 deletions pkg/controller/plan/adapter/ova/kubevirtvmparser.go

This file was deleted.

4 changes: 4 additions & 0 deletions pkg/controller/plan/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "util",
srcs = [
"kubevirtvmparser.go",
"openstack.go",
"ovirt.go",
"utils.go",
Expand All @@ -13,7 +14,10 @@ go_library(
"//pkg/apis/forklift/v1beta1",
"//pkg/controller/provider/web/openstack",
"//pkg/controller/provider/web/ovirt",
"//pkg/lib/error",
"//pkg/lib/logging",
"//pkg/settings",
"//vendor/gopkg.in/yaml.v2:yaml_v2",
"//vendor/k8s.io/api/core/v1:core",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:meta",
],
Expand Down
133 changes: 133 additions & 0 deletions pkg/controller/plan/util/kubevirtvmparser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package util

import (
"fmt"
"strings"

liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
"github.com/konveyor/forklift-controller/pkg/lib/logging"
"gopkg.in/yaml.v2"
)

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 VirtualMachine struct {
ApiVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata Metadata `yaml:"metadata"`
Spec Spec `yaml:"spec"`
}

type Metadata struct {
Name string `yaml:"name"`
Labels map[string]string `yaml:"labels"`
}

type Spec struct {
Domain Domain `yaml:"domain"`
}

type Domain struct {
OS OS `yaml:"os"`
}

type OS struct {
Firmware string `yaml:"firmware"`
}

type Bios struct{}

type EFI struct {
SecureBoot bool `yaml:"secureBoot"`
}

func GetFirmwareFromYaml(yamlData []byte) (firmware string, err error) {
var vm VirtualMachine
if err = yaml.Unmarshal(yamlData, &vm); err != nil {
return
}

if vm.Spec.Domain.OS.Firmware != "" {
return
}
err = liberr.New("Firmware type was not detected")
return
}

func GetOperationSystemFromYaml(yamlData []byte) (os string, err error) {
var vm VirtualMachine
if err = yaml.Unmarshal(yamlData, &vm); err != nil {
return
}

labels := vm.Metadata.Labels
if osinfo, ok := labels["libguestfs.org/osinfo"]; ok {
return mapOs(osinfo), nil

}
return
}

func mapOs(labelOS string) (os string) {
distro := strings.SplitN(labelOS, ".", 2)[0]

switch {
case strings.HasPrefix(distro, "rocky"):
distro = "rocky"
case strings.HasPrefix(distro, "opensuse"):
distro = "opensuse"
case strings.HasPrefix(distro, "ubuntu"):
distro = "ubuntu"
case strings.HasPrefix(distro, "fedora"):
distro = "fedora"
}

os, ok := osV2VMap[os]
if !ok {
log.Info(fmt.Sprintf("Received %s, mapped to: %s", labelOS, os))
os = "otherGuest64"
}
return
}
Loading

0 comments on commit 6f517e5

Please sign in to comment.