Search in sources :

Example 76 with VmStatic

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

the class VmManagementCommandBase method validatePinningAndMigration.

boolean validatePinningAndMigration() {
    final boolean cpuPinMigrationEnabled = Boolean.TRUE.equals(Config.<Boolean>getValue(ConfigValues.CpuPinMigrationEnabled));
    VmStatic vmStaticData = getParameters().getVmStaticData();
    if (!cpuPinMigrationEnabled && (vmStaticData.getMigrationSupport() == MigrationSupport.MIGRATABLE || vmStaticData.getMigrationSupport() == MigrationSupport.IMPLICITLY_NON_MIGRATABLE) && StringUtils.isNotEmpty(getParameters().getVm().getCpuPinning())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_CANNOT_BE_PINNED_TO_CPU_AND_MIGRATABLE);
    }
    return true;
}
Also used : VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Example 77 with VmStatic

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

the class UpdateClusterCommand method updateVms.

private boolean updateVms() {
    for (VmStatic vm : vmsLockedForUpdate) {
        VmManagementParametersBase updateParams = new VmManagementParametersBase(vm);
        /*
            Locking by UpdateVmCommand is disabled since VMs are already locked in #getExclusiveLocks method.
            This logic relies on assumption that UpdateVmCommand locks exactly only updated VM.
             */
        updateParams.setLockProperties(LockProperties.create(LockProperties.Scope.None));
        updateParams.setClusterLevelChangeFromVersion(oldCluster.getCompatibilityVersion());
        upgradeGraphicsDevices(vm, updateParams);
        updateResumeBehavior(vm);
        updateRngDeviceIfNecessary(vm.getId(), vm.getCustomCompatibilityVersion(), updateParams);
        ActionReturnValue result = runInternalAction(ActionType.UpdateVm, updateParams, cloneContextAndDetachFromParent());
        if (!result.getSucceeded()) {
            List<String> params = new ArrayList<>();
            params.add("$action Update");
            params.add("$type VM");
            params.add(parseErrorMessage(result.getValidationMessages()));
            List<String> messages = Backend.getInstance().getErrorsTranslator().translateErrorText(params);
            failedUpgradeEntities.put(vm.getName(), getFailedMessage(messages));
        }
    }
    return true;
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) VmManagementParametersBase(org.ovirt.engine.core.common.action.VmManagementParametersBase)

Example 78 with VmStatic

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

the class AddVmCommand method updateVmObject.

/**
 * This method override vm values with the instance type values
 * in case instance type is selected for this vm
 */
private void updateVmObject() {
    updateParametersVmFromInstanceType();
    // set vm interface source id to be the instance type, vm interface are taken from it
    if (getInstanceType() != null) {
        vmInterfacesSourceId = getInstanceTypeId();
    }
    VmStatic vmStatic = getParameters().getVmStaticData();
    ImageType imageType = getImageType();
    if (imageType != null) {
        vmStatic.setOsId(imageType.getOsId());
        vmStatic.setIsoPath(imageType.getIsoPath());
        vmStatic.setInitrdUrl(imageType.getInitrdUrl());
        vmStatic.setKernelUrl(imageType.getKernelUrl());
        vmStatic.setKernelParams(imageType.getKernelParams());
        // set vm disks source to be the image type, vm disks are taken from it
        vmDisksSource = (VmTemplate) imageType;
    }
    // Choose a proper default OS according to the cluster architecture
    if (getParameters().getVmStaticData().getOsId() == OsRepository.AUTO_SELECT_OS) {
        if (getCluster().getArchitecture() != ArchitectureType.undefined) {
            Integer defaultOs = osRepository.getDefaultOSes().get(getCluster().getArchitecture());
            getParameters().getVmStaticData().setOsId(defaultOs);
        }
    }
    vmHandler.autoSelectUsbPolicy(getParameters().getVmStaticData());
    // Choose a proper default display type according to the cluster architecture
    vmHandler.autoSelectDefaultDisplayType(vmDevicesSourceId, getParameters().getVmStaticData(), getCluster(), getParameters().getGraphicsDevices());
    // If not set by user, choose proper graphics device according to the cluster architecture
    vmHandler.autoSelectGraphicsDevice(vmDevicesSourceId, getParameters().getVmStaticData(), getCluster(), getParameters().getGraphicsDevices(), getEffectiveCompatibilityVersion());
}
Also used : VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) ImageType(org.ovirt.engine.core.common.businessentities.ImageType)

Example 79 with VmStatic

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

the class AddVmTemplateCommand method init.

@Override
protected void init() {
    if (Guid.isNullOrEmpty(getParameters().getVmTemplateId())) {
        getParameters().setVmTemplateId(Guid.newGuid());
    }
    setVmTemplateId(getParameters().getVmTemplateId());
    getParameters().setEntityInfo(new EntityInfo(VdcObjectType.VmTemplate, getVmTemplateId()));
    setVmTemplateName(getParameters().getName());
    VmStatic masterVm = getParameters().getMasterVm();
    if (masterVm != null) {
        setVmId(masterVm.getId());
        setClusterId(masterVm.getClusterId());
        // API backward compatibility
        if (getVmDeviceUtils().shouldOverrideSoundDevice(masterVm, getMasterVmCompatibilityVersion(), getParameters().isSoundDeviceEnabled())) {
            getParameters().setSoundDeviceEnabled(true);
        }
        if (getParameters().isSoundDeviceEnabled() == null) {
            getParameters().setSoundDeviceEnabled(false);
        }
        if (getParameters().isConsoleEnabled() == null) {
            getParameters().setConsoleEnabled(false);
        }
        vmHandler.updateDefaultTimeZone(masterVm);
        vmHandler.autoSelectUsbPolicy(masterVm);
        vmHandler.autoSelectDefaultDisplayType(getVmId(), masterVm, getCluster(), getParameters().getGraphicsDevices());
        vmHandler.autoSelectGraphicsDevice(getVmId(), masterVm, getCluster(), getParameters().getGraphicsDevices(), getMasterVmCompatibilityVersion());
        vmHandler.autoSelectResumeBehavior(masterVm, getCluster());
        separateCustomProperties(masterVm);
    }
    if (getVm() != null) {
        updateVmDevices();
        images.addAll(getVmDisksFromDB());
        setStoragePoolId(getVm().getStoragePoolId());
        isVmInDb = true;
    } else if (getCluster() != null && masterVm != null) {
        VM vm = new VM(masterVm, new VmDynamic(), null);
        vm.setClusterCompatibilityVersion(getCluster().getCompatibilityVersion());
        setVm(vm);
        setStoragePoolId(getCluster().getStoragePoolId());
    }
    updateDiskInfoDestinationMap();
    generateTargetDiskIds();
    getParameters().setUseCinderCommandCallback(!getCinderDisks().isEmpty());
}
Also used : VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) VM(org.ovirt.engine.core.common.businessentities.VM) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Example 80 with VmStatic

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

the class AddUnmanagedVmsCommand method convertVm.

// Visible for testing
protected void convertVm(int defaultOsId, DisplayType defaultDisplayType, long fetchTime, Map<String, Object> vmInfo) {
    Guid vmId = Guid.createGuidFromString((String) vmInfo.get(VdsProperties.vm_guid));
    String vmNameOnHost = (String) vmInfo.get(VdsProperties.vm_name);
    if (isHostedEngineVm(vmId, vmNameOnHost)) {
        // its a hosted engine VM -> import it
        importHostedEngineVm(vmInfo);
        return;
    }
    VmStatic vmStatic = new VmStatic();
    vmStatic.setId(vmId);
    vmStatic.setCreationDate(new Date());
    vmStatic.setClusterId(getClusterId());
    vmStatic.setName(String.format(EXTERNAL_VM_NAME_FORMAT, vmNameOnHost));
    vmStatic.setOrigin(OriginType.EXTERNAL);
    vmStatic.setNumOfSockets(VdsBrokerObjectsBuilder.parseIntVdsProperty(vmInfo.get(VdsProperties.num_of_cpus)));
    vmStatic.setMemSizeMb(VdsBrokerObjectsBuilder.parseIntVdsProperty(vmInfo.get(VdsProperties.mem_size_mb)));
    // VMs started before engine 3.6 may not have 'maxMemory' set
    final int maxMemorySize = vmInfo.get(VdsProperties.maxMemSize) != null ? VdsBrokerObjectsBuilder.parseIntVdsProperty(vmInfo.get(VdsProperties.maxMemSize)) : vmStatic.getMemSizeMb();
    vmStatic.setMaxMemorySizeMb(maxMemorySize);
    vmStatic.setSingleQxlPci(false);
    setOsId(vmStatic, (String) vmInfo.get(VdsProperties.guest_os), defaultOsId);
    setDisplayType(vmStatic, (String) vmInfo.get(VdsProperties.displayType), defaultDisplayType);
    addExternallyManagedVm(vmStatic);
    addDevices(vmInfo, fetchTime);
    log.info("Importing VM '{}' as '{}', as it is running on the on Host, but does not exist in the engine.", vmNameOnHost, vmStatic.getName());
}
Also used : VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Guid(org.ovirt.engine.core.compat.Guid) Date(java.util.Date)

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