Search in sources :

Example 21 with VmStatic

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

the class BackendVmResourceTest method testCloneVm.

@Test
public void testCloneVm() throws Exception {
    org.ovirt.engine.core.common.businessentities.VM mockedVm = mock(org.ovirt.engine.core.common.businessentities.VM.class);
    VmStatic vmStatic = mock(VmStatic.class);
    when(mockedVm.getStaticData()).thenReturn(vmStatic);
    setUpGetEntityExpectations(QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, mockedVm);
    setUriInfo(setUpActionExpectations(ActionType.CloneVm, CloneVmParameters.class, new String[] { "VmStaticData", "NewName" }, new Object[] { vmStatic, "someNewName" }));
    Action action = new Action();
    Vm vm = new Vm();
    vm.setName("someNewName");
    action.setVm(vm);
    Response response = resource.doClone(action);
    verifyActionResponse(response);
    Action actionResponse = (Action) response.getEntity();
    assertTrue(actionResponse.isSetStatus());
}
Also used : Response(javax.ws.rs.core.Response) Action(org.ovirt.engine.api.model.Action) Vm(org.ovirt.engine.api.model.Vm) CloneVmParameters(org.ovirt.engine.core.common.action.CloneVmParameters) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Test(org.junit.Test)

Example 22 with VmStatic

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

the class VdsEventListener method vdsUpEvent.

@Override
public boolean vdsUpEvent(final VDS vds) {
    HostStoragePoolParametersBase params = new HostStoragePoolParametersBase(vds);
    CommandContext commandContext = new CommandContext(new EngineContext()).withoutExecutionContext();
    commandContext.getExecutionContext().setJobRequired(true);
    boolean isSucceeded = backend.runInternalAction(ActionType.InitVdsOnUp, params, commandContext).getSucceeded();
    if (isSucceeded) {
        ThreadPoolUtil.execute(() -> {
            try {
                // migrate vms that its their default vds and failback
                // is on
                List<VmStatic> vmsToMigrate = vmStaticDao.getAllWithFailbackByVds(vds.getId());
                if (!vmsToMigrate.isEmpty()) {
                    CommandContext ctx = new CommandContext(new EngineContext());
                    ctx.getExecutionContext().setMonitored(true);
                    backend.runInternalMultipleActions(ActionType.MigrateVmToServer, new ArrayList<>(createMigrateVmToServerParametersList(vmsToMigrate, vds, null)), ctx);
                }
            } catch (RuntimeException e) {
                log.error("Failed to initialize Vds on up: {}", e.getMessage());
                log.error("Exception", e);
            }
        });
    }
    return isSucceeded;
}
Also used : HostStoragePoolParametersBase(org.ovirt.engine.core.common.action.HostStoragePoolParametersBase) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) EngineContext(org.ovirt.engine.core.bll.context.EngineContext) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Example 23 with VmStatic

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

the class BackendVmsResource method add.

@Override
public Response add(Vm vm) {
    validateParameters(vm, "cluster.id|name");
    validateIconParameters(vm);
    Response response = null;
    if (vm.isSetInitialization() && vm.getInitialization().isSetConfiguration()) {
        validateParameters(vm, "initialization.configuration.type", "initialization.configuration.data");
        response = importVmFromConfiguration(vm);
    } else {
        validateParameters(vm, "name");
        if (isCreateFromSnapshot(vm)) {
            validateSnapshotExistence(vm);
            response = createVmFromSnapshot(vm);
        } else {
            validateParameters(vm, "template.id|name");
            Cluster cluster = getCluster(vm);
            VmTemplate template = lookupTemplate(vm.getTemplate(), cluster.getStoragePoolId());
            VmStatic builtFromTemplate = VmMapper.map(template, null, cluster.getCompatibilityVersion());
            // since the template cpu_profile doesn't match cluster.
            if (!vm.isSetCpuProfile() && vm.isSetCluster() && !Objects.equals(Objects.toString(template.getClusterId(), null), vm.getCluster().getId())) {
                builtFromTemplate.setCpuProfileId(null);
            }
            VmStatic builtFromInstanceType = null;
            InstanceType instanceTypeEntity = null;
            if (vm.isSetInstanceType() && (vm.getInstanceType().isSetId() || vm.getInstanceType().isSetName())) {
                instanceTypeEntity = lookupInstance(vm.getInstanceType());
                builtFromInstanceType = VmMapper.map(instanceTypeEntity, builtFromTemplate, cluster.getCompatibilityVersion());
                builtFromInstanceType.setInstanceTypeId(instanceTypeEntity.getId());
            }
            VmStatic staticVm = getMapper(Vm.class, VmStatic.class).map(vm, builtFromInstanceType != null ? builtFromInstanceType : builtFromTemplate);
            if (namedCluster(vm)) {
                staticVm.setClusterId(cluster.getId());
            }
            updateMaxMemoryIfUnspecified(vm, staticVm);
            if (Guid.Empty.equals(template.getId()) && !vm.isSetOs()) {
                staticVm.setOsId(OsRepository.AUTO_SELECT_OS);
            }
            staticVm.setUsbPolicy(VmMapper.getUsbPolicyOnCreate(vm.getUsb()));
            if (!isFiltered() && vm.isSetPlacementPolicy()) {
                Set<Guid> hostGuidsSet = validateAndUpdateHostsInPlacementPolicy(vm.getPlacementPolicy());
                staticVm.setDedicatedVmForVdsList(new LinkedList<>(hostGuidsSet));
            } else {
                vm.setPlacementPolicy(null);
            }
            // migration support (disabling it in architectures that do not support this feature)
            if (!vm.isSetPlacementPolicy() && template.getId().equals(Guid.Empty)) {
                staticVm.setMigrationSupport(null);
            }
            Guid storageDomainId = (vm.isSetStorageDomain() && vm.getStorageDomain().isSetId()) ? asGuid(vm.getStorageDomain().getId()) : Guid.Empty;
            boolean clone = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, CLONE, true, false);
            if (clone) {
                response = cloneVmFromTemplate(staticVm, vm, template, instanceTypeEntity, cluster);
            } else if (Guid.Empty.equals(template.getId())) {
                response = addVmFromScratch(staticVm, vm, instanceTypeEntity, cluster);
            } else {
                response = addVm(staticVm, vm, storageDomainId, template, instanceTypeEntity, cluster);
            }
        }
    }
    Vm result = (Vm) response.getEntity();
    if (result != null) {
        DisplayHelper.adjustDisplayData(this, result, false);
        removeRestrictedInfo(result);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Vm(org.ovirt.engine.api.model.Vm) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Guid(org.ovirt.engine.core.compat.Guid) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType)

Example 24 with VmStatic

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

the class BackendVmPoolsResource method mapToVM.

protected VM mapToVM(VmPool model, VmTemplate template, Cluster cluster) {
    // apply template
    VmStatic fromTemplate = getMapper(VmTemplate.class, VmStatic.class).map(template, null);
    VmStatic fromInstanceType = null;
    if (model.isSetInstanceType()) {
        org.ovirt.engine.core.common.businessentities.InstanceType instanceType = loadInstanceType(model);
        fromTemplate.setInstanceTypeId(instanceType.getId());
        fromInstanceType = VmMapper.map(instanceType, fromTemplate, cluster.getCompatibilityVersion());
        fromInstanceType.setInstanceTypeId(instanceType.getId());
    }
    // override with client-provided data
    VM vm = new VM(getMapper(VmPool.class, VmStatic.class).map(model, fromInstanceType != null ? fromInstanceType : fromTemplate), new VmDynamic(), new VmStatistics());
    return vm;
}
Also used : VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VmStatistics(org.ovirt.engine.core.common.businessentities.VmStatistics) VM(org.ovirt.engine.core.common.businessentities.VM) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Example 25 with VmStatic

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

the class BackendTemplatesResource method add.

@Override
public Response add(Template template) {
    validateParameters(template, "name", "vm.id|name");
    validateIconParameters(template);
    Guid clusterId = null;
    Cluster cluster = null;
    if (namedCluster(template)) {
        clusterId = getClusterId(template);
        cluster = lookupCluster(clusterId);
    }
    if (template.getVersion() != null) {
        validateParameters(template.getVersion(), "baseTemplate");
    }
    VmStatic originalVm = getVm(cluster, template);
    VmStatic staticVm = getMapper(Template.class, VmStatic.class).map(template, originalVm);
    if (namedCluster(template)) {
        staticVm.setClusterId(clusterId);
    }
    // REVISIT: powershell has a IsVmTemlateWithSameNameExist safety check
    AddVmTemplateParameters params = new AddVmTemplateParameters(staticVm, template.getName(), template.getDescription());
    if (template.getVersion() != null) {
        params.setBaseTemplateId(Guid.createGuidFromString(template.getVersion().getBaseTemplate().getId()));
        params.setTemplateVersionName(template.getVersion().getVersionName());
    }
    params.setConsoleEnabled(template.getConsole() != null && template.getConsole().isSetEnabled() ? template.getConsole().isEnabled() : !getConsoleDevicesForEntity(originalVm.getId()).isEmpty());
    params.setVirtioScsiEnabled(template.isSetVirtioScsi() && template.getVirtioScsi().isSetEnabled() ? template.getVirtioScsi().isEnabled() : null);
    if (template.isSetSoundcardEnabled()) {
        params.setSoundDeviceEnabled(template.isSoundcardEnabled());
    } else {
        params.setSoundDeviceEnabled(!VmHelper.getSoundDevicesForEntity(this, originalVm.getId()).isEmpty());
    }
    if (template.isSetRngDevice()) {
        params.setUpdateRngDevice(true);
        params.setRngDevice(RngDeviceMapper.map(template.getRngDevice(), null));
    }
    DisplayHelper.setGraphicsToParams(template.getDisplay(), params);
    boolean isDomainSet = false;
    if (template.isSetStorageDomain() && template.getStorageDomain().isSetId()) {
        params.setDestinationStorageDomainId(asGuid(template.getStorageDomain().getId()));
        isDomainSet = true;
    }
    params.setDiskInfoDestinationMap(getDestinationTemplateDiskMap(template.getVm(), originalVm.getId(), params.getDestinationStorageDomainId(), isDomainSet));
    setupOptionalParameters(params);
    IconHelper.setIconToParams(template, params);
    Response response = performCreate(ActionType.AddVmTemplate, params, new QueryIdResolver<Guid>(QueryType.GetVmTemplate, GetVmTemplateParameters.class));
    Template result = (Template) response.getEntity();
    if (result != null) {
        DisplayHelper.adjustDisplayData(this, result);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) GetVmTemplateParameters(org.ovirt.engine.core.common.queries.GetVmTemplateParameters) AddVmTemplateParameters(org.ovirt.engine.core.common.action.AddVmTemplateParameters) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Guid(org.ovirt.engine.core.compat.Guid) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

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