Search in sources :

Example 81 with VmStatic

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;
}
Also used : VmIconIdSizePair(org.ovirt.engine.core.common.queries.VmIconIdSizePair) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) AddVmParameters(org.ovirt.engine.core.common.action.AddVmParameters) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 82 with VmStatic

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;
    });
}
Also used : VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Example 83 with VmStatic

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));
}
Also used : VmDeviceUpdate(org.ovirt.engine.core.common.utils.VmDeviceUpdate) VM(org.ovirt.engine.core.common.businessentities.VM) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) VmPropertiesUtils(org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils) HashSet(java.util.HashSet)

Example 84 with VmStatic

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);
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GetVmTemplateParameters(org.ovirt.engine.core.common.queries.GetVmTemplateParameters) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VM(org.ovirt.engine.core.common.businessentities.VM) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Guid(org.ovirt.engine.core.compat.Guid)

Example 85 with VmStatic

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();
}
Also used : Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) Before(org.junit.Before)

Aggregations

VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)87 Test (org.junit.Test)26 Guid (org.ovirt.engine.core.compat.Guid)15 VM (org.ovirt.engine.core.common.businessentities.VM)11 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)9 VmDynamic (org.ovirt.engine.core.common.businessentities.VmDynamic)8 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)8 Label (org.ovirt.engine.core.common.businessentities.Label)7 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Response (javax.ws.rs.core.Response)4 AddVmTemplateParameters (org.ovirt.engine.core.common.action.AddVmTemplateParameters)4 LabelBuilder (org.ovirt.engine.core.common.businessentities.LabelBuilder)4 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)4 VmStatistics (org.ovirt.engine.core.common.businessentities.VmStatistics)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 PostConstruct (javax.annotation.PostConstruct)3 Before (org.junit.Before)3