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();
}
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();
}));
}
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);
}
}
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));
}
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));
}
Aggregations