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());
}
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);
}
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;
}
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();
}
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));
}
Aggregations