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 Jul 23, 2024
1 parent b61a13c commit 405fc92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
42 changes: 22 additions & 20 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,34 +52,36 @@ 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) {
Expand All @@ -89,10 +90,11 @@ func GetFirmwareFromYaml(yamlData []byte) (firmware string, err error) {
return
}

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

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
4 changes: 1 addition & 3 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,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 405fc92

Please sign in to comment.