Search in sources :

Example 21 with VmBase

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

the class ExistingPoolInstanceTypeManager method getSource.

@Override
protected VmBase getSource() {
    boolean customInstanceTypeUsed = getModel().getInstanceTypes() != null && getModel().getInstanceTypes().getSelectedItem() instanceof CustomInstanceType;
    if (!customInstanceTypeUsed) {
        return (VmBase) getModel().getInstanceTypes().getSelectedItem();
    }
    if (getModel().getTemplateWithVersion() == null || getModel().getTemplateWithVersion().getSelectedItem() == null || getModel().getTemplateWithVersion().getSelectedItem().getTemplateVersion() == null) {
        return pool.getStaticData();
    }
    VmTemplate template = getModel().getTemplateWithVersion().getSelectedItem().getTemplateVersion();
    boolean isLatestPropertyChanged = pool.isUseLatestVersion() != (template instanceof LatestVmTemplate);
    // template ID changed but latest is not set, as it would cause false-positives
    boolean isTemplateIdChangedSinceInit = !pool.getVmtGuid().equals(template.getId()) && !pool.isUseLatestVersion();
    if (isTemplateIdChangedSinceInit || isLatestPropertyChanged) {
        return template;
    }
    return pool.getStaticData();
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate)

Example 22 with VmBase

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

the class InstanceTypeManager method updateDefaultDisplayRelatedFields.

protected void updateDefaultDisplayRelatedFields(final VmBase vmBase) {
    // Update display protocol selected item
    final Collection<DisplayType> displayTypes = model.getDisplayType().getItems();
    if (displayTypes == null || displayTypes.isEmpty()) {
        return;
    }
    // graphics
    Frontend.getInstance().runQuery(QueryType.GetGraphicsDevices, new IdQueryParameters(vmBase.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
        deactivate();
        List<GraphicsDevice> graphicsDevices = returnValue.getReturnValue();
        model.getIsHeadlessModeEnabled().setEntity(vmBase.getDefaultDisplayType() == DisplayType.none);
        // select display protocol
        // first by default
        DisplayType displayProtocol = displayTypes.iterator().next();
        if (displayTypes.contains(vmBase.getDefaultDisplayType())) {
            // if display types contain DT of a vm, pick this one
            displayProtocol = vmBase.getDefaultDisplayType();
        }
        maybeSetSelectedItem(model.getDisplayType(), displayProtocol);
        Set<GraphicsType> graphicsTypes = new HashSet<>();
        for (GraphicsDevice graphicsDevice : graphicsDevices) {
            graphicsTypes.add(graphicsDevice.getGraphicsType());
        }
        UnitVmModel.GraphicsTypes selected = UnitVmModel.GraphicsTypes.fromGraphicsTypes(graphicsTypes);
        if (selected != null && getModel().getGraphicsType().getItems().contains(selected)) {
            maybeSetSelectedItem(getModel().getGraphicsType(), selected);
        }
        maybeSetSelectedItem(model.getNumOfMonitors(), vmBase.getNumOfMonitors());
        maybeSetSelectedItem(model.getUsbPolicy(), vmBase.getUsbPolicy());
        maybeSetEntity(model.getIsSmartcardEnabled(), vmBase.isSmartcardEnabled());
        maybeSetSingleQxlPci(vmBase);
        activate();
    }));
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) QueryType(org.ovirt.engine.core.common.queries.QueryType) Guid(org.ovirt.engine.core.compat.Guid) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) PriorityUtil(org.ovirt.engine.ui.uicommonweb.models.vms.PriorityUtil) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) Event(org.ovirt.engine.ui.uicompat.Event) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) HashSet(java.util.HashSet) Frontend(org.ovirt.engine.ui.frontend.Frontend) VmWatchdogType(org.ovirt.engine.core.common.businessentities.VmWatchdogType) UnitVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) VirtioScsiUtil(org.ovirt.engine.ui.uicommonweb.models.vms.VirtioScsiUtil) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) HashSet(java.util.HashSet) Set(java.util.Set) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) ArrayList(java.util.ArrayList) List(java.util.List)

Example 23 with VmBase

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

the class InstanceTypeManager method updateRngDevice.

protected void updateRngDevice(final VmBase vmBase) {
    if (model.getIsRngEnabled().getIsChangable() && model.getIsRngEnabled().getIsAvailable()) {
        if (!isNextRunConfigurationExists()) {
            Frontend.getInstance().runQuery(QueryType.GetRngDevice, new IdQueryParameters(vmBase.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
                deactivate();
                List<VmDevice> rngDevices = returnValue.getReturnValue();
                getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty());
                if (!rngDevices.isEmpty()) {
                    VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0));
                    rngDevice.updateSourceByVersion(getModel().getCompatibilityVersion());
                    getModel().setRngDevice(rngDevice);
                }
                activate();
                updateVirtioScsi(vmBase);
            }));
        } else {
            deactivate();
            VmDevice rngDevice = VmDeviceCommonUtils.findVmDeviceByGeneralType(vmBase.getManagedDeviceMap(), VmDeviceGeneralType.RNG);
            getModel().getIsRngEnabled().setEntity(rngDevice != null);
            if (rngDevice != null) {
                getModel().setRngDevice(new VmRngDevice(rngDevice));
            }
            activate();
            updateVirtioScsi(vmBase);
        }
    } else {
        updateVirtioScsi(vmBase);
    }
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) QueryType(org.ovirt.engine.core.common.queries.QueryType) Guid(org.ovirt.engine.core.compat.Guid) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) PriorityUtil(org.ovirt.engine.ui.uicommonweb.models.vms.PriorityUtil) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) Event(org.ovirt.engine.ui.uicompat.Event) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) HashSet(java.util.HashSet) Frontend(org.ovirt.engine.ui.frontend.Frontend) VmWatchdogType(org.ovirt.engine.core.common.businessentities.VmWatchdogType) UnitVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) VirtioScsiUtil(org.ovirt.engine.ui.uicommonweb.models.vms.VirtioScsiUtil) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 24 with VmBase

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

the class StorageDomainValidatorTest method invalidRunningVmsForBackupDomain.

@Test
public void invalidRunningVmsForBackupDomain() {
    // VM1
    VM vm1 = new VM();
    vm1.setName("firstVM");
    Map<Guid, Disk> attachedDisksForVm1 = new HashMap<>();
    DiskImage diskVm1 = new DiskImage();
    diskVm1.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
    diskVm1.setPlugged(true);
    attachedDisksForVm1.put(Guid.newGuid(), diskVm1);
    vm1.setDiskMap(attachedDisksForVm1);
    // VM2
    VM vm2 = new VM();
    vm2.setName("secondVM");
    Map<Guid, Disk> attachedDisksForVm2 = new HashMap<>();
    DiskImage diskVm2 = new DiskImage();
    diskVm2.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
    diskVm2.setPlugged(true);
    attachedDisksForVm2.put(Guid.newGuid(), diskVm2);
    vm2.setDiskMap(attachedDisksForVm2);
    List<VM> runningVMs = new ArrayList<>();
    runningVMs.add(vm1);
    runningVMs.add(vm2);
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(runningVMs);
    QueryReturnValue ret = new QueryReturnValue();
    ret.setReturnValue(new ArrayList<VmBase>());
    ret.setSucceeded(true);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), failsWith(EngineMessage.ACTION_TYPE_FAILED_RUNNING_VM_OR_VM_LEASES_PRESENT_ON_STORAGE_DOMAIN));
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 25 with VmBase

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

the class StorageDomainValidatorTest method invalidVmLeasesForBackupDomain.

@Test
public void invalidVmLeasesForBackupDomain() {
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(Collections.EMPTY_LIST);
    QueryReturnValue ret = new QueryReturnValue();
    List<VmBase> vmLeases = new ArrayList<>();
    VM vm1 = new VM();
    vm1.setName("firstVM");
    vm1.setStatus(VMStatus.PoweringUp);
    vmLeases.add(vm1.getStaticData());
    ret.setReturnValue(vmLeases);
    ret.setSucceeded(true);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    when(vmDynamicDao.get(vm1.getId())).thenReturn(vm1.getDynamicData());
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), failsWith(EngineMessage.ACTION_TYPE_FAILED_RUNNING_VM_OR_VM_LEASES_PRESENT_ON_STORAGE_DOMAIN));
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

VmBase (org.ovirt.engine.core.common.businessentities.VmBase)38 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)15 Guid (org.ovirt.engine.core.compat.Guid)11 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)9 VM (org.ovirt.engine.core.common.businessentities.VM)8 HashSet (java.util.HashSet)7 List (java.util.List)7 Set (java.util.Set)7 HashMap (java.util.HashMap)6 Collection (java.util.Collection)5 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)5 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)5 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)5 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)5 Collections (java.util.Collections)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4