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