diff --git a/cmd/ova-provider-server/ova-provider-server.go b/cmd/ova-provider-server/ova-provider-server.go index 3118b9e13..318db9248 100644 --- a/cmd/ova-provider-server/ova-provider-server.go +++ b/cmd/ova-provider-server/ova-provider-server.go @@ -15,6 +15,7 @@ import ( "path/filepath" "strconv" "strings" + "unicode" "github.com/konveyor/forklift-controller/pkg/lib/gob" @@ -466,11 +467,28 @@ func convertToVmStruct(envelope []Envelope, ovaPath []string) ([]VM, error) { newVM.MemoryUnits = item.AllocationUnits } else { - if len(item.ElementName) > 2 { - newVM.Devices = append(newVM.Devices, Device{ - Kind: item.ElementName[:len(item.ElementName)-2], - }) + var itemKind string + if len(item.ElementName) == 0 { + if len(item.Description) > 0 { + itemKind = item.Description + } else { + itemKind = "Unknown" + } + } else { + // if the `ElementName` element has a name such as "Hard Disk 1", strip off the + // number suffix + runes := []rune(item.ElementName) + if len(runes) > 2 && + unicode.IsSpace(runes[len(runes)-2]) && + unicode.IsDigit(runes[len(runes)-1]) { + itemKind = item.ElementName[:len(item.ElementName)-2] + } else { + itemKind = item.ElementName + } } + newVM.Devices = append(newVM.Devices, Device{ + Kind: itemKind, + }) } }