Skip to content

Commit

Permalink
ova: improve handling of extra devices
Browse files Browse the repository at this point in the history
When encountering an ova file, we iterate throught the devices listed in
the <VirtualHardwareSection> of the file and attempt to identify items
that are useful to us (notably Network Adapters, memory definition,
etc). The remaining items are stored as a list of generic devices with a
`Kind` that is a free-form string.

It appears that we tried to make the generic devices slightly nicer by
stripping off number suffixes from the names of the devices and setting
the device `Kind` to e.g. "SCSI Controller" rather than "SCSI Controller
1". But the code assumes that *all* `Items` in this file have the same
numeric suffix format for `ElementName`. In reality, the `Items` vary
quite a bit.

This variation occurs both between different `Items` in the same
file, and especially between ova files that are generated by different
sources. For example, in an ova file that was generated with vsphere
7.0, the `ElementName` for my video device is simply "Video Card" with
no suffix, whereas the Hard Disk has an `ElementName` of "Hard Disk 1".
So the ova provider transforms the video card into a generic device with
Kind set to the truncated string "Video Ca".

In addition, I encountered ova files that were produced by VirtualBox
where many of the `Items` in this list did not even contain
`ElementName` elements, but did have `Description`s.

So to make the ova provider more robust to files that don't follow our
current assumptions:
- only trim the suffix if the `ElementName` string ends with a space
  and a digit
- if the `ElementName` does not exist at all, use `Description`
- If neither of these elements exist, set the `Kind` to "Unknown"

Signed-off-by: Jonathon Jongsma <[email protected]>
  • Loading branch information
jonner committed Oct 16, 2024
1 parent 16ec9fc commit 33118b9
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions 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,11 +467,24 @@ 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 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: itemKind,
})
}

}
Expand Down

0 comments on commit 33118b9

Please sign in to comment.