Search in sources :

Example 31 with VmDevice

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

the class ProcessDownVmCommand method createUpdateVmParameters.

private VmManagementParametersBase createUpdateVmParameters() {
    // clear non updateable fields got from config
    getVm().setExportDate(null);
    getVm().setOvfVersion(null);
    VmManagementParametersBase updateVmParams = new VmManagementParametersBase(getVm());
    updateVmParams.setUpdateWatchdog(true);
    updateVmParams.setSoundDeviceEnabled(false);
    updateVmParams.setBalloonEnabled(false);
    updateVmParams.setVirtioScsiEnabled(false);
    updateVmParams.setClearPayload(true);
    updateVmParams.setUpdateRngDevice(true);
    for (GraphicsType graphicsType : GraphicsType.values()) {
        updateVmParams.getGraphicsDevices().put(graphicsType, null);
    }
    for (VmDevice device : getVm().getManagedVmDeviceMap().values()) {
        switch(device.getType()) {
            case WATCHDOG:
                updateVmParams.setWatchdog(new VmWatchdog(device));
                break;
            case SOUND:
                updateVmParams.setSoundDeviceEnabled(true);
                break;
            case BALLOON:
                updateVmParams.setBalloonEnabled(true);
                break;
            case CONTROLLER:
                if (VmDeviceType.VIRTIOSCSI.getName().equals(device.getDevice())) {
                    updateVmParams.setVirtioScsiEnabled(true);
                }
                break;
            case DISK:
                if (VmPayload.isPayload(device.getSpecParams())) {
                    updateVmParams.setVmPayload(new VmPayload(device));
                }
                break;
            case CONSOLE:
                updateVmParams.setConsoleEnabled(true);
                break;
            case RNG:
                updateVmParams.setRngDevice(new VmRngDevice(device));
                break;
            case GRAPHICS:
                updateVmParams.getGraphicsDevices().put(GraphicsType.fromString(device.getDevice()), new GraphicsDevice(device));
                break;
            default:
        }
    }
    // clear these fields as these are non updatable
    getVm().getManagedVmDeviceMap().clear();
    getVm().getUnmanagedDeviceList().clear();
    return updateVmParams;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) VmManagementParametersBase(org.ovirt.engine.core.common.action.VmManagementParametersBase) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 32 with VmDevice

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

the class RemoveGraphicsAndVideoDevicesCommand method executeCommand.

@Override
protected void executeCommand() {
    VmDevice graphicsDev = getParameters().getDev();
    vmDeviceDao.remove(graphicsDev.getId());
    if (noGraphicsDevicesLeft()) {
        vmDeviceUtils.removeVideoDevices(getVmBaseId());
        // Since getParameters().isVm() isn't set by REST api, try to set VM and if failed then try to set Template
        if (!setVmToHeadlessMode()) {
            setTemplateToHeadlessMode();
        }
    }
    setSucceeded(true);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Example 33 with VmDevice

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

the class RemoveGraphicsDeviceCommand method executeCommand.

@Override
protected void executeCommand() {
    VmDevice graphicsDev = getParameters().getDev();
    vmDeviceDao.remove(graphicsDev.getId());
    setSucceeded(true);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Example 34 with VmDevice

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

the class ActivateDeactivateVmNicCommand method searchForDuplicatesWithExistingVmDevices.

private boolean searchForDuplicatesWithExistingVmDevices(VmDevice vmDeviceToHotplug) {
    String deviceAddress = vmDeviceToHotplug.getAddress();
    if (StringUtils.isEmpty(deviceAddress)) {
        return false;
    }
    Map<String, String> addressMapToHotplug = StringMapUtils.string2Map(deviceAddress);
    List<VmDevice> allVmDevices = vmDeviceDao.getVmDeviceByVmId(getVm().getId());
    for (VmDevice vmDevice : allVmDevices) {
        if (!vmDeviceToHotplug.getId().equals(vmDevice.getId())) {
            Map<String, String> deviceAddressMap = StringMapUtils.string2Map(vmDevice.getAddress());
            boolean duplicatedAddress = deviceAddressMap.equals(addressMapToHotplug);
            boolean ambiguousInterfaceState = StringUtils.isEmpty(vmDevice.getAddress()) && vmDevice.isPlugged() && VmDeviceGeneralType.INTERFACE.equals(vmDevice.getType());
            if (duplicatedAddress || ambiguousInterfaceState) {
                return true;
            }
        }
    }
    return false;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Example 35 with VmDevice

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

the class AddVmInterfaceCommand method addInterfaceDeviceToDb.

private void addInterfaceDeviceToDb() {
    VmDevice vmDevice = getVmDeviceUtils().addInterface(getParameters().getVmId(), getInterface().getId(), getInterface().isPlugged(), getInterface().isPassthrough());
    getCompensationContext().snapshotNewEntity(vmDevice);
}
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