Skip to content

Commit

Permalink
core: look for InstanceID as well when reading internal ovfs
Browse files Browse the repository at this point in the history
Issue:
When attaching SD, VM Import tab doesn't show a VM if VM OVF has 'InstanceID' instead of 'InstanceId' property. The engine log shows the below error.
'Error parsing OVF due to OVF error: ol8-clone: cannot read 'rasd:InstanceId' with value: null'.
Ref bug change https://bugzilla.redhat.com/show_bug.cgi?id=1850103

Fix:
When reading/parsing VM OVF, check for both values 'InstanceID' and 'InstanceId'.

Signed-off-by: Shubha Kulkarni <shubha.kulkarni@oracle.com>
  • Loading branch information
shubhaOracle authored and ahadas committed Dec 2, 2022
1 parent 0b75478 commit 10ba646
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ private XmlNode getNode(XmlNodeList nodeList, String attributeName, String attri
return null;
}

protected String getInstanceIdValue(XmlNode node) {
XmlNode candidateNode = selectSingleNode(node, "rasd:InstanceId", _xmlNS);
// Some OVFs have InstanceID instead of InstanceId (e.g. generated by Oracle)
// So check for both values in the xml node
if (candidateNode == null) {
candidateNode = selectSingleNode(node, "rasd:InstanceID", _xmlNS);
}

return candidateNode.innerText;
}

protected void readSnapshotsSection(@SuppressWarnings("unused") XmlNode section) {
// The snapshot section only has meaning for VMs, and is overridden in OvfVmReader.
}
Expand Down Expand Up @@ -261,7 +272,7 @@ protected void readDisk(XmlNode node, DiskImage image) {
@Override
protected VmNetworkInterface getNetworkInterface(XmlNode node) {
// prior to 3.0 the instanceId is int , in 3.1 and on this is Guid
String str = selectSingleNode(node, VMD_ID, _xmlNS).innerText;
String str = getInstanceIdValue(node);
if (!StringUtils.isNumeric(str)) { // 3.1 and above OVF format
final Guid guid = new Guid(str);
VmNetworkInterface iface = interfaces.stream().filter(i -> i.getId().equals(guid)).findFirst().orElse(null);
Expand Down Expand Up @@ -329,7 +340,8 @@ protected void readOsSection(XmlNode section) {

@Override
protected void readDiskImageItem(XmlNode node) {
final Guid guid = new Guid(selectSingleNode(node, VMD_ID, _xmlNS).innerText);
String str = getInstanceIdValue(node);
final Guid guid = new Guid(str);
DiskImage image = _images.stream().filter(d -> d.getImageId().equals(guid)).findFirst().orElse(null);
if (image == null) {
return;
Expand Down

0 comments on commit 10ba646

Please sign in to comment.