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 <[email protected]>
  • Loading branch information
bkhizgiy committed Jul 23, 2024
1 parent b61a13c commit 87e02e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
39 changes: 21 additions & 18 deletions pkg/controller/plan/util/kubevirtvmparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,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,7 +91,8 @@ func GetFirmwareFromYaml(yamlData []byte) (firmware string, err error) {
return
}

if vm.Spec.Domain.OS.Firmware != "" {
if vm.Spec.Template.Spec.Domain.OS.Firmware != "" {
firmware = vm.Spec.Template.Spec.Domain.OS.Firmware
return
}
err = liberr.New("Firmware type was not detected")
Expand Down Expand Up @@ -124,7 +127,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 87e02e6

Please sign in to comment.