Search in sources :

Example 36 with XmlNode

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

the class OvfReader method readVmInit.

private void readVmInit(XmlNode content) {
    XmlNode node = selectSingleNode(content, "VmInit");
    VmInit vmInit = vmBase.getVmInit();
    vmInit.setId(vmBase.getId());
    if (node != null) {
        if (node.attributes.get("ovf:hostname") != null) {
            vmInit.setHostname(node.attributes.get("ovf:hostname").getValue());
        }
        if (node.attributes.get("ovf:domain") != null) {
            vmInit.setDomain(node.attributes.get("ovf:domain").getValue());
        }
        if (node.attributes.get("ovf:timeZone") != null) {
            vmInit.setTimeZone(node.attributes.get("ovf:timeZone").getValue());
        }
        if (node.attributes.get("ovf:authorizedKeys") != null) {
            vmInit.setAuthorizedKeys(node.attributes.get("ovf:authorizedKeys").getValue());
        }
        if (node.attributes.get("ovf:regenerateKeys") != null) {
            vmInit.setRegenerateKeys(Boolean.parseBoolean(node.attributes.get("ovf:regenerateKeys").getValue()));
        }
        if (node.attributes.get("ovf:dnsServers") != null) {
            vmInit.setDnsServers(node.attributes.get("ovf:dnsServers").getValue());
        }
        if (node.attributes.get("ovf:dnsSearch") != null) {
            vmInit.setDnsSearch(node.attributes.get("ovf:dnsSearch").getValue());
        }
        if (node.attributes.get("ovf:networks") != null) {
            vmInit.setNetworks(VmInitUtils.jsonNetworksToList(node.attributes.get("ovf:networks").getValue()));
        }
        if (node.attributes.get("ovf:winKey") != null) {
            vmInit.setWinKey(node.attributes.get("ovf:winKey").getValue());
        }
        if (node.attributes.get("ovf:rootPassword") != null) {
            vmInit.setRootPassword(node.attributes.get("ovf:rootPassword").getValue());
        }
        if (node.attributes.get("ovf:customScript") != null) {
            vmInit.setCustomScript(node.attributes.get("ovf:customScript").getValue());
        }
    }
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) VmInit(org.ovirt.engine.core.common.businessentities.VmInit)

Example 37 with XmlNode

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

the class OvfReader method getMapNode.

private static Map<String, Object> getMapNode(XmlNode node) {
    Map<String, Object> returnValue = new HashMap<>();
    NodeList list = node.getChildNodes();
    for (int index = 0; index < list.getLength(); ++index) {
        Node currNode = list.item(index);
        short nodeType = currNode.getNodeType();
        if (nodeType == Node.ELEMENT_NODE) {
            NodeList childNodes = currNode.getChildNodes();
            // If the element node has only one child, then it contains the value
            if (childNodes.getLength() == 1) {
                Node valueNode = childNodes.item(0);
                if (valueNode.getNodeType() == Node.TEXT_NODE) {
                    returnValue.put(currNode.getNodeName(), valueNode.getNodeValue());
                }
            } else if (childNodes.getLength() > 1) {
                // In this case, we have a nested map, so we parse it
                returnValue.put(currNode.getNodeName(), getMapNode(new XmlNode(currNode)));
            }
        }
    }
    return returnValue;
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) HashMap(java.util.HashMap) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode)

Example 38 with XmlNode

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

the class OvfReader method setDeviceByResource.

private void setDeviceByResource(XmlNode node, VmDevice vmDevice) {
    String resourceType = selectSingleNode(node, VMD_RESOURCE_TYPE, _xmlNS).innerText;
    XmlNode resourceSubTypeNode = selectSingleNode(node, VMD_SUB_RESOURCE_TYPE, _xmlNS);
    if (resourceSubTypeNode == null) {
        // we need special handling for Monitor to define it as vnc or spice
        if (OvfHardware.Monitor.equals(adjustHardwareResourceType(resourceType))) {
            // get number of monitors from VirtualQuantity in OVF
            if (selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS).innerText)) {
                int virtualQuantity = Integer.parseInt(selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS).innerText);
                if (virtualQuantity > 1) {
                    vmDevice.setDevice(VmDeviceType.QXL.getName());
                } else {
                    // get first supported display device
                    List<Pair<GraphicsType, DisplayType>> supportedGraphicsAndDisplays = osRepository.getGraphicsAndDisplays(vmBase.getOsId(), new Version(getVersion()));
                    if (!supportedGraphicsAndDisplays.isEmpty()) {
                        DisplayType firstDisplayType = supportedGraphicsAndDisplays.get(0).getSecond();
                        vmDevice.setDevice(firstDisplayType.getDefaultVmDeviceType().getName());
                    } else {
                        vmDevice.setDevice(VmDeviceType.QXL.getName());
                    }
                }
            } else {
                // default to spice if quantity not found
                vmDevice.setDevice(VmDeviceType.QXL.getName());
            }
        } else {
            vmDevice.setDevice(VmDeviceType.getoVirtDevice(Integer.parseInt(resourceType)).getName());
        }
    } else if (OvfHardware.Network.equals(resourceType)) {
        // handle interfaces with different sub types : we have 0-5 as the VmInterfaceType enum
        Integer nicTypeValue = getVmInterfaceType(resourceSubTypeNode);
        VmInterfaceType nicType = nicTypeValue != null ? VmInterfaceType.forValue(nicTypeValue) : null;
        if (nicType != null) {
            if (nicType == VmInterfaceType.pciPassthrough) {
                vmDevice.setDevice(VmDeviceType.HOST_DEVICE.getName());
            } else {
                vmDevice.setDevice(VmDeviceType.BRIDGE.getName());
            }
        } else {
            vmDevice.setDevice(VmDeviceType.getoVirtDevice(Integer.parseInt(resourceType)).getName());
        }
    }
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) Version(org.ovirt.engine.core.compat.Version) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 39 with XmlNode

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

the class OvfReader method readDiskImageItem.

protected void readDiskImageItem(XmlNode node, DiskImage image) {
    XmlNode templateNode = selectSingleNode(node, "rasd:Template", _xmlNS);
    if (templateNode != null && StringUtils.isNotEmpty(templateNode.innerText)) {
        image.setImageTemplateId(new Guid(templateNode.innerText));
    }
    XmlNode applicationsNode = selectSingleNode(node, "rasd:ApplicationList", _xmlNS);
    if (applicationsNode != null) {
        image.setAppList(applicationsNode.innerText);
    }
    XmlNode storageNode = selectSingleNode(node, "rasd:StorageId", _xmlNS);
    if (storageNode != null && StringUtils.isNotEmpty(storageNode.innerText)) {
        image.setStorageIds(new ArrayList<>(Arrays.asList(new Guid(storageNode.innerText))));
    }
    XmlNode storagePoolNode = selectSingleNode(node, "rasd:StoragePoolId", _xmlNS);
    if (storagePoolNode != null && StringUtils.isNotEmpty(storagePoolNode.innerText)) {
        image.setStoragePoolId(new Guid(storagePoolNode.innerText));
    }
    XmlNode creationDateNode = selectSingleNode(node, "rasd:CreationDate", _xmlNS);
    Date creationDate = creationDateNode != null ? OvfParser.utcDateStringToLocalDate(creationDateNode.innerText) : null;
    if (creationDate != null) {
        image.setCreationDate(creationDate);
    }
    XmlNode lastModifiedNode = selectSingleNode(node, "rasd:LastModified", _xmlNS);
    Date lastModified = lastModifiedNode != null ? OvfParser.utcDateStringToLocalDate(lastModifiedNode.innerText) : null;
    if (lastModified != null) {
        image.setLastModified(lastModified);
    }
    XmlNode lastModifiedDateNode = selectSingleNode(node, "rasd:last_modified_date", _xmlNS);
    Date last_modified_date = lastModifiedDateNode != null ? OvfParser.utcDateStringToLocalDate(lastModifiedDateNode.innerText) : null;
    if (last_modified_date != null) {
        image.setLastModifiedDate(last_modified_date);
    }
    VmDevice readDevice = readManagedVmDevice(node, image.getId());
    image.setPlugged(readDevice.isPlugged());
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) Guid(org.ovirt.engine.core.compat.Guid) Date(java.util.Date)

Example 40 with XmlNode

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

the class OvfVmReader method readEventLogValue.

private String readEventLogValue(XmlNode content, String name) {
    StringBuilder fullNameSB = new StringBuilder(EXPORT_ONLY_PREFIX);
    fullNameSB.append(name);
    XmlNode node = selectSingleNode(content, fullNameSB.toString());
    if (node != null) {
        return node.innerText;
    }
    return null;
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode)

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