use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.
the class BackendVmsResourceTest method doTestBadAddFromScratch.
private void doTestBadAddFromScratch(boolean valid, boolean success, String detail) throws Exception {
setUpEntityQueryExpectations(QueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getTemplateEntity(0));
when(osRepository.isBalloonEnabled(anyInt(), any())).thenReturn(false);
setUpEntityQueryExpectations(QueryType.GetClusterById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[1] }, getClusterEntity());
setUriInfo(setUpActionExpectations(ActionType.AddVmFromScratch, AddVmParameters.class, new String[] { "StorageDomainId" }, new Object[] { Guid.Empty }, valid, success));
Vm model = getModel(0);
model.setCluster(new org.ovirt.engine.api.model.Cluster());
model.getCluster().setId(GUIDS[1].toString());
model.setTemplate(new Template());
model.getTemplate().setId(DEFAULT_TEMPLATE_ID);
try {
collection.add(model);
fail("expected WebApplicationException");
} catch (WebApplicationException wae) {
verifyFault(wae, detail);
}
}
use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.
the class BackendTemplatesResource method mapCollection.
protected Templates mapCollection(List<VmTemplate> entities) {
Set<String> details = DetailHelper.getDetails(httpHeaders, uriInfo);
boolean includeData = details.contains(DetailHelper.MAIN);
boolean includeSize = details.contains("size");
if (includeData) {
// Fill VmInit for entities - the search query no join the VmInit to Templates
IdsQueryParameters params = new IdsQueryParameters();
List<Guid> ids = entities.stream().map(VmTemplate::getId).collect(Collectors.toList());
params.setId(ids);
QueryReturnValue queryReturnValue = runQuery(QueryType.GetVmsInit, params);
if (queryReturnValue.getSucceeded() && queryReturnValue.getReturnValue() != null) {
List<VmInit> vmInits = queryReturnValue.getReturnValue();
Map<Guid, VmInit> initMap = Entities.businessEntitiesById(vmInits);
for (VmTemplate template : entities) {
template.setVmInit(initMap.get(template.getId()));
}
}
}
Templates collection = new Templates();
if (includeData) {
for (VmTemplate entity : entities) {
Template template = map(entity);
collection.getTemplates().add(addLinks(populate(template, entity)));
DisplayHelper.adjustDisplayData(this, template);
}
}
if (includeSize) {
collection.setSize((long) entities.size());
}
return collection;
}
use of org.ovirt.engine.api.model.Template 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;
}
use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.
the class BackendTemplateWatchdogResource method addParents.
@Override
public Watchdog addParents(Watchdog watchdog) {
Template template = new Template();
template.setId(templateId.toString());
watchdog.setTemplate(template);
return watchdog;
}
use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.
the class V3SpecialObjectsOutAdapter method adapt.
@Override
public V3SpecialObjects adapt(SpecialObjects from) {
V3SpecialObjects to = new V3SpecialObjects();
Template blankTemplate = from.getBlankTemplate();
if (blankTemplate != null) {
V3Link blankTemplateLink = new V3Link();
blankTemplateLink.setRel("templates/blank");
blankTemplateLink.setHref(blankTemplate.getHref());
to.getLinks().add(blankTemplateLink);
}
Tag rootTag = from.getRootTag();
if (rootTag != null) {
V3Link rootTagLink = new V3Link();
rootTagLink.setRel("tags/root");
rootTagLink.setHref(rootTag.getHref());
to.getLinks().add(rootTagLink);
}
return to;
}
Aggregations