Search in sources :

Example 21 with XmlNode

use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.

the class OvfVmReader method readAffinityLabelsSection.

@Override
protected void readAffinityLabelsSection(XmlNode section) {
    XmlNodeList list = selectNodes(section, OvfProperties.AFFINITY_LABEL);
    List<Label> affinityLabels = new ArrayList<>();
    for (XmlNode node : list) {
        String affinityLabelName = node.attributes.get("ovf:name").innerText;
        LabelBuilder builder = new LabelBuilder();
        Label label = builder.name(affinityLabelName).build();
        affinityLabels.add(label);
    }
    fullEntityOvfData.setAffinityLabels(affinityLabels);
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) Label(org.ovirt.engine.core.common.businessentities.Label) ArrayList(java.util.ArrayList) LabelBuilder(org.ovirt.engine.core.common.businessentities.LabelBuilder) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList)

Example 22 with XmlNode

use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.

the class OvfVmReader method readAffinityGroupsSection.

@Override
protected void readAffinityGroupsSection(XmlNode section) {
    XmlNodeList list = selectNodes(section, OvfProperties.AFFINITY_GROUP);
    List<AffinityGroup> affinityGroups = new ArrayList<>();
    for (XmlNode node : list) {
        String affinityGroupName = node.attributes.get("ovf:name").innerText;
        AffinityGroup affinityGroup = new AffinityGroup();
        affinityGroup.setName(affinityGroupName);
        affinityGroups.add(affinityGroup);
    }
    fullEntityOvfData.setAffinityGroups(affinityGroups);
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) ArrayList(java.util.ArrayList) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList)

Example 23 with XmlNode

use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.

the class OvfVmReader method readSnapshotsSection.

@Override
protected void readSnapshotsSection(XmlNode section) {
    XmlNodeList list = selectNodes(section, "Snapshot");
    List<Snapshot> snapshots = new ArrayList<>();
    _vm.setSnapshots(snapshots);
    for (XmlNode node : list) {
        XmlNode vmConfiguration = selectSingleNode(node, "VmConfiguration", _xmlNS);
        Snapshot snapshot = new Snapshot(vmConfiguration != null);
        snapshot.setId(new Guid(node.attributes.get("ovf:id").getValue()));
        snapshot.setVmId(_vm.getId());
        snapshot.setType(SnapshotType.valueOf(selectSingleNode(node, "Type", _xmlNS).innerText));
        snapshot.setStatus(SnapshotStatus.OK);
        snapshot.setDescription(selectSingleNode(node, "Description", _xmlNS).innerText);
        XmlNode memory = selectSingleNode(node, "Memory", _xmlNS);
        if (memory != null) {
            List<Guid> guids = Guid.createGuidListFromString(memory.innerText);
            snapshot.setMemoryDiskId(guids.get(2));
            snapshot.setMetadataDiskId(guids.get(4));
        }
        final Date creationDate = OvfParser.utcDateStringToLocalDate(selectSingleNode(node, "CreationDate", _xmlNS).innerText);
        if (creationDate != null) {
            snapshot.setCreationDate(creationDate);
        }
        snapshot.setVmConfiguration(vmConfiguration == null ? null : new String(Base64.decodeBase64(vmConfiguration.innerText)));
        XmlNode appList = selectSingleNode(node, "ApplicationList", _xmlNS);
        if (appList != null) {
            snapshot.setAppList(appList.innerText);
        }
        snapshots.add(snapshot);
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Date(java.util.Date) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList)

Example 24 with XmlNode

use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.

the class OvfUtils method fetchVmDisks.

public Set<Guid> fetchVmDisks(XmlDocument xmlDocument) {
    Set<Guid> disksIds = new HashSet<>();
    XmlNode references = xmlDocument.selectSingleNode("//*/References");
    // we assume that all files in OVFs that are generated by oVirt are disks
    for (XmlNode file : references.selectNodes("File")) {
        disksIds.add(Guid.createGuidFromString(file.attributes.get("ovf:href").getValue().substring(0, GUID_LENGTH)));
    }
    disksIds.addAll(fetchMemoryDisks(xmlDocument));
    return disksIds;
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) Guid(org.ovirt.engine.core.compat.Guid) HashSet(java.util.HashSet)

Example 25 with XmlNode

use of org.ovirt.engine.core.utils.ovf.xml.XmlNode in project ovirt-engine by oVirt.

the class OvfUtils method fetchMemoryDisks.

public Set<Guid> fetchMemoryDisks(XmlDocument xmlDocument) {
    Set<Guid> memoryDiskIds = new HashSet<>();
    xmlDocument.selectNodes("ovf:SnapshotsSection_Type");
    XmlNode content = xmlDocument.selectSingleNode("//*/Content");
    XmlNodeList nodeList = content.selectNodes("Section");
    if (nodeList != null) {
        for (XmlNode section : nodeList) {
            String value = section.attributes.get("xsi:type").getValue();
            if (value.equals("ovf:SnapshotsSection_Type")) {
                Iterator<XmlNode> snapshotIter = section.selectNodes("Snapshot").iterator();
                while (snapshotIter.hasNext()) {
                    XmlNode memorySnapshot = snapshotIter.next().selectSingleNode("Memory");
                    if (memorySnapshot != null) {
                        List<Guid> guids = Guid.createGuidListFromString(memorySnapshot.innerText);
                        memoryDiskIds.add(guids.get(2));
                        memoryDiskIds.add(guids.get(4));
                    }
                }
            }
        }
    }
    return memoryDiskIds;
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) Guid(org.ovirt.engine.core.compat.Guid) HashSet(java.util.HashSet) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList)

Aggregations

XmlNode (org.ovirt.engine.core.utils.ovf.xml.XmlNode)50 XmlNodeList (org.ovirt.engine.core.utils.ovf.xml.XmlNodeList)23 Guid (org.ovirt.engine.core.compat.Guid)19 HashMap (java.util.HashMap)16 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)14 ArrayList (java.util.ArrayList)13 XmlAttribute (org.ovirt.engine.core.utils.ovf.xml.XmlAttribute)12 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)10 XmlDocument (org.ovirt.engine.core.utils.ovf.xml.XmlDocument)10 Map (java.util.Map)9 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)9 DiskLunMap (org.ovirt.engine.core.common.businessentities.storage.DiskLunMap)9 MemoizingSupplier (org.ovirt.engine.core.utils.MemoizingSupplier)9 XmlNamespaceManager (org.ovirt.engine.core.utils.ovf.xml.XmlNamespaceManager)9 Arrays (java.util.Arrays)8 Collections (java.util.Collections)8 Comparator (java.util.Comparator)8 List (java.util.List)8 Objects (java.util.Objects)8 Optional (java.util.Optional)8