Search in sources :

Example 1 with AddVmTemplateParameters

use of org.ovirt.engine.core.common.action.AddVmTemplateParameters 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)

Example 2 with AddVmTemplateParameters

use of org.ovirt.engine.core.common.action.AddVmTemplateParameters in project ovirt-engine by oVirt.

the class InstanceTypeListModel method postInstanceTypeNameUniqueCheck.

private void postInstanceTypeNameUniqueCheck() {
    UnitVmModel model = (UnitVmModel) getWindow();
    VM vm = new VM();
    buildVmStatic(vm.getStaticData());
    vm.setVmDescription(model.getDescription().getEntity());
    AddVmTemplateParameters addInstanceTypeParameters = new AddVmTemplateParameters(vm, model.getName().getEntity(), model.getDescription().getEntity());
    addInstanceTypeParameters.setTemplateType(VmEntityType.INSTANCE_TYPE);
    addInstanceTypeParameters.setVmTemplateId(null);
    addInstanceTypeParameters.setPublicUse(true);
    addInstanceTypeParameters.setSoundDeviceEnabled(model.getIsSoundcardEnabled().getEntity());
    addInstanceTypeParameters.setConsoleEnabled(model.getIsConsoleDeviceEnabled().getEntity());
    addInstanceTypeParameters.setBalloonEnabled(model.getMemoryBalloonDeviceEnabled().getEntity());
    addInstanceTypeParameters.setVirtioScsiEnabled(model.getIsVirtioScsiEnabled().getEntity());
    if (model.getIsHeadlessModeEnabled().getEntity()) {
        addInstanceTypeParameters.getVm().setDefaultDisplayType(DisplayType.none);
    }
    setVmWatchdogToParams(model, addInstanceTypeParameters);
    setRngDeviceToParams(model, addInstanceTypeParameters);
    BuilderExecutor.build(model, addInstanceTypeParameters, new UnitToGraphicsDeviceParamsBuilder());
    getWindow().startProgress();
    Frontend.getInstance().runAction(ActionType.AddVmTemplate, addInstanceTypeParameters, new UnitVmModelNetworkAsyncCallback(model, addInstanceTypeNetworkManager), this);
}
Also used : UnitToGraphicsDeviceParamsBuilder(org.ovirt.engine.ui.uicommonweb.builders.vm.UnitToGraphicsDeviceParamsBuilder) UnitVmModelNetworkAsyncCallback(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModelNetworkAsyncCallback) VM(org.ovirt.engine.core.common.businessentities.VM) AddVmTemplateParameters(org.ovirt.engine.core.common.action.AddVmTemplateParameters) UnitVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel)

Example 3 with AddVmTemplateParameters

use of org.ovirt.engine.core.common.action.AddVmTemplateParameters in project ovirt-engine by oVirt.

the class AddVmTemplateCommandTest method setupDedicatedHostForVmAndTemplate.

private void setupDedicatedHostForVmAndTemplate(boolean setDefaultHostForTemplate) {
    Guid hostId = Guid.newGuid();
    vm.setDedicatedVmForVdsList(Collections.singletonList(hostId));
    AddVmTemplateParameters parameters = new AddVmTemplateParameters();
    VmStatic vmStatic = new VmStatic();
    vmStatic.setDedicatedVmForVdsList(setDefaultHostForTemplate ? Collections.singletonList(hostId) : Collections.emptyList());
    parameters.setMasterVm(vmStatic);
    parameters.setTemplateType(VmEntityType.TEMPLATE);
    doReturn(parameters).when(cmd).getParameters();
}
Also used : AddVmTemplateParameters(org.ovirt.engine.core.common.action.AddVmTemplateParameters) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Guid(org.ovirt.engine.core.compat.Guid)

Example 4 with AddVmTemplateParameters

use of org.ovirt.engine.core.common.action.AddVmTemplateParameters in project ovirt-engine by oVirt.

the class ImportRepoImageCommand method createTemplate.

private Guid createTemplate() {
    VmTemplate blankTemplate = vmTemplateDao.get(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
    VmStatic masterVm = new VmStatic(blankTemplate);
    DiskImage templateDiskImage = getParameters().getDiskImage();
    String vmTemplateName = getParameters().getTemplateName();
    AddVmTemplateParameters parameters = new AddVmTemplateParameters(masterVm, vmTemplateName, templateDiskImage.getDiskDescription());
    // Setting the user from the parent command, as the session might already be invalid
    parameters.setParametersCurrentUser(getParameters().getParametersCurrentUser());
    // Setting the cluster ID, and other related properties derived from it
    if (getParameters().getClusterId() != null) {
        masterVm.setClusterId(getParameters().getClusterId());
        Cluster vdsGroup = getCluster(masterVm.getClusterId());
        masterVm.setOsId(osRepository.getDefaultOSes().get(vdsGroup.getArchitecture()));
        DisplayType defaultDisplayType = osRepository.getGraphicsAndDisplays(masterVm.getOsId(), vdsGroup.getCompatibilityVersion()).get(0).getSecond();
        masterVm.setDefaultDisplayType(defaultDisplayType);
    }
    parameters.setBalloonEnabled(true);
    ActionReturnValue addVmTemplateReturnValue = Backend.getInstance().runInternalAction(ActionType.AddVmTemplate, parameters, ExecutionHandler.createDefaultContextForTasks(getContext()));
    // No reason for this to return null, but checking just to make sure, and returning the created template, or null if failed
    return addVmTemplateReturnValue.getActionReturnValue() != null ? (Guid) addVmTemplateReturnValue.getActionReturnValue() : null;
}
Also used : DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) AddVmTemplateParameters(org.ovirt.engine.core.common.action.AddVmTemplateParameters) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 5 with AddVmTemplateParameters

use of org.ovirt.engine.core.common.action.AddVmTemplateParameters in project ovirt-engine by oVirt.

the class BackendInstanceTypesResource method add.

@Override
public Response add(InstanceType instanceType) {
    validateParameters(instanceType, "name");
    VmStatic vmStatic = getMapper(InstanceType.class, VmStatic.class).map(instanceType, new VmStatic());
    VM vm = new VM();
    vm.setStaticData(vmStatic);
    String name = instanceType.getName();
    String description = "";
    if (instanceType.isSetDescription()) {
        description = instanceType.getDescription();
    }
    vm.setVmDescription(description);
    updateMaxMemoryIfUnspecified(instanceType, vm);
    AddVmTemplateParameters addInstanceTypeParameters = new AddVmTemplateParameters(vm, name, description);
    addInstanceTypeParameters.setTemplateType(VmEntityType.INSTANCE_TYPE);
    addInstanceTypeParameters.setVmTemplateId(null);
    addInstanceTypeParameters.setPublicUse(true);
    addInstanceTypeParameters.setConsoleEnabled(instanceType.getConsole() != null && instanceType.getConsole().isSetEnabled() ? instanceType.getConsole().isEnabled() : false);
    addInstanceTypeParameters.setVirtioScsiEnabled(instanceType.isSetVirtioScsi() && instanceType.getVirtioScsi().isSetEnabled() ? instanceType.getVirtioScsi().isEnabled() : null);
    if (instanceType.isSetSoundcardEnabled()) {
        addInstanceTypeParameters.setSoundDeviceEnabled(instanceType.isSoundcardEnabled());
    }
    DisplayHelper.setGraphicsToParams(instanceType.getDisplay(), addInstanceTypeParameters);
    Response response = performCreate(ActionType.AddVmTemplate, addInstanceTypeParameters, new QueryIdResolver<Guid>(QueryType.GetInstanceType, 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) VM(org.ovirt.engine.core.common.businessentities.VM) AddVmTemplateParameters(org.ovirt.engine.core.common.action.AddVmTemplateParameters) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Guid(org.ovirt.engine.core.compat.Guid) InstanceType(org.ovirt.engine.api.model.InstanceType) Template(org.ovirt.engine.api.model.Template)

Aggregations

AddVmTemplateParameters (org.ovirt.engine.core.common.action.AddVmTemplateParameters)6 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)4 VM (org.ovirt.engine.core.common.businessentities.VM)3 Guid (org.ovirt.engine.core.compat.Guid)3 Response (javax.ws.rs.core.Response)2 Template (org.ovirt.engine.api.model.Template)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 GetVmTemplateParameters (org.ovirt.engine.core.common.queries.GetVmTemplateParameters)2 InstanceType (org.ovirt.engine.api.model.InstanceType)1 DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)1 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)1 UnitToAddVmTemplateParametersBuilder (org.ovirt.engine.ui.uicommonweb.builders.template.UnitToAddVmTemplateParametersBuilder)1 UnitToGraphicsDeviceParamsBuilder (org.ovirt.engine.ui.uicommonweb.builders.vm.UnitToGraphicsDeviceParamsBuilder)1 UnitVmModel (org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel)1 UnitVmModelNetworkAsyncCallback (org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModelNetworkAsyncCallback)1