Search in sources :

Example 91 with VmTemplate

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

the class RegisterTemplateModel method prepareActionParameters.

private List<ActionParametersBase> prepareActionParameters() {
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    for (ImportTemplateData entityData : getEntities().getItems()) {
        VmTemplate vmTemplate = entityData.getEntity();
        Cluster cluster = entityData.getCluster().getSelectedItem();
        ImportVmTemplateFromConfParameters params = new ImportVmTemplateFromConfParameters();
        params.setExternalVnicProfileMappings(cloneExternalVnicProfiles(cluster));
        params.setContainerId(vmTemplate.getId());
        params.setStorageDomainId(getStorageDomainId());
        params.setImagesExistOnTargetStorageDomain(true);
        params.setClusterId(cluster != null ? cluster.getId() : null);
        if (isQuotaEnabled()) {
            Quota quota = entityData.getClusterQuota().getSelectedItem();
            params.setQuotaId(quota != null ? quota.getId() : null);
            params.setDiskTemplateMap(vmTemplate.getDiskTemplateMap());
            updateDiskQuotas(new ArrayList<Disk>(params.getDiskTemplateMap().values()));
        }
        parameters.add(params);
    }
    return parameters;
}
Also used : ImportVmTemplateFromConfParameters(org.ovirt.engine.core.common.action.ImportVmTemplateFromConfParameters) ImportTemplateData(org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData) Quota(org.ovirt.engine.core.common.businessentities.Quota) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 92 with VmTemplate

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

the class OvfHelper method readVmTemplateFromOvf.

/**
 * parses a given ovf to a VmTemplate, initialized with images and interfaces.
 * @return
 *        VmTemplate that represents the given ovf data
 */
public FullEntityOvfData readVmTemplateFromOvf(String ovf) throws OvfReaderException {
    VmTemplate template = new VmTemplate();
    FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(template);
    ovfManager.importTemplate(ovf, fullEntityOvfData);
    template.setInterfaces(fullEntityOvfData.getInterfaces());
    // add disk map
    for (DiskImage disk : fullEntityOvfData.getDiskImages()) {
        template.getDiskTemplateMap().put(disk.getId(), disk);
    }
    return fullEntityOvfData;
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 93 with VmTemplate

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

the class OvfUpdateProcessHelper method loadVmData.

/**
 * Loads additional need vm data for it's ovf
 */
public void loadVmData(VM vm) {
    vmDeviceUtils.setVmDevices(vm.getStaticData());
    if (vm.getInterfaces().isEmpty()) {
        vm.setInterfaces(vmNetworkInterfaceDao.getAllForVm(vm.getId()));
    }
    if (StringUtils.isEmpty(vm.getVmtName())) {
        if (!Guid.Empty.equals(vm.getVmtGuid())) {
            VmTemplate t = vmTemplateDao.get(vm.getVmtGuid());
            vm.setVmtName(t.getName());
        } else {
            vm.setVmtName(VmTemplateHandler.BLANK_VM_TEMPLATE_NAME);
        }
    }
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 94 with VmTemplate

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

the class ProcessOvfUpdateForStoragePoolCommand method populateTemplatesMetadataForOvfUpdate.

/**
 * Creates and returns a map containing valid templates metadata
 */
protected Map<Guid, KeyValuePairCompat<String, List<Guid>>> populateTemplatesMetadataForOvfUpdate(List<Guid> idsToProcess) {
    Map<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndTemplateMetadata = new HashMap<>();
    List<VmTemplate> templates = vmTemplateDao.getVmTemplatesByIds(idsToProcess);
    for (VmTemplate template : templates) {
        if (VmTemplateStatus.Locked != template.getStatus()) {
            updateTemplateDisksFromDb(template);
            boolean verifyDisksNotLocked = verifyImagesStatus(template.getDiskList());
            if (verifyDisksNotLocked) {
                ovfUpdateProcessHelper.loadTemplateData(template);
                Long currentDbGeneration = vmStaticDao.getDbGeneration(template.getId());
                // currentDbGeneration can be null in case that the template was deleted during the run of OvfDataUpdater.
                if (currentDbGeneration != null && template.getDbGeneration() == currentDbGeneration) {
                    proccessedOvfConfigurationsInfo.add(ovfUpdateProcessHelper.buildMetadataDictionaryForTemplate(template, vmsAndTemplateMetadata));
                    proccessedIdsInfo.add(template.getId());
                    proccessedOvfGenerationsInfo.add(template.getDbGeneration());
                    proccessDisksDomains(template.getDiskList());
                }
            }
        }
    }
    return vmsAndTemplateMetadata;
}
Also used : KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) HashMap(java.util.HashMap) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Guid(org.ovirt.engine.core.compat.Guid)

Example 95 with VmTemplate

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

Aggregations

VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)149 ArrayList (java.util.ArrayList)42 Guid (org.ovirt.engine.core.compat.Guid)40 Test (org.junit.Test)30 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)23 HashMap (java.util.HashMap)22 List (java.util.List)20 VM (org.ovirt.engine.core.common.businessentities.VM)19 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)16 Map (java.util.Map)13 QueryType (org.ovirt.engine.core.common.queries.QueryType)13 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)12 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)11 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)11 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)11 Frontend (org.ovirt.engine.ui.frontend.Frontend)10 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)9 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)9 Collection (java.util.Collection)8 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)8