use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.
the class OvfReader method readGeneralData.
protected void readGeneralData(XmlNode content) {
vmBase.setVmInit(new VmInit());
consumeReadProperty(content, DESCRIPTION, val -> vmBase.setDescription(val));
consumeReadProperty(content, COMMENT, val -> vmBase.setComment(val));
consumeReadProperty(content, DOMAIN, val -> vmBase.getVmInit().setDomain(val));
consumeReadProperty(content, CREATION_DATE, val -> vmBase.setCreationDate(OvfParser.utcDateStringToLocalDate(val)));
consumeReadProperty(content, EXPORT_DATE, val -> vmBase.setExportDate(OvfParser.utcDateStringToLocalDate(val)));
consumeReadProperty(content, DEFAULT_BOOT_SEQUENCE, val -> vmBase.setDefaultBootSequence(BootSequence.forValue(Integer.parseInt(val))));
consumeReadProperty(content, INITRD_URL, val -> vmBase.setInitrdUrl(val));
consumeReadProperty(content, KERNEL_URL, val -> vmBase.setKernelUrl(val));
consumeReadProperty(content, KERNEL_PARAMS, val -> vmBase.setKernelParams(val));
consumeReadProperty(content, GENERATION, val -> vmBase.setDbGeneration(Long.parseLong(val)), () -> vmBase.setDbGeneration(1L));
XmlNode node = selectSingleNode(content, CUSTOM_COMPATIBILITY_VERSION);
if (node != null) {
vmBase.setCustomCompatibilityVersion(new Version(node.innerText));
}
// the originating ENGINE version
Version originVersion = new Version(getVersion());
node = selectSingleNode(content, CLUSTER_COMPATIBILITY_VERSION);
if (node != null) {
originVersion = new Version(node.innerText);
}
vmBase.setClusterCompatibilityVersionOrigin(originVersion);
// Note: the fetching of 'default display type' should happen before reading
// the hardware section
consumeReadProperty(content, getDefaultDisplayTypeStringRepresentation(), val -> vmBase.setDefaultDisplayType(DisplayType.forValue(Integer.parseInt(val))));
// after reading the hardware section, if graphics device is still absent, add a default one
addDefaultGraphicsDevice();
fixDiskVmElements();
// due to dependency on vmBase.getOsId() must be read AFTER readOsSection
consumeReadProperty(content, TIMEZONE, val -> vmBase.setTimeZone(val), () -> {
if (osRepository.isWindows(vmBase.getOsId())) {
vmBase.setTimeZone(Config.getValue(ConfigValues.DefaultWindowsTimeZone));
} else {
vmBase.setTimeZone(Config.getValue(ConfigValues.DefaultGeneralTimeZone));
}
});
consumeReadProperty(content, ORIGIN, val -> vmBase.setOrigin(OriginType.forValue(Integer.parseInt(val))));
consumeReadProperty(content, VM_TYPE, val -> vmBase.setVmType(VmType.forValue(Integer.parseInt(val))));
consumeReadProperty(content, RESUME_BEHAVIOR, val -> vmBase.setResumeBehavior(VmResumeBehavior.valueOf(val)));
consumeReadProperty(content, IS_SMARTCARD_ENABLED, val -> vmBase.setSmartcardEnabled(Boolean.parseBoolean(val)));
consumeReadProperty(content, NUM_OF_IOTHREADS, val -> vmBase.setNumOfIoThreads(Integer.parseInt(val)));
consumeReadProperty(content, DELETE_PROTECTED, val -> vmBase.setDeleteProtected(Boolean.parseBoolean(val)));
consumeReadProperty(content, SSO_METHOD, val -> vmBase.setSsoMethod(SsoMethod.fromString(val)));
consumeReadProperty(content, TUNNEL_MIGRATION, val -> vmBase.setTunnelMigration(Boolean.parseBoolean(val)));
consumeReadProperty(content, VNC_KEYBOARD_LAYOUT, val -> vmBase.setVncKeyboardLayout(val));
consumeReadProperty(content, MIN_ALLOCATED_MEMORY, val -> vmBase.setMinAllocatedMem(Integer.parseInt(val)));
consumeReadProperty(content, IS_STATELESS, val -> vmBase.setStateless(Boolean.parseBoolean(val)));
consumeReadProperty(content, IS_RUN_AND_PAUSE, val -> vmBase.setRunAndPause(Boolean.parseBoolean(val)));
consumeReadProperty(content, CREATED_BY_USER_ID, val -> vmBase.setCreatedByUserId(Guid.createGuidFromString(val)));
consumeReadProperty(content, MIGRATION_DOWNTIME, val -> vmBase.setMigrationDowntime(Integer.parseInt(val)));
consumeReadProperty(content, MIGRATION_SUPPORT, val -> vmBase.setMigrationSupport(MigrationSupport.forValue(Integer.parseInt(val))));
// TODO dedicated to multiple hosts
readDedicatedHostsList();
consumeReadProperty(content, SERIAL_NUMBER_POLICY, val -> vmBase.setSerialNumberPolicy(SerialNumberPolicy.forValue(Integer.parseInt(val))));
consumeReadProperty(content, CUSTOM_SERIAL_NUMBER, val -> vmBase.setCustomSerialNumber(val));
consumeReadProperty(content, AUTO_STARTUP, val -> vmBase.setAutoStartup(Boolean.parseBoolean(val)));
consumeReadProperty(content, PRIORITY, val -> vmBase.setPriority(Integer.parseInt(val)));
consumeReadProperty(content, IS_BOOT_MENU_ENABLED, val -> vmBase.setBootMenuEnabled(Boolean.parseBoolean(val)));
consumeReadProperty(content, IS_SPICE_FILE_TRANSFER_ENABLED, val -> vmBase.setSpiceFileTransferEnabled(Boolean.parseBoolean(val)));
consumeReadProperty(content, IS_SPICE_COPY_PASTE_ENABLED, val -> vmBase.setSpiceCopyPasteEnabled(Boolean.parseBoolean(val)));
consumeReadProperty(content, ALLOW_CONSOLE_RECONNECT, val -> vmBase.setAllowConsoleReconnect(Boolean.parseBoolean(val)));
consumeReadProperty(content, CONSOLE_DISCONNECT_ACTION, val -> vmBase.setConsoleDisconnectAction(ConsoleDisconnectAction.fromString(val)));
consumeReadProperty(content, IS_AUTO_CONVERGE, val -> vmBase.setAutoConverge(Boolean.parseBoolean(val)));
consumeReadProperty(content, IS_MIGRATE_COMPRESSED, val -> vmBase.setMigrateCompressed(Boolean.parseBoolean(val)));
consumeReadProperty(content, MIGRATION_POLICY_ID, val -> vmBase.setMigrationPolicyId(Guid.createGuidFromString(val)));
consumeReadProperty(content, CUSTOM_EMULATED_MACHINE, val -> vmBase.setCustomEmulatedMachine(val));
consumeReadProperty(content, CUSTOM_CPU_NAME, val -> vmBase.setCustomCpuName(val));
consumeReadProperty(content, PREDEFINED_PROPERTIES, val -> vmBase.setPredefinedProperties(val));
consumeReadProperty(content, USER_DEFINED_PROPERTIES, val -> vmBase.setUserDefinedProperties(val));
consumeReadProperty(content, MAX_MEMORY_SIZE_MB, val -> vmBase.setMaxMemorySizeMb(Integer.parseInt(val)));
vmBase.setCustomProperties(VmPropertiesUtils.getInstance().customProperties(vmBase.getPredefinedProperties(), vmBase.getUserDefinedProperties()));
consumeReadProperty(content, VM_LEASE, val -> vmBase.setLeaseStorageDomainId(new Guid(val)));
readVmInit(content);
}
use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.
the class OvfReader method setDeviceByResource.
private void setDeviceByResource(XmlNode node, VmDevice vmDevice) {
String resourceType = selectSingleNode(node, VMD_RESOURCE_TYPE, _xmlNS).innerText;
XmlNode resourceSubTypeNode = selectSingleNode(node, VMD_SUB_RESOURCE_TYPE, _xmlNS);
if (resourceSubTypeNode == null) {
// we need special handling for Monitor to define it as vnc or spice
if (OvfHardware.Monitor.equals(adjustHardwareResourceType(resourceType))) {
// get number of monitors from VirtualQuantity in OVF
if (selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS).innerText)) {
int virtualQuantity = Integer.parseInt(selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS).innerText);
if (virtualQuantity > 1) {
vmDevice.setDevice(VmDeviceType.QXL.getName());
} else {
// get first supported display device
List<Pair<GraphicsType, DisplayType>> supportedGraphicsAndDisplays = osRepository.getGraphicsAndDisplays(vmBase.getOsId(), new Version(getVersion()));
if (!supportedGraphicsAndDisplays.isEmpty()) {
DisplayType firstDisplayType = supportedGraphicsAndDisplays.get(0).getSecond();
vmDevice.setDevice(firstDisplayType.getDefaultVmDeviceType().getName());
} else {
vmDevice.setDevice(VmDeviceType.QXL.getName());
}
}
} else {
// default to spice if quantity not found
vmDevice.setDevice(VmDeviceType.QXL.getName());
}
} else {
vmDevice.setDevice(VmDeviceType.getoVirtDevice(Integer.parseInt(resourceType)).getName());
}
} else if (OvfHardware.Network.equals(resourceType)) {
// handle interfaces with different sub types : we have 0-5 as the VmInterfaceType enum
Integer nicTypeValue = getVmInterfaceType(resourceSubTypeNode);
VmInterfaceType nicType = nicTypeValue != null ? VmInterfaceType.forValue(nicTypeValue) : null;
if (nicType != null) {
if (nicType == VmInterfaceType.pciPassthrough) {
vmDevice.setDevice(VmDeviceType.HOST_DEVICE.getName());
} else {
vmDevice.setDevice(VmDeviceType.BRIDGE.getName());
}
} else {
vmDevice.setDevice(VmDeviceType.getoVirtDevice(Integer.parseInt(resourceType)).getName());
}
}
}
use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.
the class OvfReader method addDefaultGraphicsDevice.
private void addDefaultGraphicsDevice() {
VmDevice device = VmDeviceCommonUtils.findVmDeviceByGeneralType(vmBase.getManagedDeviceMap(), VmDeviceGeneralType.GRAPHICS);
if (device != null) {
return;
}
List<Pair<GraphicsType, DisplayType>> graphicsAndDisplays = osRepository.getGraphicsAndDisplays(vmBase.getOsId(), new Version(getVersion()));
GraphicsType graphicsType = vmBase.getDefaultDisplayType() == DisplayType.cirrus ? GraphicsType.VNC : GraphicsType.SPICE;
GraphicsType supportedGraphicsType = null;
for (Pair<GraphicsType, DisplayType> pair : graphicsAndDisplays) {
if (pair.getSecond() == vmBase.getDefaultDisplayType()) {
if (pair.getFirst() == graphicsType) {
supportedGraphicsType = graphicsType;
break;
}
if (supportedGraphicsType == null) {
supportedGraphicsType = pair.getFirst();
}
}
}
if (supportedGraphicsType != null) {
device = new GraphicsDevice(supportedGraphicsType.getCorrespondingDeviceType());
device.setId(new VmDeviceId(Guid.newGuid(), vmBase.getId()));
addManagedVmDevice(device);
} else {
log.warn("Cannot find any graphics type for display type {} supported by OS {} in compatibility version {}", vmBase.getDefaultDisplayType().name(), osRepository.getOsName(vmBase.getOsId()), getVersion());
}
}
use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.
the class AsyncDataProvider method initCpuMap.
private void initCpuMap() {
cpuMap = new HashMap<>();
final List<QueryType> queryTypes = new ArrayList<>();
final List<QueryParametersBase> queryParams = new ArrayList<>();
for (Version version : Version.ALL) {
queryTypes.add(QueryType.GetAllServerCpuList);
queryParams.add(new GetAllServerCpuListParameters(version));
}
final IFrontendMultipleQueryAsyncCallback callback = result -> {
for (int i = 0; i < result.getReturnValues().size(); i++) {
final List<ServerCpu> cpus = result.getReturnValues().get(i).getReturnValue();
final Version version = ((GetAllServerCpuListParameters) result.getParameters().get(i)).getVersion();
initCpuMapForVersion(version, cpus);
}
};
Frontend.getInstance().runMultipleQueries(queryTypes, queryParams, callback);
}
use of org.ovirt.engine.core.compat.Version in project ovirt-engine by oVirt.
the class VmModelBehaviorBase method updateCompatibilityVersion.
/*
* Updates the custom compatibility version combo box options on init/DC-change
*/
protected void updateCompatibilityVersion() {
DataCenterWithCluster dataCenterWithCluster = getModel().getDataCenterWithClustersList().getSelectedItem();
if (dataCenterWithCluster == null) {
return;
}
final StoragePool dataCenter = dataCenterWithCluster.getDataCenter();
if (dataCenter == null) {
return;
}
AsyncDataProvider.getInstance().getDataCenterVersions(new AsyncQuery<>(versions -> {
versions.add(0, null);
Version selectedVersion;
selectedVersion = getModel().getCustomCompatibilityVersion().getSelectedItem();
if (selectedVersion != null && versions.contains(selectedVersion)) {
getModel().getCustomCompatibilityVersion().setItems(versions, selectedVersion);
} else {
getModel().getCustomCompatibilityVersion().setItems(versions);
}
}), dataCenter.getId());
}
Aggregations