Search in sources :

Example 1 with XmlAttribute

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

the class VmDevicesConverter method parseAddress.

private String parseAddress(XmlNode node) {
    String result = "";
    XmlNode addressNode = node.selectSingleNode("address");
    if (addressNode == null) {
        return "";
    }
    XmlAttribute val = addressNode.attributes.get("type");
    result += String.format("%s=%s", "type", val.getValue());
    val = addressNode.attributes.get("slot");
    if (val != null) {
        result += String.format(", %s=%s", "slot", val.getValue());
    }
    val = addressNode.attributes.get("bus");
    if (val != null) {
        result += String.format(", %s=%s", "bus", val.getValue());
    }
    val = addressNode.attributes.get("domain");
    if (val != null) {
        result += String.format(", %s=%s", "domain", val.getValue());
    }
    val = addressNode.attributes.get("function");
    if (val != null) {
        result += String.format(", %s=%s", "function", val.getValue());
    }
    val = addressNode.attributes.get("controller");
    if (val != null) {
        result += String.format(", %s=%s", "controller", val.getValue());
    }
    val = addressNode.attributes.get("target");
    if (val != null) {
        result += String.format(", %s=%s", "target", val.getValue());
    }
    val = addressNode.attributes.get("unit");
    if (val != null) {
        result += String.format(", %s=%s", "unit", val.getValue());
    }
    val = addressNode.attributes.get("port");
    if (val != null) {
        result += String.format(", %s=%s", "port", val.getValue());
    }
    val = addressNode.attributes.get("multifunction");
    if (val != null) {
        result += String.format(", %s=%s", "multifunction", val.getValue());
    }
    val = addressNode.attributes.get("base");
    if (val != null) {
        result += String.format(", %s=%s", "base", val.getValue());
    }
    return result.isEmpty() ? result : String.format("{%s}", result);
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute)

Example 2 with XmlAttribute

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

the class VmDevicesConverter method parseIoThreadId.

private Integer parseIoThreadId(XmlNode node) {
    XmlNode driverNode = node.selectSingleNode("driver");
    if (driverNode == null) {
        return null;
    }
    XmlAttribute val = driverNode.attributes.get("iothread");
    return val != null ? Integer.valueOf(val.getValue()) : null;
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute)

Example 3 with XmlAttribute

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

the class OvfOvaReader method readDisk.

@Override
protected void readDisk(XmlNode node, DiskImage image) {
    String diskId = node.attributes.get("ovf:diskId").getValue();
    String fileRef = node.attributes.get("ovf:fileRef").getValue();
    // If the disk storage type is Cinder then override the disk image with Cinder object,
    // otherwise use the disk image.
    image = new DiskImage();
    // image.
    if (node.attributes.get("ovf:disk_storage_type") != null) {
        String diskStorageType = node.attributes.get("ovf:disk_storage_type").getValue();
        if (diskStorageType != null && diskStorageType.equals(DiskStorageType.CINDER.name())) {
            image = new CinderDisk();
            if (node.attributes.get("ovf:cinder_volume_type") != null) {
                String cinderVolumeType = node.attributes.get("ovf:cinder_volume_type").getValue();
                image.setCinderVolumeType(cinderVolumeType);
            }
        }
    }
    try {
        image.setImageId(new Guid(fileRef));
    } catch (Exception ex) {
        log.warn("could not retrieve volume id of {} from ovf, generating new guid", fileRef);
        image.setImageId(Guid.newGuid());
    }
    try {
        image.setId(new Guid(diskId));
    } catch (Exception ex) {
        log.warn("could not retrieve disk id of {} from ovf, generating new guid", diskId);
        image.setId(Guid.newGuid());
    }
    XmlAttribute description = node.attributes.get("ovf:description");
    if (description != null) {
        image.setDescription(description.getValue());
    } else {
        image.setDescription(diskId);
    }
    XmlAttribute virtualSize = node.attributes.get("ovf:capacity");
    if (virtualSize != null) {
        // TODO take ovf:capacityAllocationUnits into account
        image.setSize(convertGigabyteToBytes(Long.parseLong(virtualSize.getValue())));
    }
    XmlAttribute populatedSize = node.attributes.get("ovf:populatedSize");
    if (populatedSize != null) {
        image.setActualSizeInBytes(Long.parseLong(populatedSize.getValue()));
    } else {
        Long actualSize = Long.parseLong(fileIdToFileAttributes.get(fileRef).get("ovf:size").getValue());
        image.setActualSizeInBytes(actualSize);
    }
    super.readDisk(node, image);
    if (StringUtils.isEmpty(image.getDiskAlias())) {
        image.setDiskAlias(diskId);
    }
    image.setRemotePath(fileIdToFileAttributes.get(fileRef).get("ovf:href").getValue());
    _images.add(image);
}
Also used : XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute) Guid(org.ovirt.engine.core.compat.Guid) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 4 with XmlAttribute

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

the class OvfReader method consumeReadXmlAttribute.

protected void consumeReadXmlAttribute(XmlNode content, String propertyKey, Consumer<String> then, Runnable orElse) {
    XmlAttribute node = content.attributes.get(propertyKey);
    acceptNode(then, orElse, node);
}
Also used : XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute)

Example 5 with XmlAttribute

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

the class OvfOvaReader method readOsSection.

protected void readOsSection(XmlNode section) {
    XmlAttribute ovirtOsId = section.attributes.get("ovirt:id");
    int osId = ovirtOsId != null ? Integer.parseInt(ovirtOsId.getValue()) : mapOsId(section.attributes.get("ovf:id").getValue());
    vm.setVmOs(osId);
    setClusterArch(osRepository.getArchitectureFromOS(osId));
}
Also used : XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute)

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