Search in sources :

Example 1 with ImportVmTemplateParameters

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

the class BackendStorageDomainTemplateResource method doImport.

@Override
public Response doImport(Action action) {
    validateParameters(action, "storageDomain.id|name");
    Guid destStorageDomainId = getDestStorageDomainId(action);
    Guid clusterId = null;
    if (action.isSetCluster()) {
        clusterId = getClusterId(action);
    }
    ImportVmTemplateParameters params = new ImportVmTemplateParameters(parent.getDataCenterId(destStorageDomainId), parent.getStorageDomainId(), destStorageDomainId, clusterId, getEntity());
    params.setImageToDestinationDomainMap(getDiskToDestinationMap(action));
    params.setForceOverride(action.isSetExclusive() ? action.isExclusive() : false);
    if (action.isSetClone()) {
        params.setImportAsNewEntity(action.isClone());
        if (action.isSetTemplate() && action.getTemplate().isSetName()) {
            params.getVmTemplate().setName(action.getTemplate().getName());
        }
    }
    return doAction(ActionType.ImportVmTemplate, params, action);
}
Also used : ImportVmTemplateParameters(org.ovirt.engine.core.common.action.ImportVmTemplateParameters) Guid(org.ovirt.engine.core.compat.Guid)

Example 2 with ImportVmTemplateParameters

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

the class ImportVmTemplateCommandTest method mockStorageDomains.

private void mockStorageDomains() {
    final ImportVmTemplateParameters parameters = command.getParameters();
    final StorageDomain srcDomain = new StorageDomain();
    srcDomain.setStorageDomainType(StorageDomainType.ImportExport);
    srcDomain.setStatus(StorageDomainStatus.Active);
    when(storageDomainDao.getForStoragePool(parameters.getSourceDomainId(), parameters.getStoragePoolId())).thenReturn(srcDomain);
    final StorageDomain destDomain = new StorageDomain();
    destDomain.setStorageDomainType(StorageDomainType.Data);
    destDomain.setUsedDiskSize(0);
    destDomain.setAvailableDiskSize(1000);
    destDomain.setStatus(StorageDomainStatus.Active);
    when(storageDomainDao.getForStoragePool(parameters.getDestDomainId(), parameters.getStoragePoolId())).thenReturn(destDomain);
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) ImportVmTemplateParameters(org.ovirt.engine.core.common.action.ImportVmTemplateParameters)

Example 3 with ImportVmTemplateParameters

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

the class ImportVmTemplateCommandTest method createParameters.

protected ImportVmTemplateParameters createParameters() {
    VmTemplate t = new VmTemplate();
    t.setName("testTemplate");
    return new ImportVmTemplateParameters(Guid.newGuid(), Guid.newGuid(), Guid.newGuid(), Guid.newGuid(), t);
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ImportVmTemplateParameters(org.ovirt.engine.core.common.action.ImportVmTemplateParameters)

Example 4 with ImportVmTemplateParameters

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

the class TemplateBackupModel method executeImport.

protected void executeImport() {
    ImportTemplateModel model = (ImportTemplateModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    if (!model.validate()) {
        return;
    }
    List<ActionParametersBase> prms = new ArrayList<>();
    for (Object object : importModel.getItems()) {
        ImportTemplateData importData = (ImportTemplateData) object;
        VmTemplate template = importData.getTemplate();
        ImportVmTemplateParameters importVmTemplateParameters = new ImportVmTemplateParameters(model.getStoragePool().getId(), getEntity().getId(), Guid.Empty, model.getCluster().getSelectedItem().getId(), template);
        if (importModel.getClusterQuota().getSelectedItem() != null && importModel.getClusterQuota().getIsAvailable()) {
            importVmTemplateParameters.setQuotaId(importModel.getClusterQuota().getSelectedItem().getId());
        }
        CpuProfile cpuProfile = importModel.getCpuProfiles().getSelectedItem();
        if (cpuProfile != null) {
            importVmTemplateParameters.setCpuProfileId(cpuProfile.getId());
        }
        Map<Guid, Guid> map = new HashMap<>();
        for (DiskImage disk : template.getDiskList()) {
            map.put(disk.getId(), importModel.getDiskImportData(disk.getId()).getSelectedStorageDomain().getId());
            if (importModel.getDiskImportData(disk.getId()).getSelectedQuota() != null) {
                disk.setQuotaId(importModel.getDiskImportData(disk.getId()).getSelectedQuota().getId());
            }
        }
        importVmTemplateParameters.setImageToDestinationDomainMap(map);
        if (importData.isExistsInSystem() || importData.getClone().getEntity()) {
            if (!cloneObjectMap.containsKey(template.getId())) {
                continue;
            }
            importVmTemplateParameters.setImportAsNewEntity(true);
            importVmTemplateParameters.getVmTemplate().setName(((ImportTemplateData) cloneObjectMap.get(template.getId())).getTemplate().getName());
        }
        prms.add(importVmTemplateParameters);
    }
    model.startProgress();
    Frontend.getInstance().runMultipleAction(ActionType.ImportVmTemplate, prms, result -> {
        TemplateBackupModel templateBackupModel = (TemplateBackupModel) result.getState();
        templateBackupModel.getWindow().stopProgress();
        templateBackupModel.cancel();
        List<ActionReturnValue> retVals = result.getReturnValue();
        if (retVals != null && templateBackupModel.getSelectedItems().size() == retVals.size()) {
            StringBuilder importedTemplates = new StringBuilder();
            int counter = 0;
            boolean toShowConfirmWindow = false;
            for (VmTemplate template : templateBackupModel.getSelectedItems()) {
                if (retVals.get(counter) != null && retVals.get(counter).isValid()) {
                    // $NON-NLS-1$
                    importedTemplates.append(template.getName()).append(", ");
                    toShowConfirmWindow = true;
                }
                counter++;
            }
            if (toShowConfirmWindow) {
                ConfirmationModel confirmModel = new ConfirmationModel();
                templateBackupModel.setConfirmWindow(confirmModel);
                confirmModel.setTitle(constants.importTemplatesTitle());
                confirmModel.setHelpTag(HelpTag.import_template);
                // $NON-NLS-1$
                confirmModel.setHashName("import_template");
                confirmModel.setMessage(messages.importProcessHasBegunForTemplates(StringHelper.trimEnd(importedTemplates.toString().trim(), ',')));
                confirmModel.getCommands().add(// $NON-NLS-1$
                new UICommand(CANCEL_CONFIRMATION_COMMAND, templateBackupModel).setTitle(constants.close()).setIsDefault(true).setIsCancel(true));
            }
        }
    }, this);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) ImportTemplateData(org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ImportVmTemplateParameters(org.ovirt.engine.core.common.action.ImportVmTemplateParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ImportTemplateModel(org.ovirt.engine.ui.uicommonweb.models.templates.ImportTemplateModel) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Aggregations

ImportVmTemplateParameters (org.ovirt.engine.core.common.action.ImportVmTemplateParameters)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)1 CpuProfile (org.ovirt.engine.core.common.businessentities.profiles.CpuProfile)1 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)1 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)1 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)1 ImportTemplateModel (org.ovirt.engine.ui.uicommonweb.models.templates.ImportTemplateModel)1 ImportTemplateData (org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData)1