Skip to content

Commit

Permalink
minor changes virt-v2v ymal parser
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <bkhizgiy@redhat.com>
  • Loading branch information
bkhizgiy committed Aug 20, 2024
1 parent 1b4de05 commit 19fff66
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
1 change: 0 additions & 1 deletion pkg/controller/plan/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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",
Expand Down
52 changes: 27 additions & 25 deletions pkg/controller/plan/util/kubevirtvmparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"strings"

liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
"github.com/konveyor/forklift-controller/pkg/lib/logging"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -53,47 +52,50 @@ var osV2VMap = map[string]string{
"win2k22": "windows2022srvNext_64Guest",
}

type VirtualMachine struct {
ApiVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata Metadata `yaml:"metadata"`
Spec Spec `yaml:"spec"`
type OS struct {
Firmware string `yaml:"firmware"`
}

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

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

type Domain struct {
OS OS `yaml:"os"`
type Template struct {
Spec TemplateSpec `yaml:"spec"`
}

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

type Bios struct{}
type VirtualMachine struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata Metadata `yaml:"metadata"`
Spec VirtualMachineSpec `yaml:"spec"`
}

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

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

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

return firmware, nil
}

func GetOperationSystemFromYaml(yamlData []byte) (os string, err error) {
Expand Down Expand Up @@ -124,7 +126,7 @@ func mapOs(labelOS string) (os string) {
distro = "fedora"
}

os, ok := osV2VMap[os]
os, ok := osV2VMap[distro]
if !ok {
log.Info(fmt.Sprintf("Received %s, mapped to: %s", labelOS, os))
os = "otherGuest64"
Expand Down
7 changes: 3 additions & 4 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var (
const LETTERS = "abcdefghijklmnopqrstuvwxyz"
const LETTERS_LENGTH = len(LETTERS)

var firmware = "bios"
var nameChanged bool

func main() {
Expand Down Expand Up @@ -119,6 +118,8 @@ func buildCommand() []string {
}
virtV2vArgs = append(virtV2vArgs, "-o", "kubevirt")

// When converting VM with name that do not meet DNS1123 RFC requirements,
// it should be changed to supported one to ensure the conversion does not fail.
if checkEnvVariablesSet("V2V_NewName") {
virtV2vArgs = append(virtV2vArgs, "-on", os.Getenv("V2V_NewName"))
nameChanged = true
Expand Down Expand Up @@ -307,9 +308,7 @@ func vmHandler(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "text/yaml")
_, err = w.Write(yamlData)
if err == nil {
w.WriteHeader(http.StatusOK)
} else {
if err != nil {
fmt.Printf("Error writing response: %v\n", err)
http.Error(w, "Error writing response", http.StatusInternalServerError)
}
Expand Down

0 comments on commit 19fff66

Please sign in to comment.