Search in sources :

Example 46 with VmDevice

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

the class AddUnmanagedVmsCommand method importHostedEngineVm.

// Visible for testing
protected void importHostedEngineVm(Map<String, Object> vmStruct) {
    VM vm = VdsBrokerObjectsBuilder.buildVmsDataFromExternalProvider(vmStruct);
    if (vm != null) {
        vm.setImages(VdsBrokerObjectsBuilder.buildDiskImagesFromDevices(vmStruct, vm.getId()));
        vm.setInterfaces(VdsBrokerObjectsBuilder.buildVmNetworkInterfacesFromDevices(vmStruct));
        for (DiskImage diskImage : vm.getImages()) {
            vm.getDiskMap().put(diskImage.getId(), diskImage);
        }
        vm.setClusterId(getClusterId());
        vm.setRunOnVds(getVdsId());
        List<GraphicsDevice> graphicsDevices = extractGraphicsDevices(vm.getId(), (Object[]) vmStruct.get(VdsProperties.Devices));
        if (graphicsDevices.size() == 1 && VmDeviceType.valueOf(graphicsDevices.get(0).getDevice().toUpperCase()) == VmDeviceType.VNC) {
            vm.setDefaultDisplayType(DisplayType.vga);
        } else {
            vm.setDefaultDisplayType(DisplayType.qxl);
        }
        // HE VM does not support that feature, disable it
        vm.setSingleQxlPci(false);
        for (GraphicsDevice graphicsDevice : graphicsDevices) {
            vm.getManagedVmDeviceMap().put(graphicsDevice.getDeviceId(), graphicsDevice);
        }
        VmDevice consoleDevice = VdsBrokerObjectsBuilder.buildConsoleDevice(vmStruct, vm.getId());
        if (consoleDevice != null) {
            vm.getManagedVmDeviceMap().put(consoleDevice.getDeviceId(), consoleDevice);
        }
        importHostedEngineVm(vm);
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VM(org.ovirt.engine.core.common.businessentities.VM) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 47 with VmDevice

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

the class AddWatchdogCommand method executeCommand.

@Override
protected void executeCommand() {
    VmDevice watchdogDevice = vmDeviceUtils.addWatchdogDevice(getParameters().getId(), getSpecParams());
    setSucceeded(true);
    setActionReturnValue(watchdogDevice.getId().getDeviceId());
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Example 48 with VmDevice

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

the class CloneVmCommand method setupParameters.

private void setupParameters() {
    setVmId(Guid.newGuid());
    VM vmToClone = getVm();
    getParameters().setNewVmGuid(getVmId());
    getParameters().setVm(vmToClone);
    List<VmDevice> devices = vmDeviceDao.getVmDeviceByVmId(oldVmId);
    getParameters().setSoundDeviceEnabled(containsDeviceWithType(devices, VmDeviceGeneralType.SOUND));
    getParameters().setConsoleEnabled(containsDeviceWithType(devices, VmDeviceGeneralType.CONSOLE));
    getParameters().setVirtioScsiEnabled(containsDeviceWithType(devices, VmDeviceGeneralType.CONTROLLER, VmDeviceType.VIRTIOSCSI));
    getParameters().setBalloonEnabled(containsDeviceWithType(devices, VmDeviceGeneralType.BALLOON));
    setGraphicsDevices(devices);
    QueryReturnValue watchdogs = runInternalQuery(QueryType.GetWatchdog, new IdQueryParameters(oldVmId));
    if (!((List<VmWatchdog>) watchdogs.getReturnValue()).isEmpty()) {
        VmWatchdog watchdog = ((List<VmWatchdog>) watchdogs.getReturnValue()).iterator().next();
        getParameters().setUpdateWatchdog(true);
        getParameters().setWatchdog(watchdog);
    }
    fillDisksToParameters();
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VM(org.ovirt.engine.core.common.businessentities.VM) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog)

Example 49 with VmDevice

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

the class AddGraphicsAndVideoDevicesCommand method executeCommand.

@Override
protected void executeCommand() {
    VmDevice graphicsDev = getParameters().getDev();
    if (graphicsDev.getDeviceId() == null) {
        graphicsDev.setDeviceId(Guid.newGuid());
    }
    vmDeviceDao.save(graphicsDev);
    if (getPrevDevices().isEmpty()) {
        if (getParameters().isVm()) {
            setVmToNonHeadlessMode();
        } else {
            setTemplateToNonHeadlessMode();
        }
    }
    setSucceeded(true);
    setActionReturnValue(graphicsDev.getId().getDeviceId());
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Example 50 with VmDevice

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

the class VmDeviceCommonUtils method sortInterfacesByName.

private static List<VmDevice> sortInterfacesByName(List<VmDevice> pluggedInterfaces, List<VmNetworkInterface> interfaces) {
    if (pluggedInterfaces.size() < 2) {
        return pluggedInterfaces;
    }
    final Map<Guid, String> deviceIdToIfaceName = new HashMap<>();
    for (VmNetworkInterface iface : interfaces) {
        deviceIdToIfaceName.put(iface.getId(), iface.getName());
    }
    Collections.sort(pluggedInterfaces, Comparator.comparing(d -> deviceIdToIfaceName.get(d.getId().getDeviceId())));
    return pluggedInterfaces;
}
Also used : GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) HashMap(java.util.HashMap) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) BootSequence(org.ovirt.engine.core.common.businessentities.BootSequence) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) List(java.util.List) VM(org.ovirt.engine.core.common.businessentities.VM) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Optional(java.util.Optional) Comparator(java.util.Comparator) LinkedList(java.util.LinkedList) Collections(java.util.Collections) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) Config(org.ovirt.engine.core.common.config.Config) HashMap(java.util.HashMap) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid)

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