Search in sources :

Example 6 with XmlNodeList

use of org.ovirt.engine.core.utils.ovf.xml.XmlNodeList 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 7 with XmlNodeList

use of org.ovirt.engine.core.utils.ovf.xml.XmlNodeList 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)

Example 8 with XmlNodeList

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

the class OvfUtils method getOsSection.

private ArchitectureType getOsSection(XmlDocument xmlDocument) {
    ArchitectureType archType = null;
    XmlNode content = xmlDocument.selectSingleNode("//*/Content");
    XmlNodeList nodeList = content.selectNodes("Section");
    XmlNode selectedSection = null;
    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;
}
Also used : ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList)

Example 9 with XmlNodeList

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

the class OvfOvaReader method buildDisk.

@Override
public void buildDisk() {
    XmlNode diskSection = selectSingleNode(_document, "//*/DiskSection");
    XmlNodeList list = diskSection.selectNodes("Disk");
    for (XmlNode node : list) {
        readDisk(node, null);
    }
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList)

Example 10 with XmlNodeList

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

the class OvfOvirtReader method readUserDomainsSection.

protected void readUserDomainsSection(@SuppressWarnings("unused") XmlNode section) {
    XmlNodeList list = selectNodes(section, OvfProperties.USER);
    Set<DbUser> dbUsers = new HashSet<>();
    Map<String, Set<String>> userToRoles = new HashMap<>();
    for (XmlNode node : list) {
        String userDomain = selectSingleNode(node, OvfProperties.USER_DOMAIN, _xmlNS).innerText;
        DbUser dbUser = new DbUser();
        dbUser.setLoginName(userDomain.split("@")[0]);
        dbUser.setDomain(userDomain.split("@")[1]);
        dbUsers.add(dbUser);
        XmlNode rolesElement = selectSingleNode(node, OvfProperties.USER_ROLES);
        XmlNodeList roleNodes = selectNodes(rolesElement, OvfProperties.ROLE_NAME);
        Set<String> roleNames = new HashSet<>();
        for (XmlNode roleNode : roleNodes) {
            String roleName = roleNode.innerText;
            roleNames.add(roleName);
        }
        userToRoles.put(dbUser.getLoginName(), roleNames);
    }
    fullEntityOvfData.setDbUsers(dbUsers);
    fullEntityOvfData.setUserToRoles(userToRoles);
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) HashSet(java.util.HashSet)

Aggregations

XmlNode (org.ovirt.engine.core.utils.ovf.xml.XmlNode)13 XmlNodeList (org.ovirt.engine.core.utils.ovf.xml.XmlNodeList)13 Guid (org.ovirt.engine.core.compat.Guid)5 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 ArchitectureType (org.ovirt.engine.core.common.businessentities.ArchitectureType)1 Label (org.ovirt.engine.core.common.businessentities.Label)1 LabelBuilder (org.ovirt.engine.core.common.businessentities.LabelBuilder)1 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)1 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)1 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)1 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)1 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)1 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)1 AffinityGroup (org.ovirt.engine.core.common.scheduling.AffinityGroup)1