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` within 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 14, 2024
1 parent 770bff3 commit 5a9e04d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 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,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,
})
}

}
Expand Down

0 comments on commit 5a9e04d

Please sign in to comment.