Search in sources :

Example 41 with XmlNode

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

the class OvfUtils method isExternalVM.

public boolean isExternalVM(XmlDocument xmlDocument) {
    XmlNode content = xmlDocument.selectSingleNode("//*/Content");
    NodeList nodeList = content.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeName().equals(VM_ORIGIN) && node.getChildNodes().item(0) != null) {
            Integer originType = Integer.valueOf(node.getChildNodes().item(0).getNodeValue());
            return OriginType.EXTERNAL == OriginType.forValue(originType);
        }
    }
    return false;
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) NodeList(org.w3c.dom.NodeList) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList) Node(org.w3c.dom.Node) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode)

Example 42 with XmlNode

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

the class OvfUtils method fetchLeaseDomainId.

public static Guid fetchLeaseDomainId(String ovfData) {
    Guid leaseDomainId = null;
    try {
        XmlDocument xmlDocument = new XmlDocument(ovfData);
        XmlNode xmlNode = xmlDocument.selectSingleNode("//*/Content").selectSingleNode("LeaseDomainId");
        if (xmlNode != null) {
            leaseDomainId = Guid.createGuidFromString(xmlNode.innerText);
        }
    } catch (Exception e) {
        log.debug("failed to parse a given ovf configuration: \n" + ovfData, e);
    }
    return leaseDomainId;
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) Guid(org.ovirt.engine.core.compat.Guid) IOException(java.io.IOException)

Example 43 with XmlNode

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

the class VmDevicesConverter method parseDev.

/**
 * This method should be used for managed devices with one instance per VM
 */
private Map<String, Object> parseDev(VmDeviceGeneralType devType, XmlDocument document, List<VmDevice> devices) {
    VmDevice dbDevice = filterDevice(devices, devType);
    if (dbDevice == null) {
        return Collections.emptyMap();
    }
    XmlNode node = selectSingleNode(document, devType);
    if (node == null) {
        return Collections.emptyMap();
    }
    Map<String, Object> result = new HashMap<>();
    result.put(VdsProperties.Device, devType);
    result.put(VdsProperties.DeviceId, dbDevice.getDeviceId().toString());
    result.put(VdsProperties.Address, parseAddress(node));
    result.put(VdsProperties.Alias, parseAlias(node));
    result.put(VdsProperties.SpecParams, dbDevice.getSpecParams());
    return result;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) HashMap(java.util.HashMap)

Example 44 with XmlNode

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

the class VmDevicesConverter method convert.

public Map<String, Object> convert(Guid vmId, Guid hostId, String xml) throws Exception {
    String devicesXml = xml.substring(xml.indexOf(DEVICES_START_ELEMENT), xml.indexOf(DEVICES_END_ELEMENT) + DEVICES_END_ELEMENT.length());
    XmlDocument document = new XmlDocument(devicesXml);
    XmlNode metadata = new XmlDocument(xml).selectSingleNode("domain/metadata");
    Map<String, Object> result = new HashMap<>();
    result.put(VdsProperties.vm_guid, vmId.toString());
    result.put(VdsProperties.Devices, parseDevices(vmId, hostId, document));
    result.put(VdsProperties.GuestDiskMapping, parseDiskMapping(metadata));
    return result;
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) HashMap(java.util.HashMap) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument)

Example 45 with XmlNode

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

the class VmDevicesConverter method parseVideos.

private List<Map<String, Object>> parseVideos(XmlDocument document, List<VmDevice> devices) {
    List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.VIDEO);
    List<Map<String, Object>> result = new ArrayList<>();
    for (XmlNode node : selectNodes(document, VmDeviceGeneralType.VIDEO)) {
        Map<String, Object> dev = new HashMap<>();
        dev.put(VdsProperties.Type, VmDeviceGeneralType.VIDEO.getValue());
        dev.put(VdsProperties.Device, parseVideoType(node));
        dev.put(VdsProperties.Address, parseAddress(node));
        dev.put(VdsProperties.Alias, parseAlias(node));
        // There is supposed to be one video device of each type (spice/vnc/..)
        VmDevice dbDev = correlate(dev, dbDevices, device -> dbDevices.stream().filter(d -> d.getDevice().equals(device.get(VdsProperties.Device))).findFirst().orElse(null));
        if (dbDev == null) {
            log.warn("unmanaged video device with address '{}' is ignored", dev.get(VdsProperties.Address));
            continue;
        }
        dbDevices.remove(dbDev);
        dev.put(VdsProperties.DeviceId, dbDev.getDeviceId().toString());
        dev.put(VdsProperties.SpecParams, dbDev.getSpecParams());
        result.add(dev);
    }
    return result;
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) DiskLunMapDao(org.ovirt.engine.core.dao.DiskLunMapDao) Guid(org.ovirt.engine.core.compat.Guid) XmlNamespaceManager(org.ovirt.engine.core.utils.ovf.xml.XmlNamespaceManager) UsbControllerModel(org.ovirt.engine.core.common.businessentities.UsbControllerModel) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute) LibvirtVmXmlBuilder(org.ovirt.engine.core.vdsbroker.builder.vminfo.LibvirtVmXmlBuilder) Singleton(javax.inject.Singleton) Function(java.util.function.Function) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) Inject(javax.inject.Inject) DiskImageDao(org.ovirt.engine.core.dao.DiskImageDao) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VdsProperties(org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties) VmDeviceDao(org.ovirt.engine.core.dao.VmDeviceDao) VmNetworkInterfaceDao(org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao) MemoizingSupplier(org.ovirt.engine.core.utils.MemoizingSupplier) Logger(org.slf4j.Logger) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) HostDeviceDao(org.ovirt.engine.core.dao.HostDeviceDao) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) SPEC_PARAM_NODE(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.SPEC_PARAM_NODE) SPEC_PARAM_SIZE(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.SPEC_PARAM_SIZE) Optional(java.util.Optional) Comparator(java.util.Comparator) Collections(java.util.Collections) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) Map(java.util.Map)

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