use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class CommonVmPoolCommand method buildAddVmParameters.
private AddVmParameters buildAddVmParameters(String vmName) {
VmStatic currVm = new VmStatic(getParameters().getVmStaticData());
currVm.setName(vmName);
currVm.setStateless(!getVmPool().isStateful());
if (getParameters().getVmLargeIcon() != null) {
final VmIconIdSizePair iconIds = iconUtils.ensureIconPairInDatabase(getParameters().getVmLargeIcon());
currVm.setSmallIconId(iconIds.getSmall());
currVm.setLargeIconId(iconIds.getLarge());
}
AddVmParameters parameters = new AddVmParameters(currVm);
parameters.setPoolId(getVmPool().getVmPoolId());
if (getVmPool().isAutoStorageSelect()) {
parameters.setDiskInfoDestinationMap(autoSelectTargetDomainAndVolumeFormat());
} else {
parameters.setDiskInfoDestinationMap(diskInfoDestinationMap);
}
if (StringUtils.isEmpty(getParameters().getSessionId())) {
parameters.setParametersCurrentUser(getCurrentUser());
} else {
parameters.setSessionId(getParameters().getSessionId());
}
parameters.setParentCommand(getActionType());
parameters.setParentParameters(getParameters());
// check if device is enabled or we need to override it to true
parameters.setSoundDeviceEnabled(Boolean.TRUE.equals(getParameters().isSoundDeviceEnabled()) || vmDeviceUtils.shouldOverrideSoundDevice(getParameters().getVmStaticData(), getEffectiveCompatibilityVersion(), getParameters().isSoundDeviceEnabled()));
parameters.setConsoleEnabled(getParameters().isConsoleEnabled());
parameters.setVirtioScsiEnabled(getParameters().isVirtioScsiEnabled());
parameters.setBalloonEnabled(getParameters().isBalloonEnabled());
parameters.setEndProcedure(EndProcedure.COMMAND_MANAGED);
VmRngDevice rngDevice = getParameters().getRngDevice();
if (rngDevice != null) {
parameters.setUpdateRngDevice(true);
parameters.setRngDevice(rngDevice);
}
parameters.getGraphicsDevices().putAll(getParameters().getGraphicsDevices());
return parameters;
}
use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class HotUnplugMemoryCommand method updateNextRunConfiguration.
private void updateNextRunConfiguration(int memoryAfterHotUnplugMb, int minMemoryAfterHotUnplugMb) {
final VmStatic nextRunConfigurationStatic = getNextRunConfiguration();
if (nextRunConfigurationStatic == null) {
return;
}
// Update next run snapshot only if old memory state matches old next run snapshot state
if (getVm().getMemSizeMb() != nextRunConfigurationStatic.getMemSizeMb()) {
return;
}
nextRunConfigurationStatic.setMemSizeMb(memoryAfterHotUnplugMb);
nextRunConfigurationStatic.setMinAllocatedMem(minMemoryAfterHotUnplugMb);
TransactionSupport.executeInNewTransaction(() -> {
vmHandler.createNextRunSnapshot(getVm(), nextRunConfigurationStatic, null, getCompensationContext());
return null;
});
}
use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class GetVmChangedFieldsForNextRunQuery method executeQueryCommand.
@Override
protected void executeQueryCommand() {
VM srcVm = getParameters().getOriginal();
VM dstVm = getParameters().getUpdated();
VmStatic srcStatic = srcVm.getStaticData();
VmStatic dstStatic = dstVm.getStaticData();
// Copy creationDate to ignore it, because it is never changed by user.
// Without this creationDate will always show change in milliseconds,
// because creationDate is saved without milliseconds in OVF, but
// with milliseconds in the DB.
dstStatic.setCreationDate(srcStatic.getCreationDate());
// so it is not needed to include them into changed fields list.
if (VmCommonUtils.isCpusToBeHotpluggedOrUnplugged(srcVm, dstVm)) {
dstStatic.setNumOfSockets(srcStatic.getNumOfSockets());
}
if (VmCommonUtils.isMemoryToBeHotplugged(srcVm, dstVm)) {
dstStatic.setMemSizeMb(srcStatic.getMemSizeMb());
dstStatic.setMinAllocatedMem(srcStatic.getMinAllocatedMem());
}
if (VmCommonUtils.isVmLeaseToBeHotPluggedOrUnplugged(srcVm, dstVm)) {
dstStatic.setLeaseStorageDomainId(srcStatic.getLeaseStorageDomainId());
}
VmPropertiesUtils vmPropertiesUtils = SimpleDependencyInjector.getInstance().get(VmPropertiesUtils.class);
vmPropertiesUtils.separateCustomPropertiesToUserAndPredefined(srcVm.getCompatibilityVersion(), srcStatic);
vmPropertiesUtils.separateCustomPropertiesToUserAndPredefined(dstVm.getCompatibilityVersion(), dstStatic);
Set<String> result = new HashSet<>(vmHandler.getChangedFieldsForStatus(srcStatic, dstStatic, VMStatus.Up));
for (VmDeviceUpdate device : vmHandler.getVmDevicesFieldsToUpdateOnNextRun(srcVm.getId(), VMStatus.Up, getParameters().getUpdateVmParameters())) {
if (!device.getName().isEmpty()) {
result.add(device.getName());
} else {
switch(device.getType()) {
case UNKNOWN:
case VIRTIO:
result.add(device.getGeneralType().name());
break;
default:
result.add(device.getType().getName());
break;
}
}
}
setReturnValue(new ArrayList<>(result));
}
use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class GetVmDataByPoolIdQuery method executeQueryCommand.
@Override
protected void executeQueryCommand() {
VM vm = vmPoolDao.getVmDataFromPoolByPoolGuid(getParameters().getId(), getUserID(), getParameters().isFiltered());
if (vm != null) {
boolean isLatestLoad = vm.isUseLatestVersion();
boolean loadTemplateData = false;
Guid vmtGuid = vm.getVmtGuid();
if (vm.isNextRunConfigurationExists()) {
QueryReturnValue nextRunRet = backend.runInternalQuery(QueryType.GetVmNextRunConfiguration, new IdQueryParameters(vm.getId()));
if (nextRunRet != null) {
VM nextRunVm = nextRunRet.getReturnValue();
if (nextRunVm != null) {
// template version was changed -> load data from template
isLatestLoad = nextRunVm.isUseLatestVersion();
vmtGuid = nextRunVm.getVmtGuid();
loadTemplateData = true;
}
}
}
VmTemplate templateData = null;
if (isLatestLoad) {
QueryReturnValue latestRet = backend.runInternalQuery(QueryType.GetLatestTemplateInChain, new IdQueryParameters(vmtGuid));
if (latestRet != null) {
templateData = latestRet.getReturnValue();
}
} else if (loadTemplateData) {
QueryReturnValue templateRet = backend.runInternalQuery(QueryType.GetVmTemplate, new GetVmTemplateParameters(vmtGuid));
if (templateRet != null) {
templateData = templateRet.getReturnValue();
}
}
if (templateData != null) {
VmStatic temp = vm.getStaticData();
temp.setVmtGuid(vmtGuid);
temp.setUseLatestVersion(isLatestLoad);
VmHandler.copyData(templateData, temp);
vm.setStaticData(temp);
}
vmHandler.updateDisksFromDb(vm);
vmHandler.updateVmInitFromDB(vm.getStaticData(), true);
}
getQueryReturnValue().setReturnValue(vm);
}
use of org.ovirt.engine.core.common.businessentities.VmStatic in project ovirt-engine by oVirt.
the class EditAffinityGroupCommandTest method setup.
@Before
public void setup() {
AffinityGroup affinityGroup2 = new AffinityGroup();
affinityGroup2.setClusterId(clusterId);
affinityGroup2.setName(AFFINITY_GROUP_NAME + "##");
doReturn(affinityGroup2).when(command).getAffinityGroup();
doReturn(new Cluster()).when(command).getCluster();
VmStatic vmStatic = new VmStatic();
vmStatic.setClusterId(clusterId);
doReturn(Collections.singletonList(vmStatic)).when(vmStaticDao).getByIds(any());
doReturn(clusterId).when(command).getClusterId();
}
Aggregations