private static VmTemplate cloneVmTemplate(VmTemplate instance) { VmTemplate obj = new VmTemplate(); obj.setStoragePoolId(instance.getStoragePoolId()); obj.setStoragePoolName(instance.getStoragePoolName()); obj.setDefaultDisplayType(instance.getDefaultDisplayType()); obj.setPriority(instance.getPriority()); obj.setIsoPath(instance.getIsoPath()); obj.setOrigin(instance.getOrigin()); obj.setDiskImageMap(instance.getDiskImageMap()); obj.setInterfaces(instance.getInterfaces()); obj.setAutoStartup(instance.isAutoStartup()); obj.setChildCount(instance.getChildCount()); obj.setCpuPerSocket(instance.getCpuPerSocket()); obj.setThreadsPerCpu(instance.getThreadsPerCpu()); obj.setCreationDate(instance.getCreationDate()); obj.setDefaultBootSequence(instance.getDefaultBootSequence()); obj.setComment(instance.getComment()); obj.setCustomEmulatedMachine(instance.getCustomEmulatedMachine()); obj.setBiosType(instance.getBiosType()); obj.setCustomCpuName(instance.getCustomCpuName()); obj.setCustomCompatibilityVersion(instance.getCustomCompatibilityVersion()); obj.setStateless(instance.isStateless()); obj.setMemSizeMb(instance.getMemSizeMb()); obj.setMaxMemorySizeMb(instance.getMaxMemorySizeMb()); obj.setName(instance.getName()); obj.setNiceLevel(instance.getNiceLevel()); obj.setNumOfMonitors(instance.getNumOfMonitors()); obj.setAllowConsoleReconnect(instance.isAllowConsoleReconnect()); obj.setNumOfSockets(instance.getNumOfSockets());
public VmTemplate(VmTemplate template) { super(template); diskTemplateMap = new HashMap<>(); diskImageMap = new HashMap<>(); setChildCount(template.getChildCount()); setStatus(template.getStatus()); setTemplateType(template.getTemplateType()); setBaseTemplateId(template.getBaseTemplateId()); setTemplateVersionName(template.getTemplateVersionName()); setTemplateVersionNumber(template.getTemplateVersionNumber()); setDisabled(template.isDisabled()); setDescription(this.getDescription()); }
/** * In case the template is not base, return template's version name and version number in the format: * " (Version: version-name (version-number))" */ private String getTemplateVersionNameAndNumber(VmTemplate template) { if (template.isBaseTemplate()) { return ""; //$NON-NLS-1$ } return messages.templateVersionNameAndNumber(template.getTemplateVersionName() != null ? template.getTemplateVersionName() : "", //$NON-NLS-1$ template.getTemplateVersionNumber()); } }
/** * Check if template is base template or version of a template * @return true if template is a base template, and false if its a version of a template */ public boolean isBaseTemplate() { return getId().equals(getBaseTemplateId()); }
staticVm.setVmtGuid(entity.getId()); staticVm.setClusterId(entity.getClusterId()); staticVm.setOsId(entity.getOsId()); staticVm.setNiceLevel(entity.getNiceLevel()); staticVm.setCpuShares(entity.getCpuShares()); staticVm.setStateless(entity.isStateless()); staticVm.setDeleteProtected(entity.isDeleteProtected()); staticVm.setSsoMethod(entity.getSsoMethod()); staticVm.setVmType(entity.getVmType()); staticVm.setIsoPath(entity.getIsoPath()); staticVm.setKernelUrl(entity.getKernelUrl()); staticVm.setKernelParams(entity.getKernelParams()); staticVm.setInitrdUrl(entity.getInitrdUrl()); staticVm.setTimeZone(entity.getTimeZone()); staticVm.setAllowConsoleReconnect(entity.isAllowConsoleReconnect()); staticVm.setVncKeyboardLayout(entity.getVncKeyboardLayout()); staticVm.setVmInit(entity.getVmInit()); staticVm.setSerialNumberPolicy(entity.getSerialNumberPolicy()); staticVm.setCustomSerialNumber(entity.getCustomSerialNumber()); staticVm.setSpiceFileTransferEnabled(entity.isSpiceFileTransferEnabled()); staticVm.setSpiceCopyPasteEnabled(entity.isSpiceCopyPasteEnabled()); staticVm.setRunAndPause(entity.isRunAndPause()); staticVm.setCpuProfileId(entity.getCpuProfileId()); staticVm.setAutoConverge(entity.getAutoConverge()); staticVm.setMigrateCompressed(entity.getMigrateCompressed()); staticVm.setCustomProperties(entity.getCustomProperties()); staticVm.setCustomEmulatedMachine(entity.getCustomEmulatedMachine()); staticVm.setCustomCpuName(entity.getCustomCpuName()); staticVm.setConsoleDisconnectAction(entity.getConsoleDisconnectAction());
@Override public VmTemplate mapRow(ResultSet rs, int rowNum) throws SQLException { final VmTemplate entity = new VmTemplate(); map(rs, entity); entity.setId(getGuidDefaultEmpty(rs, "vmt_guid")); entity.setChildCount(rs.getInt("child_count")); entity.setName(rs.getString("name")); entity.setClusterId(getGuid(rs, "cluster_id")); entity.setStatus(VmTemplateStatus.forValue(rs.getInt("status"))); entity.setClusterName(rs.getString("cluster_name")); entity.setClusterCompatibilityVersion(new VersionRowMapper("cluster_compatibility_version").mapRow(rs, rowNum)); entity.setStoragePoolId(getGuid(rs, "storage_pool_id")); entity.setStoragePoolName(rs.getString("storage_pool_name")); entity.setQuotaName(rs.getString("quota_name")); entity.setQuotaEnforcementType(QuotaEnforcementTypeEnum.forValue(rs.getInt("quota_enforcement_type"))); entity.setDisabled(rs.getBoolean("is_disabled")); entity.setTrustedService(rs.getBoolean("trusted_service")); entity.setTemplateType(VmEntityType.valueOf(rs.getString("entity_type"))); entity.setClusterArch(ArchitectureType.forValue(rs.getInt("architecture"))); entity.setBaseTemplateId(getGuidDefaultEmpty(rs, "base_template_id")); entity.setTemplateVersionNumber(rs.getInt("template_version_number")); entity.setTemplateVersionName(rs.getString("template_version_name")); return entity; } }
static VmTemplate setUpEntityExpectations(VmTemplate entity, int index) { when(entity.getId()).thenReturn(GUIDS[index]); when(entity.getClusterId()).thenReturn(GUIDS[2]); when(entity.getName()).thenReturn(NAMES[index]); when(entity.getDescription()).thenReturn(DESCRIPTIONS[index]); when(entity.getNumOfCpus()).thenReturn(8); when(entity.getNumOfSockets()).thenReturn(2); when(entity.getThreadsPerCpu()).thenReturn(1); when(entity.getCpuPerSocket()).thenReturn(4); if(index == 2) { when(entity.getTemplateVersionName()).thenReturn(VERSION_NAME); when(entity.getTemplateVersionNumber()).thenReturn(2); when(entity.getBaseTemplateId()).thenReturn(GUIDS[1]); when(entity.isBaseTemplate()).thenReturn(false); } else { when(entity.getTemplateVersionNumber()).thenReturn(1); // same base template id as the template itself when(entity.getBaseTemplateId()).thenReturn(GUIDS[index]); when(entity.isBaseTemplate()).thenReturn(true); } when(entity.getSmallIconId()).thenReturn(GUIDS[2]); when(entity.getLargeIconId()).thenReturn(GUIDS[3]); return entity; }
@Override protected void writeGeneralData() { super.writeGeneralData(); _writer.writeElement(TEMPLATE_ID, template.getId().toString()); OriginType originType = template.getOrigin(); _writer.writeElement(ORIGIN, originType == null ? "" : String.valueOf(originType.getValue())); _writer.writeElement(VM_DEFAULT_DISPLAY_TYPE, String.valueOf(template.getDefaultDisplayType().getValue())); _writer.writeElement(IS_DISABLED, String.valueOf(template.isDisabled())); _writer.writeElement(TRUSTED_SERVICE, String.valueOf(template.isTrustedService())); _writer.writeElement(TEMPLATE_TYPE, template.getTemplateType().name()); _writer.writeElement(BASE_TEMPLATE_ID, template.getBaseTemplateId().toString()); _writer.writeElement(TEMPLATE_VERSION_NUMBER, String.valueOf(template.getTemplateVersionNumber())); _writer.writeElement(TEMPLATE_VERSION_NAME, template.getTemplateVersionName()); }
@Override public Object getQueryableId() { return getId(); }
@Override protected void readGeneralData(XmlNode content) { super.readGeneralData(content); consumeReadProperty(content, TEMPLATE_ID, val -> _vmTemplate.setId(new Guid(val))); consumeReadProperty(content, IS_DISABLED, val -> _vmTemplate.setDisabled(Boolean.parseBoolean(val))); consumeReadProperty(content, TRUSTED_SERVICE, val -> _vmTemplate.setTrustedService(Boolean.parseBoolean(val))); consumeReadProperty(content, TEMPLATE_TYPE, val -> _vmTemplate.setTemplateType(VmEntityType.valueOf(val))); consumeReadProperty(content, BASE_TEMPLATE_ID, val -> _vmTemplate.setBaseTemplateId(Guid.createGuidFromString(val)), () -> { // in case base template is missing, we assume it is a base template _vmTemplate.setBaseTemplateId(_vmTemplate.getId()); }); consumeReadProperty(content, TEMPLATE_VERSION_NUMBER, val -> _vmTemplate.setTemplateVersionNumber(Integer.parseInt(val))); consumeReadProperty(content, TEMPLATE_VERSION_NAME, val -> _vmTemplate.setTemplateVersionName(val)); consumeReadProperty(content, AUTO_STARTUP, val -> _vmTemplate.setAutoStartup(Boolean.parseBoolean(val))); }
if (entity.getVmInit() != null) { model.setInitialization(InitializationMapper.map(entity.getVmInit(), null)); if (entity.getStatus() != null) { model.setStatus(mapTemplateStatus(entity.getStatus())); if (entity.getDefaultBootSequence() != null || entity.getKernelUrl() != null || entity.getInitrdUrl() != null || entity.getKernelParams() != null) { OperatingSystem os = new OperatingSystem(); os.setType(SimpleDependencyInjector.getInstance().get(OsRepository.class).getUniqueOsNames().get(entity.getOsId())); if (entity.getDefaultBootSequence() != null) { Boot boot = VmMapper.map(entity.getDefaultBootSequence(), null); os.setBoot(boot); os.setKernel(entity.getKernelUrl()); os.setInitrd(entity.getInitrdUrl()); os.setCmdline(entity.getKernelParams()); model.setOs(os); if (entity.getClusterArch() != null) { model.getCpu().setArchitecture(CPUMapper.map(entity.getClusterArch(), null)); model.getDisplay().setDisconnectAction(map(entity.getConsoleDisconnectAction(), null).toString()); version.setVersionName(entity.getTemplateVersionName());
protected org.ovirt.engine.core.common.businessentities.VmTemplate getTemplateEntity() { VmTemplate entity = mock(VmTemplate.class); when(entity.getId()).thenReturn(GUIDS[1]); when(entity.getClusterId()).thenReturn(GUIDS[2]); when(entity.getName()).thenReturn(NAMES[1]); when(entity.getDescription()).thenReturn(DESCRIPTIONS[1]); when(entity.getNumOfCpus()).thenReturn(8); when(entity.getNumOfSockets()).thenReturn(2); when(entity.getDefaultDisplayType()).thenReturn(DisplayType.vga); when(entity.getNumOfMonitors()).thenReturn(2); when(entity.getVmType()).thenReturn(VmType.Server); return entity; }
@Override protected MapSqlParameterSource createFullParametersMapper(VmTemplate template) { return createBaseParametersMapper(template) .addValue("child_count", template.getChildCount()) .addValue("name", template.getName()) .addValue("status", template.getStatus()) .addValue("is_disabled", template.isDisabled()) .addValue("template_type", template.getTemplateType().name()) .addValue("base_template_id", template.getBaseTemplateId()) .addValue("template_version_name", template.getTemplateVersionName()); }
@Override protected VmTemplate generateNewEntity() { VmTemplate newVmTemplate = new VmTemplate(); newVmTemplate.setId(Guid.newGuid()); newVmTemplate.setName("NewVmTemplate"); newVmTemplate.setClusterId(FixturesTool.CLUSTER); newVmTemplate.setClusterArch(ArchitectureType.x86_64); newVmTemplate.setCpuProfileId(FixturesTool.CPU_PROFILE_2); newVmTemplate.setSmallIconId(FixturesTool.SMALL_ICON_ID); newVmTemplate.setLargeIconId(FixturesTool.LARGE_ICON_ID); return newVmTemplate; }
@Override protected void readGeneralData(XmlNode content) { super.readGeneralData(content); consumeReadProperty(content, IS_DISABLED, val -> template.setDisabled(Boolean.parseBoolean(val))); consumeReadProperty(content, TRUSTED_SERVICE, val -> template.setTrustedService(Boolean.parseBoolean(val))); consumeReadProperty(content, TEMPLATE_TYPE, val -> template.setTemplateType(VmEntityType.valueOf(val))); consumeReadProperty(content, BASE_TEMPLATE_ID, val -> template.setBaseTemplateId(Guid.createGuidFromString(val)), // in case base template is missing, we assume it is a base template () -> template.setBaseTemplateId(template.getId())); consumeReadProperty(content, TEMPLATE_VERSION_NUMBER, val -> template.setTemplateVersionNumber(Integer.parseInt(val))); consumeReadProperty(content, TEMPLATE_VERSION_NAME, val -> template.setTemplateVersionName(val)); }
private void initTemplate() { // Update model state according to VM properties. buildModel(template, (source, destination) -> { updateTimeZone(template.getTimeZone()); // Storage domain and provisioning are not available for an existing VM. getModel().getStorageDomain().setIsChangeable(false); getModel().getProvisioning().setIsAvailable(false); // Select display protocol. DisplayType displayType = template.getDefaultDisplayType(); if (getModel().getDisplayType().getItems().contains(displayType)) { getModel().getDisplayType().setSelectedItem(displayType); } updateConsoleDevice(template.getId()); toggleAutoSetVmHostname(); getModel().getVmInitEnabled().setEntity(template.getVmInit() != null); getModel().getVmInitModel().init(template); getModel().getTemplateVersionName().setEntity(template.getTemplateVersionName()); getModel().getBootMenuEnabled().setEntity(template.isBootMenuEnabled()); getModel().getSpiceFileTransferEnabled().setEntity(template.isSpiceFileTransferEnabled()); getModel().getSpiceCopyPasteEnabled().setEntity(template.isSpiceCopyPasteEnabled()); getModel().getMigrationMode().setSelectedItem(template.getMigrationSupport()); initPriority(template.getPriority()); getModel().updateResumeBehavior(); }); }
static org.ovirt.engine.core.common.businessentities.VmTemplate setUpEntityExpectations( org.ovirt.engine.core.common.businessentities.VmTemplate entity, int index) { entity.setId(GUIDS[index]); entity.setClusterId(GUIDS[2]); entity.setName(NAMES[index]); entity.setDescription(DESCRIPTIONS[index]); entity.setCpuPerSocket(4); entity.setNumOfSockets(2); entity.setDefaultDisplayType(DisplayType.qxl); entity.setNumOfMonitors(2); entity.setVmType(VmType.Server); return entity; }
@Override public SafeHtml getName(VmTemplate item) { SafeHtmlBuilder builder = new SafeHtmlBuilder(); builder.append(super.getName(item)); if (!item.getId().equals(item.getBaseTemplateId())) { if (item.getTemplateVersionName() != null) { builder.appendEscaped("/"); // $NON-NLS-1$ builder.appendEscaped(item.getTemplateVersionName()); } builder.appendEscaped(" ("); // $NON-NLS-1$ builder.append(item.getTemplateVersionNumber()); builder.appendEscaped(")"); // $NON-NLS-1$ } return builder.toSafeHtml(); } }
this.setStatus(VmTemplateStatus.forValue(status)); setTemplateType(templateType); setBaseTemplateId(baseTemplateId); setTemplateVersionNumber(BASE_VERSION_NUMBER); setTemplateVersionName(templateVersionName); setDescription(this.getDescription());
getModel().getIsSoundcardEnabled().setIsChangeable(true); getModel().getVmType().setIsChangeable(true); getModel().getTemplateVersionName().setIsChangeable(!template.isBaseTemplate()); getModel().getName().setIsChangeable(template.isBaseTemplate()); if (template.getStoragePoolId() != null && !template.getStoragePoolId().equals(Guid.Empty)) { AsyncDataProvider.getInstance().getDataCenterById(new AsyncQuery<>( dataCenter -> AsyncDataProvider.getInstance().getClusterListByService( template.getClusterArch()); template.getClusterId()); updateRngDevice(template.getId()); initTemplate(); initCdImage(); }), template.getId()); Frontend.getInstance().runQuery(QueryType.IsBalloonEnabled, new IdQueryParameters(template.getId()), new AsyncQuery<>( (QueryReturnValue returnValue) -> getModel().getMemoryBalloonDeviceEnabled().setEntity((Boolean) returnValue.getReturnValue()) returnValue -> getModel().getIsVirtioScsiEnabled().setEntity(returnValue)), template.getId()); }), true, false)), template.getStoragePoolId());