Search in sources :

Example 41 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class HotPlugDiskToVmCommandTest method mockVmDevice.

protected void mockVmDevice(boolean plugged) {
    vmDevice = new VmDevice();
    vmDevice.setId(new VmDeviceId());
    vmDevice.setPlugged(plugged);
    when(vmDeviceDao.get(any())).thenReturn(vmDevice);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 42 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class OvfReader method readUnmanagedVmDevice.

protected VmDevice readUnmanagedVmDevice(XmlNode node, Guid deviceId) {
    VmDevice vmDevice = readVmDevice(node, deviceId);
    vmBase.getUnmanagedDeviceList().add(vmDevice);
    return vmDevice;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Example 43 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class OvfReader method readHardwareSection.

protected void readHardwareSection(XmlNode section) {
    boolean readVirtioSerial = false;
    int nicIdx = 0;
    for (XmlNode item : selectNodes(section, "Item")) {
        String resourceType = selectSingleNode(item, "rasd:ResourceType", _xmlNS).innerText;
        resourceType = adjustHardwareResourceType(resourceType);
        switch(resourceType) {
            case OvfHardware.CPU:
                readCpuItem(item);
                break;
            case OvfHardware.Memory:
                readMemoryItem(item);
                break;
            case OvfHardware.DiskImage:
                readDiskImageItem(item);
                break;
            case OvfHardware.Network:
                /**
                 *  If NIC items are found in the hardware section of the OVF, they are the real ones,
                 *  so clear the NIC references found in the <NetworkSection> of the OVF which are used
                 *  only to map networks, but should not be used to create NICs. Clear() is performed only
                 *  upon finding the first NIC item.
                 */
                if (nicIdx == 0) {
                    interfaces.clear();
                }
                readNetworkItem(item, ++nicIdx);
                break;
            case OvfHardware.USB:
                readUsbItem(item);
                break;
            case OvfHardware.Monitor:
                readMonitorItem(item);
                break;
            case OvfHardware.Graphics:
                // so far graphics doesn't contain anything special
                readManagedVmDevice(item, Guid.newGuid());
                break;
            case OvfHardware.CD:
                readCdItem(item);
                break;
            case OvfHardware.OTHER:
                VmDevice vmDevice = readOtherHardwareItem(item);
                readVirtioSerial = readVirtioSerial || VmDeviceType.VIRTIOSERIAL.getName().equals(vmDevice.getDevice());
                break;
        }
    }
    if (!readVirtioSerial) {
        addManagedVmDevice(VmDeviceCommonUtils.createVirtioSerialDeviceForVm(vmBase.getId()));
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode)

Example 44 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class OvfReader method readVmDevice.

/**
 * Reads vm device attributes from OVF and stores it in the collection
 */
private VmDevice readVmDevice(XmlNode node, Guid deviceId) {
    VmDevice vmDevice = new VmDevice();
    vmDevice.setId(new VmDeviceId(deviceId, vmBase.getId()));
    if (selectSingleNode(node, VMD_ADDRESS, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_ADDRESS, _xmlNS).innerText)) {
        vmDevice.setAddress(String.valueOf(selectSingleNode(node, VMD_ADDRESS, _xmlNS).innerText));
    } else {
        vmDevice.setAddress("");
    }
    if (selectSingleNode(node, VMD_ALIAS, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_ALIAS, _xmlNS).innerText)) {
        vmDevice.setAlias(String.valueOf(selectSingleNode(node, VMD_ALIAS, _xmlNS).innerText));
    } else {
        vmDevice.setAlias("");
    }
    XmlNode specParamsNode = selectSingleNode(node, VMD_SPEC_PARAMS, _xmlNS);
    if (specParamsNode != null && !StringUtils.isEmpty(specParamsNode.innerText)) {
        vmDevice.setSpecParams(getMapNode(specParamsNode));
    } else {
        // Empty map
        vmDevice.setSpecParams(Collections.emptyMap());
    }
    if (selectSingleNode(node, VMD_TYPE, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_TYPE, _xmlNS).innerText)) {
        vmDevice.setType(VmDeviceGeneralType.forValue(String.valueOf(selectSingleNode(node, VMD_TYPE, _xmlNS).innerText)));
    } else {
        int resourceType = getResourceType(node, VMD_RESOURCE_TYPE);
        vmDevice.setType(VmDeviceGeneralType.forValue(VmDeviceType.getoVirtDevice(resourceType)));
    }
    if (selectSingleNode(node, VMD_DEVICE, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_DEVICE, _xmlNS).innerText)) {
        vmDevice.setDevice(String.valueOf(selectSingleNode(node, VMD_DEVICE, _xmlNS).innerText));
    } else {
        setDeviceByResource(node, vmDevice);
    }
    if (selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS).innerText)) {
        vmDevice.setPlugged(Boolean.valueOf(selectSingleNode(node, VMD_IS_PLUGGED, _xmlNS).innerText));
    } else {
        vmDevice.setPlugged(Boolean.TRUE);
    }
    if (selectSingleNode(node, VMD_IS_READONLY, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_IS_READONLY, _xmlNS).innerText)) {
        vmDevice.setReadOnly(Boolean.valueOf(selectSingleNode(node, VMD_IS_READONLY, _xmlNS).innerText));
    } else {
        vmDevice.setReadOnly(Boolean.FALSE);
    }
    if (selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS) != null && StringUtils.isNotEmpty(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)) {
        vmDevice.setCustomProperties(DevicePropertiesUtils.getInstance().convertProperties(String.valueOf(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)));
    } else {
        vmDevice.setCustomProperties(null);
    }
    if (selectSingleNode(node, VMD_SNAPSHOT_PROP, _xmlNS) != null && StringUtils.isNotEmpty(selectSingleNode(node, VMD_SNAPSHOT_PROP, _xmlNS).innerText)) {
        vmDevice.setSnapshotId(new Guid(String.valueOf(selectSingleNode(node, VMD_CUSTOM_PROP, _xmlNS).innerText)));
    }
    return vmDevice;
}
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) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 45 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class OvfWriter method writeGraphics.

private void writeGraphics() {
    Collection<VmDevice> devices = vmBase.getManagedDeviceMap().values();
    for (VmDevice vmDevice : devices) {
        if (vmDevice.getType() == VmDeviceGeneralType.GRAPHICS) {
            _writer.writeStartElement("Item");
            _writer.writeElement(RASD_URI, "Caption", "Graphical Framebuffer");
            _writer.writeElement(RASD_URI, "InstanceId", vmDevice.getId().getDeviceId().toString());
            _writer.writeElement(RASD_URI, "ResourceType", adjustHardwareResourceType(OvfHardware.Graphics));
            writeVmDeviceInfo(vmDevice);
            // item
            _writer.writeEndElement();
        }
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Aggregations

VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)170 HashMap (java.util.HashMap)59 Guid (org.ovirt.engine.core.compat.Guid)53 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)48 ArrayList (java.util.ArrayList)34 Map (java.util.Map)33 VM (org.ovirt.engine.core.common.businessentities.VM)29 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)28 List (java.util.List)26 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)21 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)21 VmDeviceType (org.ovirt.engine.core.common.utils.VmDeviceType)20 Collections (java.util.Collections)19 Test (org.junit.Test)19 Collectors (java.util.stream.Collectors)18 Arrays (java.util.Arrays)17 Optional (java.util.Optional)17 StringUtils (org.apache.commons.lang.StringUtils)17 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)17 Inject (javax.inject.Inject)16