Search in sources :

Example 6 with XmlAttribute

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

the class VmDevicesConverter method parseDiskPath.

private String parseDiskPath(XmlNode node) {
    XmlNode sourceNode = node.selectSingleNode("source");
    if (sourceNode == null) {
        return "";
    }
    XmlAttribute attr = sourceNode.attributes.get("file");
    if (attr != null) {
        return attr.getValue();
    }
    attr = sourceNode.attributes.get("dev");
    if (attr != null) {
        return attr.getValue();
    }
    attr = sourceNode.attributes.get("name");
    if (attr != null) {
        return attr.getValue();
    }
    return "";
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute)

Example 7 with XmlAttribute

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

the class VmDevicesConverter method parseHostAddress.

private Map<String, String> parseHostAddress(XmlNode node) {
    XmlNode sourceNode = node.selectSingleNode("source");
    if (sourceNode == null) {
        return null;
    }
    XmlNode addressNode = sourceNode.selectSingleNode("address");
    if (addressNode == null) {
        return null;
    }
    Map<String, String> address = new HashMap<>();
    Arrays.asList("domain", "slot", "bus", "function", "device", "host", "target", "lun").forEach(key -> {
        XmlAttribute attribute = addressNode.attributes.get(key);
        if (attribute != null) {
            String valStr = attribute.getValue();
            boolean hex = valStr.startsWith("0x");
            int val = Integer.parseInt(hex ? valStr.substring(2) : valStr, hex ? 16 : 10);
            address.put(key, String.valueOf(val));
        }
    });
    XmlAttribute uuidAttribute = addressNode.attributes.get("uuid");
    if (uuidAttribute != null) {
        address.put("uuid", uuidAttribute.getValue());
    }
    return address;
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute) HashMap(java.util.HashMap)

Aggregations

XmlAttribute (org.ovirt.engine.core.utils.ovf.xml.XmlAttribute)7 XmlNode (org.ovirt.engine.core.utils.ovf.xml.XmlNode)4 HashMap (java.util.HashMap)1 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)1 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)1 Guid (org.ovirt.engine.core.compat.Guid)1