Search in sources :

Example 81 with VmTemplate

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

the class VmModelBehaviorBase method initDisks.

public void initDisks() {
    VmTemplate template = getModel().getTemplateWithVersion().getSelectedItem().getTemplateVersion();
    AsyncDataProvider.getInstance().getTemplateDiskList(asyncQuery(this::initTemplateDisks), template.getId());
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate)

Example 82 with VmTemplate

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

the class VmModelBehaviorBase method setupTemplateWithVersion.

protected void setupTemplateWithVersion(final Guid templateId, final boolean useLatest, final boolean isVersionChangeable) {
    AsyncDataProvider.getInstance().getTemplateById(new AsyncQuery<>(rawTemplate -> {
        if (isVersionChangeable) {
            // only used by pools therefore query is limited to admin-portal permissions.
            AsyncDataProvider.getInstance().getVmTemplatesByBaseTemplateId(new AsyncQuery<>(templatesChain -> initTemplateWithVersion(templatesChain, templateId, useLatest)), rawTemplate.getBaseTemplateId());
        } else {
            final VmTemplate template = useLatest ? new LatestVmTemplate(rawTemplate) : rawTemplate;
            if (template.isBaseTemplate()) {
                TemplateWithVersion templateCouple = new TemplateWithVersion(template, template);
                setReadOnlyTemplateWithVersion(templateCouple);
            } else {
                AsyncDataProvider.getInstance().getTemplateById(new AsyncQuery<>(baseTemplate -> {
                    TemplateWithVersion templateCouple = new TemplateWithVersion(baseTemplate, template);
                    setReadOnlyTemplateWithVersion(templateCouple);
                }), template.getBaseTemplateId());
            }
        }
    }), templateId);
}
Also used : UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) TemplateWithVersion(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateWithVersion) Arrays(java.util.Arrays) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) VmType(org.ovirt.engine.core.common.businessentities.VmType) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) DiskByDiskAliasComparator(org.ovirt.engine.core.common.businessentities.comparators.DiskByDiskAliasComparator) Event(org.ovirt.engine.ui.uicompat.Event) ImagesDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.ImagesDataProvider) VmNumaSupportModel(org.ovirt.engine.ui.uicommonweb.models.hosts.numa.VmNumaSupportModel) QuotaEnforcementTypeEnum(org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) Version(org.ovirt.engine.core.compat.Version) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) I18NNameValidation(org.ovirt.engine.ui.uicommonweb.validation.I18NNameValidation) StringHelper(org.ovirt.engine.core.compat.StringHelper) VolumeType(org.ovirt.engine.core.common.businessentities.storage.VolumeType) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) QueryType(org.ovirt.engine.core.common.queries.QueryType) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) TimeZoneType(org.ovirt.engine.core.common.TimeZoneType) Guid(org.ovirt.engine.core.compat.Guid) ServerCpu(org.ovirt.engine.core.common.businessentities.ServerCpu) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) HashMap(java.util.HashMap) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ExistingBlankTemplateModelBehavior(org.ovirt.engine.ui.uicommonweb.models.templates.ExistingBlankTemplateModelBehavior) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) HashSet(java.util.HashSet) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) Frontend(org.ovirt.engine.ui.frontend.Frontend) NumaSupportModel(org.ovirt.engine.ui.uicommonweb.models.hosts.numa.NumaSupportModel) InstanceTypeManager(org.ovirt.engine.ui.uicommonweb.models.vms.instancetypes.InstanceTypeManager) UIMessages(org.ovirt.engine.ui.uicompat.UIMessages) NameableComparator(org.ovirt.engine.core.common.businessentities.comparators.NameableComparator) Linq(org.ovirt.engine.ui.uicommonweb.Linq) BuilderExecutor(org.ovirt.engine.ui.uicommonweb.builders.BuilderExecutor) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Quota(org.ovirt.engine.core.common.businessentities.Quota) VmCommonUtils(org.ovirt.engine.core.common.utils.VmCommonUtils) VM(org.ovirt.engine.core.common.businessentities.VM) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) TemplateWithVersion(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateWithVersion) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate)

Example 83 with VmTemplate

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

the class VmModelBehaviorBase method createTemplateWithVersionsAddLatest.

/**
 * @param templates raw templates from backend, latest not included
 * @return model ready for 'Template' comobox, including latest
 */
private static List<TemplateWithVersion> createTemplateWithVersionsAddLatest(List<VmTemplate> templates, boolean addLatest) {
    final Map<Guid, VmTemplate> baseIdToBaseTemplateMap = new HashMap<>();
    final Map<Guid, VmTemplate> baseIdToLastVersionMap = new HashMap<>();
    for (VmTemplate template : templates) {
        if (template.isBaseTemplate()) {
            baseIdToBaseTemplateMap.put(template.getId(), template);
            baseIdToLastVersionMap.put(template.getId(), template);
        }
    }
    final List<TemplateWithVersion> result = new ArrayList<>();
    for (VmTemplate template : templates) {
        // update last version map
        if (baseIdToLastVersionMap.get(template.getBaseTemplateId()).getTemplateVersionNumber() < template.getTemplateVersionNumber()) {
            baseIdToLastVersionMap.put(template.getBaseTemplateId(), template);
        }
        final VmTemplate baseTemplate = baseIdToBaseTemplateMap.get(template.getBaseTemplateId());
        result.add(new TemplateWithVersion(baseTemplate, template));
    }
    // add latest
    if (addLatest) {
        for (Map.Entry<Guid, VmTemplate> pair : baseIdToLastVersionMap.entrySet()) {
            VmTemplate baseTemplate = baseIdToBaseTemplateMap.get(pair.getKey());
            VmTemplate latestTemplate = new LatestVmTemplate(pair.getValue());
            result.add(new TemplateWithVersion(baseTemplate, latestTemplate));
        }
    }
    Collections.sort(result);
    return result;
}
Also used : TemplateWithVersion(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateWithVersion) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate) Map(java.util.Map) HashMap(java.util.HashMap)

Example 84 with VmTemplate

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

the class ExistingPoolInstanceTypeManager method getSource.

@Override
protected VmBase getSource() {
    boolean customInstanceTypeUsed = getModel().getInstanceTypes() != null && getModel().getInstanceTypes().getSelectedItem() instanceof CustomInstanceType;
    if (!customInstanceTypeUsed) {
        return (VmBase) getModel().getInstanceTypes().getSelectedItem();
    }
    if (getModel().getTemplateWithVersion() == null || getModel().getTemplateWithVersion().getSelectedItem() == null || getModel().getTemplateWithVersion().getSelectedItem().getTemplateVersion() == null) {
        return pool.getStaticData();
    }
    VmTemplate template = getModel().getTemplateWithVersion().getSelectedItem().getTemplateVersion();
    boolean isLatestPropertyChanged = pool.isUseLatestVersion() != (template instanceof LatestVmTemplate);
    // template ID changed but latest is not set, as it would cause false-positives
    boolean isTemplateIdChangedSinceInit = !pool.getVmtGuid().equals(template.getId()) && !pool.isUseLatestVersion();
    if (isTemplateIdChangedSinceInit || isLatestPropertyChanged) {
        return template;
    }
    return pool.getStaticData();
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate)

Example 85 with VmTemplate

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

the class NetworkValidatorTest method networkInUseByOneTemplate.

@Test
public void networkInUseByOneTemplate() throws Exception {
    VmTemplate template = mock(VmTemplate.class);
    when(template.getName()).thenReturn(NAMEABLE_NAME);
    networkNotUsedByTemplatesTest(failsWithOneNetworkInUse(), Collections.singletonList(template));
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Test(org.junit.Test)

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