Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on unexpected ova files #1106

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion cmd/ova-provider-server/ova-provider-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"path/filepath"
"strconv"
"strings"
"unicode"

"github.com/konveyor/forklift-controller/pkg/lib/gob"

Expand Down Expand Up @@ -466,8 +467,23 @@ func convertToVmStruct(envelope []Envelope, ovaPath []string) ([]VM, error) {
newVM.MemoryUnits = item.AllocationUnits

} else {
var itemKind string
if len(item.ElementName) > 0 {
// if the `ElementName` element has a name such as "Hard Disk 1", strip off the
// number suffix to try to get a more generic name for the device type
itemKind = strings.TrimRightFunc(item.ElementName, func(r rune) bool {
return unicode.IsDigit(r) || unicode.IsSpace(r)
})
} else {
// Some .ova files do not include an `ElementName` element for each device. Fall
// back to using the `Description` element
itemKind = item.Description
}
if len(itemKind) == 0 {
itemKind = "Unknown"
}
newVM.Devices = append(newVM.Devices, Device{
Kind: item.ElementName[:len(item.ElementName)-2],
Kind: itemKind,
})
}

Expand Down
Loading