Maor Lipchuk has uploaded a new change for review. Change subject: core: Support architecture type at OvfUtils ......................................................................
core: Support architecture type at OvfUtils Support set of architecture type when parsing the OVF from OVF Store disks. Change-Id: I77327c3487dc80533f6127258f05acae29914879 Signed-off-by: Maor Lipchuk <[email protected]> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OvfUtils.java 1 file changed, 45 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/48/29248/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OvfUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OvfUtils.java index cde52c2..4bf9475 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OvfUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OvfUtils.java @@ -9,17 +9,25 @@ import java.util.Map; import java.util.Map.Entry; +import org.ovirt.engine.core.common.businessentities.ArchitectureType; import org.ovirt.engine.core.common.businessentities.OvfEntityData; import org.ovirt.engine.core.common.businessentities.VmEntityType; +import org.ovirt.engine.core.common.osinfo.OsRepository; +import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.compat.backendcompat.XmlDocument; +import org.ovirt.engine.core.compat.backendcompat.XmlNode; +import org.ovirt.engine.core.compat.backendcompat.XmlNodeList; import org.ovirt.engine.core.utils.archivers.tar.TarInMemoryExport; +import org.ovirt.engine.core.utils.log.Log; +import org.ovirt.engine.core.utils.log.LogFactory; public class OvfUtils { private final static String TEMPLATE_ENTITY_TYPE = "<TemplateType>"; private final static String ENTITY_NAME = "<Name>"; private final static String END_ENTITY_NAME = "</Name>"; private final static String OVF_FILE_EXT = ".ovf"; - + protected final static Log log = LogFactory.getLog(TarInMemoryExport.class); private static String getEntityName(String ovfData) { int beginIndexOfEntityName = ovfData.indexOf(ENTITY_NAME) + ENTITY_NAME.length(); int endIndexOfEntityName = ovfData.indexOf(END_ENTITY_NAME, beginIndexOfEntityName); @@ -44,12 +52,14 @@ String ovfData, VmEntityType vmEntityType, String entityName, + ArchitectureType archType, Guid entityId) { OvfEntityData ovfEntityData = new OvfEntityData(); ovfEntityData.setOvfData(ovfData); ovfEntityData.setEntityType(vmEntityType); ovfEntityData.setEntityName(entityName); ovfEntityData.setStorageDomainId(storageDomainId); + ovfEntityData.setArchitecture(archType); ovfEntityData.setEntityId(entityId); return ovfEntityData; } @@ -69,13 +79,22 @@ for (Entry<String, ByteBuffer> fileEntry : filesFromTar.entrySet()) { if (fileEntry.getKey().endsWith(OVF_FILE_EXT)) { String ovfData = new String(fileEntry.getValue().array()); - + VmEntityType vmType = getVmEntityType(ovfData); + ArchitectureType archType = null; + try { + XmlDocument xmlDocument = new XmlDocument(ovfData); + archType = getOsSection(xmlDocument); + } catch (Exception e) { + log.errorFormat("Could not parse architecture type for VM. Exception : {0}", e); + continue; + } // Creates an OVF entity data. OvfEntityData ovfEntityData = createOvfEntityData(storageDomainId, ovfData, - getVmEntityType(ovfData), + vmType, getEntityName(ovfData), + archType, getEntityId(fileEntry.getKey())); ovfEntityDataFromTar.add(ovfEntityData); } @@ -83,4 +102,27 @@ return ovfEntityDataFromTar; } + + private static ArchitectureType getOsSection(XmlDocument xmlDocument) { + ArchitectureType archType = null; + XmlNode content = xmlDocument.SelectSingleNode("//*/Content"); + XmlNodeList nodeList = content.SelectNodes("Section"); + XmlNode selectedSection = null; + OsRepository osRepository = SimpleDependecyInjector.getInstance().get(OsRepository.class); + if (nodeList != null) { + for (XmlNode section : nodeList) { + String value = section.attributes.get("xsi:type").getValue(); + + if (value.equals("ovf:OperatingSystemSection_Type")) { + selectedSection = section; + break; + } + } + if (selectedSection != null) { + int osId = osRepository.getOsIdByUniqueName(selectedSection.innerText); + archType = osRepository.getArchitectureFromOS(osId); + } + } + return archType; + } } -- To view, visit http://gerrit.ovirt.org/29248 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I77327c3487dc80533f6127258f05acae29914879 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Maor Lipchuk <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
