Roy Golan has uploaded a new change for review. Change subject: core: libosinfo - export/import new OS types and CpuArch ......................................................................
core: libosinfo - export/import new OS types and CpuArch Add CPU architecture section to the XSI elements for the OVF both for export and import flows. Backward compatibility: since "Operating System" (VmOsType) enum ids has changed, the OVF reader translates old ids to new ons. Change-Id: I7178e0fe9889b59f5cf576d200abe28d52d77470 Signed-off-by: Roy Golan <rgo...@redhat.com> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmWriter.java 4 files changed, 63 insertions(+), 29 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/56/9256/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java index d86bbe2..d2df831 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java @@ -8,6 +8,7 @@ import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.common.businessentities.BootSequence; +import org.ovirt.engine.core.common.businessentities.CpuArch; import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.DiskInterface; import org.ovirt.engine.core.common.businessentities.ImageStatus; @@ -17,6 +18,7 @@ import org.ovirt.engine.core.common.businessentities.VmDeviceId; import org.ovirt.engine.core.common.businessentities.VmInterfaceType; import org.ovirt.engine.core.common.businessentities.VmNetworkInterface; +import org.ovirt.engine.core.common.businessentities.VmOsType; import org.ovirt.engine.core.common.businessentities.VmType; import org.ovirt.engine.core.common.businessentities.VolumeFormat; import org.ovirt.engine.core.common.businessentities.VolumeType; @@ -271,8 +273,6 @@ return iface; } - protected abstract void ReadOsSection(XmlNode section); - protected abstract void ReadHardwareSection(XmlNode section); protected void readGeneralData() { @@ -349,9 +349,9 @@ if (StringHelper.EqOp(value, "ovf:OperatingSystemSection_Type")) { ReadOsSection(section); - - } - else if (StringHelper.EqOp(value, "ovf:VirtualHardwareSection_Type")) { + } else if (StringHelper.EqOp(value, "ovf:CpuArchitectureSection_Type")) { + ReadCpuArchSection(section); + } else if (StringHelper.EqOp(value, "ovf:VirtualHardwareSection_Type")) { ReadHardwareSection(section); } else if (StringUtils.equals(value, "ovf:SnapshotsSection_Type")) { readSnapshotsSection(section); @@ -491,6 +491,51 @@ } } + protected void ReadOsSection(XmlNode section) { + vmBase.setId(new Guid(section.Attributes.get("ovf:id").getValue())); + XmlNode node = section.SelectSingleNode("Description"); + VmOsType os = VmOsType.Unassigned; + parse: if (node != null) { + String text = node.InnerText; + VmOsType valueOf = VmOsType.valueOf(text); + if (valueOf != null) { + os = valueOf; + break parse; + } + // found old values, upgrade it to the new representation. + if (text.equalsIgnoreCase("windowsxp")) { + os = VmOsType.winxp; + } else if (text.startsWith("Windows2003")) { + os = VmOsType.win2k3; + } else if (text.startsWith("Windows2008")) { + os = VmOsType.win2k8; + } else if (text.startsWith("Windows7")) { + os = VmOsType.win7; + } else if (text.startsWith("RHEL3")) { + os = VmOsType.rhel__3; + } else if (text.startsWith("RHEL4")) { + os = VmOsType.rhel__4_8; // 4.8 is the current earliest version 4 mapped in Libosinfo + } else if (text.startsWith("RHEL5")) { + os = VmOsType.rhel__5_4; // 5.4 is the current earliest version 5 mapped in Libosinfo + } else if (text.startsWith("RHEL6")) { + os = VmOsType.rhel__6_0; // 5.4 is the current earliest version 5 mapped in Libosinfo + } + } else { + vmBase.setos(VmOsType.Unassigned); + } + vmBase.setos(os); + } + + protected void ReadCpuArchSection(XmlNode section) { + vmBase.setId(new Guid(section.Attributes.get("ovf:id").getValue())); + XmlNode node = section.SelectSingleNode("Description"); + if (node != null) { + vmBase.setCpuArch(CpuArch.valueOf(node.InnerText)); + } else { + vmBase.setCpuArch(CpuArch.UNASSIGNED); + } + } + private static Map<String,Object> getMapNode(XmlNode node) { Map<String,Object> returnValue = new HashMap<String,Object>(); diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java index 07ac175..520aaec 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java @@ -9,7 +9,6 @@ import org.ovirt.engine.core.common.businessentities.UsbPolicy; import org.ovirt.engine.core.common.businessentities.VmInterfaceType; import org.ovirt.engine.core.common.businessentities.VmNetworkInterface; -import org.ovirt.engine.core.common.businessentities.VmOsType; import org.ovirt.engine.core.common.businessentities.VmTemplate; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.StringHelper; @@ -28,17 +27,6 @@ ArrayList<VmNetworkInterface> interfaces) { super(document, images, interfaces, vmTemplate); _vmTemplate = vmTemplate; - } - - @Override - protected void ReadOsSection(XmlNode section) { - _vmTemplate.setId(new Guid(section.Attributes.get("ovf:id").getValue())); - XmlNode node = section.SelectSingleNode("Description"); - if (node != null) { - _vmTemplate.setos(VmOsType.valueOf(node.InnerText)); - } else { - _vmTemplate.setos(VmOsType.Unassigned); - } } @Override diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java index ca1a5ef..156af03 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java @@ -14,7 +14,6 @@ import org.ovirt.engine.core.common.businessentities.UsbPolicy; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VmNetworkInterface; -import org.ovirt.engine.core.common.businessentities.VmOsType; import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils; import org.ovirt.engine.core.compat.Guid; @@ -36,17 +35,6 @@ super(document, images, interfaces, vm.getStaticData()); _vm = vm; _vm.setInterfaces(interfaces); - } - - @Override - protected void ReadOsSection(XmlNode section) { - _vm.getStaticData().setId(new Guid(section.Attributes.get("ovf:id").getValue())); - XmlNode node = section.SelectSingleNode("Description"); - if (node != null) { - _vm.getStaticData().setos(VmOsType.valueOf(node.InnerText)); - } else { - _vm.getStaticData().setos(VmOsType.Unassigned); - } } @Override diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmWriter.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmWriter.java index 1bd3e6d..6dd1df2 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmWriter.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmWriter.java @@ -133,6 +133,19 @@ _writer.WriteEndElement(); _writer.WriteEndElement(); + // CPU architecture + _writer.WriteStartElement("Section"); + _writer.WriteAttributeString(OVF_URI, "id", vmBase.getId().toString()); + _writer.WriteAttributeString(OVF_URI, "required", "false"); + _writer.WriteAttributeString(XSI_URI, "type", "ovf:CpuArchitectureSection_Type"); + _writer.WriteStartElement("Info"); + _writer.WriteRaw("Guest CPU Architecture"); + _writer.WriteEndElement(); + _writer.WriteStartElement("Description"); + _writer.WriteRaw(vmBase.getCpuArch().name()); + _writer.WriteEndElement(); + _writer.WriteEndElement(); + // hardware _writer.WriteStartElement("Section"); _writer.WriteAttributeString(XSI_URI, "type", "ovf:VirtualHardwareSection_Type"); -- To view, visit http://gerrit.ovirt.org/9256 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7178e0fe9889b59f5cf576d200abe28d52d77470 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Roy Golan <rgo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches