Search in sources :

Example 71 with VmDeviceId

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

the class UpdateVmTemplateInterfaceCommand method executeCommand.

@Override
protected void executeCommand() {
    vmNicDao.update(getParameters().getInterface());
    VmDevice vmDevice = vmDeviceDao.get(new VmDeviceId(getParameters().getInterface().getId(), getParameters().getVmTemplateId()));
    vmDevice.setPlugged(getParameters().getInterface().isPlugged());
    vmDevice.setDevice(getParameters().getInterface().isPassthrough() ? VmDeviceType.HOST_DEVICE.getName() : VmDeviceType.BRIDGE.getName());
    vmDeviceDao.update(vmDevice);
    setSucceeded(true);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 72 with VmDeviceId

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

the class VmDeviceUtils method getVmDevicesForNextRun.

/**
 * Returns a map (device ID to VmDevice) of devices that are relevant for next run.
 *
 * The list of devices is built by examining properties that are annotated with EditableDeviceOnVmStatusField
 * annotation.
 *
 * @param vm the relevant VM
 * @param objectWithEditableDeviceFields object that contains properties which are annotated with
 *                                       EditableDeviceOnVmStatusField (e.g. parameters file)
 * @param vmVideoDeviceTypeforNextRun VM video device type for next run
 * @return a map of device ID to VmDevice
 */
public Map<Guid, VmDevice> getVmDevicesForNextRun(VM vm, Object objectWithEditableDeviceFields, DisplayType vmVideoDeviceTypeforNextRun) {
    setVmDevices(vm.getStaticData());
    Map<Guid, VmDevice> vmManagedDeviceMap = vm.getManagedVmDeviceMap();
    List<VmDeviceUpdate> fieldList = vmHandler.getVmDevicesFieldsToUpdateOnNextRun(vm.getId(), vm.getStatus(), objectWithEditableDeviceFields);
    // Add the enabled devices and remove the disabled ones
    for (VmDeviceUpdate update : fieldList) {
        if (update.isEnable()) {
            VmDevice device;
            if (update.getDevice() == null) {
                device = new VmDevice(new VmDeviceId(Guid.newGuid(), vm.getId()), update.getGeneralType(), update.getType().getName(), "", Collections.emptyMap(), true, true, update.isReadOnly(), "", null, null, null);
            } else {
                device = update.getDevice();
                if (device.getVmId() == null) {
                    device.setVmId(vm.getId());
                }
                if (device.getDeviceId() == null) {
                    if (device.getType() == VmDeviceGeneralType.RNG) {
                        // only one RNG device is allowed per VM
                        VmDevice rng = VmDeviceCommonUtils.findVmDeviceByType(vmManagedDeviceMap, update.getType());
                        device.setDeviceId(rng != null ? rng.getDeviceId() : Guid.newGuid());
                    } else {
                        device.setDeviceId(Guid.newGuid());
                    }
                }
            }
            vmManagedDeviceMap.put(device.getDeviceId(), device);
        } else {
            VmDevice device;
            if (update.getType() != VmDeviceType.UNKNOWN) {
                device = VmDeviceCommonUtils.findVmDeviceByType(vmManagedDeviceMap, update.getType());
            } else {
                device = VmDeviceCommonUtils.findVmDeviceByGeneralType(vmManagedDeviceMap, update.getGeneralType());
            }
            if (device != null) {
                vmManagedDeviceMap.remove(device.getDeviceId());
            }
        }
    }
    // as all other devices will be done
    if (vmVideoDeviceTypeforNextRun == DisplayType.none) {
        vmManagedDeviceMap = vmManagedDeviceMap.entrySet().stream().filter(entry -> !entry.getValue().getType().equals(VmDeviceGeneralType.VIDEO)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    } else if (vm.getDefaultDisplayType() == DisplayType.none) {
        VmDevice videoDevice = new VmDevice(new VmDeviceId(Guid.newGuid(), vm.getId()), VmDeviceGeneralType.VIDEO, vmVideoDeviceTypeforNextRun.toString(), "", Collections.emptyMap(), true, true, false, "", null, null, null);
        vmManagedDeviceMap.put(videoDevice.getDeviceId(), videoDevice);
    }
    return vmManagedDeviceMap;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceUpdate(org.ovirt.engine.core.common.utils.VmDeviceUpdate) Guid(org.ovirt.engine.core.compat.Guid) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 73 with VmDeviceId

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

the class VmDeviceUtils method enableNormalUsb.

private void enableNormalUsb(VmBase vmBase, ChipsetType chipset) {
    final UsbControllerModel controllerModel = getUsbControllerModel(vmBase, chipset);
    if (controllerModel == null) {
        return;
    }
    addManagedDevice(new VmDeviceId(Guid.newGuid(), vmBase.getId()), VmDeviceGeneralType.CONTROLLER, VmDeviceType.USB, createUsbControllerSpecParams(controllerModel.libvirtName, 0), true, false);
}
Also used : UsbControllerModel(org.ovirt.engine.core.common.businessentities.UsbControllerModel) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 74 with VmDeviceId

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

the class VmValidator method populateDisksWithVmData.

private void populateDisksWithVmData(Collection<? extends Disk> disks, Guid vmId) {
    for (Disk disk : disks) {
        DiskVmElement dve = getDiskVmElementDao().get(new VmDeviceId(disk.getId(), vmId));
        disk.setDiskVmElements(Collections.singletonList(dve));
    }
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 75 with VmDeviceId

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

the class NewDiskModel method initialize.

@Override
public void initialize() {
    super.initialize();
    setDiskVmElement(new DiskVmElement(new VmDeviceId(null, getIsFloating() ? null : getVm().getId())));
    if (!getIsFloating()) {
        if (getIsBootable().getIsChangable()) {
            getIsBootable().setEntity(true);
        }
        updateSuggestedDiskAliasFromServer();
        getIsPlugged().setIsAvailable(true);
    } else {
        // Read only disk can be created only in the scope of VM.
        getIsReadOnly().setIsAvailable(false);
        getIsPlugged().setEntity(false);
        getIsBootable().setIsAvailable(false);
        getDiskInterface().setIsAvailable(false);
        getPassDiscard().setIsAvailable(false);
        // set using scsi reservation to be invisible
        getIsUsingScsiReservation().setIsAvailable(false);
        getIsUsingScsiReservation().setEntity(false);
    }
    getSizeExtend().setIsAvailable(false);
}
Also used : DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Aggregations

VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)75 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)40 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)21 Guid (org.ovirt.engine.core.compat.Guid)19 HashMap (java.util.HashMap)13 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)12 Test (org.junit.Test)10 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)9 ArrayList (java.util.ArrayList)7 Map (java.util.Map)5 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)5 VM (org.ovirt.engine.core.common.businessentities.VM)5 VmPayload (org.ovirt.engine.core.common.businessentities.VmPayload)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)4 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)3 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)3