Search in sources :

Example 6 with VmRngDevice

use of org.ovirt.engine.core.common.businessentities.VmRngDevice 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 7 with VmRngDevice

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

the class VmDeviceUtils method copyVmDevices.

/**
 * Copy devices from the given VmDevice list to the destination VM/VmBase.
 */
public void copyVmDevices(Guid srcId, Guid dstId, VmBase srcVmBase, VmBase dstVmBase, List<VmDevice> srcDevices, Map<Guid, Guid> srcDeviceIdToDstDeviceIdMapping, boolean isSoundEnabled, boolean isConsoleEnabled, Boolean isVirtioScsiEnabled, boolean isBalloonEnabled, Set<GraphicsType> graphicsToSkip, boolean copySnapshotDevices, boolean copyHostDevices, Version versionToUpdateRngDeviceWith) {
    if (graphicsToSkip == null) {
        graphicsToSkip = Collections.emptySet();
    }
    String dstCdPath = dstVmBase.getIsoPath();
    boolean dstIsVm = !(dstVmBase instanceof VmTemplate);
    boolean hasCd = hasCdDevice(dstVmBase.getId());
    boolean hasSound = false;
    boolean hasConsole = false;
    boolean hasVirtioScsi = false;
    boolean hasBalloon = false;
    boolean hasRng = hasRngDevice(dstId);
    Cluster cluster = null;
    if (dstVmBase.getClusterId() != null) {
        cluster = clusterDao.get(dstVmBase.getClusterId());
    }
    for (VmDevice device : srcDevices) {
        if (device.getSnapshotId() != null && !copySnapshotDevices) {
            continue;
        }
        Guid deviceId = Guid.newGuid();
        Map<String, Object> specParams = new HashMap<>();
        switch(device.getType()) {
            case DISK:
                if (VmDeviceType.DISK.getName().equals(device.getDevice())) {
                    if (srcDeviceIdToDstDeviceIdMapping.containsKey(device.getDeviceId())) {
                        deviceId = srcDeviceIdToDstDeviceIdMapping.get(device.getDeviceId());
                    }
                } else if (VmDeviceType.CDROM.getName().equals(device.getDevice())) {
                    if (!hasCd) {
                        hasCd = true;
                        // check here is source VM had CD (VM from snapshot)
                        String srcCdPath = (String) device.getSpecParams().get(VdsProperties.Path);
                        specParams.putAll(getCdDeviceSpecParams(srcCdPath, dstCdPath));
                    } else {
                        // CD already exists
                        continue;
                    }
                }
                break;
            case INTERFACE:
                if (srcDeviceIdToDstDeviceIdMapping.containsKey(device.getDeviceId())) {
                    deviceId = srcDeviceIdToDstDeviceIdMapping.get(device.getDeviceId());
                }
                break;
            case CONTROLLER:
                if (VmDeviceType.USB.getName().equals(device.getDevice())) {
                    specParams = device.getSpecParams();
                } else if (VmDeviceType.VIRTIOSCSI.getName().equals(device.getDevice())) {
                    hasVirtioScsi = true;
                    if (Boolean.FALSE.equals(isVirtioScsiEnabled)) {
                        continue;
                    }
                }
                break;
            case VIDEO:
                if (dstIsVm) {
                    // to the new Vm params.
                    continue;
                }
                specParams.putAll(getVideoDeviceSpecParams(dstVmBase));
                break;
            case BALLOON:
                if (!isBalloonEnabled) {
                    continue;
                }
                hasBalloon = true;
                specParams.putAll(getMemoryBalloonSpecParams());
                break;
            case SMARTCARD:
                specParams.putAll(getSmartcardDeviceSpecParams());
                break;
            case WATCHDOG:
                specParams.putAll(device.getSpecParams());
                break;
            case RNG:
                if (hasRng) {
                    continue;
                }
                if (!new VirtIoRngValidator().canAddRngDevice(cluster, new VmRngDevice(device)).isValid()) {
                    continue;
                }
                final VmRngDevice rngDevice = new VmRngDevice(device);
                if (versionToUpdateRngDeviceWith != null) {
                    rngDevice.updateSourceByVersion(versionToUpdateRngDeviceWith);
                }
                specParams.putAll(rngDevice.getSpecParams());
                break;
            case CONSOLE:
                if (!isConsoleEnabled) {
                    continue;
                }
                specParams.putAll(device.getSpecParams());
                hasConsole = true;
                break;
            case SOUND:
                if (!isSoundEnabled) {
                    continue;
                }
                hasSound = true;
                break;
            case GRAPHICS:
                GraphicsType type = GraphicsType.fromVmDeviceType(VmDeviceType.getByName(device.getDevice()));
                // OR if we already have it
                if (graphicsToSkip.contains(type) || hasGraphicsDevice(dstId, GraphicsType.fromString(device.getDevice()))) {
                    continue;
                }
                break;
            case HOSTDEV:
                if (!copyHostDevices) {
                    continue;
                }
                specParams.putAll(device.getSpecParams());
                break;
            default:
                break;
        }
        device.setId(new VmDeviceId(deviceId, dstId));
        device.setSpecParams(specParams);
        vmDeviceDao.save(device);
    }
    if (!hasCd) {
        addCdDevice(dstId, dstCdPath);
    }
    updateUsbSlots(srcVmBase, dstVmBase, () -> clusterDao.get(dstVmBase.getClusterId()));
    if (isSoundEnabled && !hasSound) {
        if (dstIsVm) {
            addSoundDevice(dstVmBase);
        } else {
            addSoundDevice(dstVmBase.getId(), dstVmBase.getOsId(), cluster != null ? cluster.getCompatibilityVersion() : null);
        }
    }
    if (isConsoleEnabled && !hasConsole) {
        addConsoleDevice(dstId);
    }
    if (Boolean.TRUE.equals(isVirtioScsiEnabled) && !hasVirtioScsi) {
        addVirtioScsiController(dstVmBase, getVmCompatibilityVersion(dstVmBase));
    }
    if (isBalloonEnabled && !hasBalloon) {
        addMemoryBalloon(dstId);
    }
    if (dstIsVm) {
        addVideoDevices(dstVmBase, getNeededNumberOfVideoDevices(dstVmBase));
    }
}
Also used : VirtIoRngValidator(org.ovirt.engine.core.bll.validator.VirtIoRngValidator) HashMap(java.util.HashMap) MacPoolPerCluster(org.ovirt.engine.core.bll.network.macpool.MacPoolPerCluster) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Guid(org.ovirt.engine.core.compat.Guid) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 8 with VmRngDevice

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

the class BackendTemplatesResource method doPopulate.

@Override
protected Template doPopulate(Template model, VmTemplate entity) {
    if (!model.isSetConsole()) {
        model.setConsole(new Console());
    }
    model.getConsole().setEnabled(!getConsoleDevicesForEntity(entity.getId()).isEmpty());
    if (!model.isSetVirtioScsi()) {
        model.setVirtioScsi(new VirtioScsi());
    }
    model.getVirtioScsi().setEnabled(!VmHelper.getVirtioScsiControllersForEntity(this, entity.getId()).isEmpty());
    model.setSoundcardEnabled(!VmHelper.getSoundDevicesForEntity(this, entity.getId()).isEmpty());
    List<VmRngDevice> rngDevices = getRngDevices(entity.getId());
    if (rngDevices != null && !rngDevices.isEmpty()) {
        model.setRngDevice(RngDeviceMapper.map(rngDevices.get(0), null));
    }
    MemoryPolicyHelper.setupMemoryBalloon(model, this);
    return model;
}
Also used : VirtioScsi(org.ovirt.engine.api.model.VirtioScsi) Console(org.ovirt.engine.api.model.Console) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 9 with VmRngDevice

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

the class RngDeviceMapper method map.

@Mapping(from = VmRngDevice.class, to = RngDevice.class)
public static RngDevice map(VmRngDevice entity, RngDevice template) {
    RngDevice model = (template == null) ? new RngDevice() : template;
    if (entity.getBytes() != null) {
        model.setRate(new Rate());
        model.getRate().setBytes(entity.getBytes());
        if (entity.getPeriod() != null) {
            model.getRate().setPeriod(entity.getPeriod());
        }
    }
    RngSource restSource = map(entity.getSource(), null);
    model.setSource(restSource);
    return model;
}
Also used : RngSource(org.ovirt.engine.api.model.RngSource) Rate(org.ovirt.engine.api.model.Rate) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) RngDevice(org.ovirt.engine.api.model.RngDevice)

Example 10 with VmRngDevice

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

the class ExistingNonClusterModelBehavior method initialize.

@Override
public void initialize() {
    super.initialize();
    updateNumOfSockets();
    getModel().getUsbPolicy().setItems(Arrays.asList(UsbPolicy.values()));
    getModel().getIsSoundcardEnabled().setIsChangeable(true);
    Frontend.getInstance().runQuery(QueryType.GetGraphicsDevices, new IdQueryParameters(entity.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
        List<GraphicsDevice> graphicsDevices = returnValue.getReturnValue();
        Set<GraphicsType> graphicsTypesCollection = new HashSet<>();
        for (GraphicsDevice graphicsDevice : graphicsDevices) {
            graphicsTypesCollection.add(graphicsDevice.getGraphicsType());
        }
        initDisplayTypes(entity.getDefaultDisplayType(), UnitVmModel.GraphicsTypes.fromGraphicsTypes(graphicsTypesCollection));
        doBuild();
    }));
    initSoundCard(entity.getId());
    updateConsoleDevice(entity.getId());
    initPriority(entity.getPriority());
    Frontend.getInstance().runQuery(QueryType.IsBalloonEnabled, new IdQueryParameters(entity.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> getModel().getMemoryBalloonDeviceEnabled().setEntity((Boolean) returnValue.getReturnValue())));
    getInstance().isVirtioScsiEnabledForVm(new AsyncQuery<>(returnValue -> getModel().getIsVirtioScsiEnabled().setEntity(returnValue)), entity.getId());
    getInstance().getWatchdogByVmId(new AsyncQuery<QueryReturnValue>(returnValue -> {
        @SuppressWarnings("unchecked") Collection<VmWatchdog> watchdogs = returnValue.getReturnValue();
        for (VmWatchdog watchdog : watchdogs) {
            getModel().getWatchdogAction().setSelectedItem(watchdog.getAction());
            getModel().getWatchdogModel().setSelectedItem(watchdog.getModel());
        }
    }), entity.getId());
    Frontend.getInstance().runQuery(QueryType.GetRngDevice, new IdQueryParameters(entity.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
        List<VmDevice> rngDevices = returnValue.getReturnValue();
        getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty());
        if (!rngDevices.isEmpty()) {
            VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0));
            getModel().setRngDevice(rngDevice);
        }
    }));
    getModel().getEmulatedMachine().setSelectedItem(entity.getCustomEmulatedMachine());
    getModel().getCustomCpu().setSelectedItem(entity.getCustomCpuName());
    getModel().getMigrationMode().setSelectedItem(entity.getMigrationSupport());
    getModel().getCpuSharesAmount().setEntity(entity.getCpuShares());
    getModel().getIsHighlyAvailable().setEntity(entity.isAutoStartup());
    updateCpuSharesSelection();
}
Also used : UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) QueryType(org.ovirt.engine.core.common.queries.QueryType) AsyncDataProvider.getInstance(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider.getInstance) Arrays(java.util.Arrays) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) BuilderExecutor(org.ovirt.engine.ui.uicommonweb.builders.BuilderExecutor) NameAndDescriptionVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.NameAndDescriptionVmBaseToUnitBuilder) Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Set(java.util.Set) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) HashSet(java.util.HashSet) HwOnlyVmBaseToUnitBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.HwOnlyVmBaseToUnitBuilder) Frontend(org.ovirt.engine.ui.frontend.Frontend) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) UnitVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Set(java.util.Set) HashSet(java.util.HashSet) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) Collection(java.util.Collection) List(java.util.List) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Aggregations

VmRngDevice (org.ovirt.engine.core.common.businessentities.VmRngDevice)24 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)8 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)5 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)5 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)5 Test (org.junit.Test)4 GraphicsDevice (org.ovirt.engine.core.common.businessentities.GraphicsDevice)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4 VmWatchdog (org.ovirt.engine.core.common.businessentities.VmWatchdog)4 Guid (org.ovirt.engine.core.compat.Guid)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Rate (org.ovirt.engine.api.model.Rate)3 RngDevice (org.ovirt.engine.api.model.RngDevice)3 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)3 RngDeviceParameters (org.ovirt.engine.core.common.action.RngDeviceParameters)3 VmBase (org.ovirt.engine.core.common.businessentities.VmBase)3