use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class ProcessDownVmCommand method createUpdateVmParameters.
private VmManagementParametersBase createUpdateVmParameters() {
// clear non updateable fields got from config
getVm().setExportDate(null);
getVm().setOvfVersion(null);
VmManagementParametersBase updateVmParams = new VmManagementParametersBase(getVm());
updateVmParams.setUpdateWatchdog(true);
updateVmParams.setSoundDeviceEnabled(false);
updateVmParams.setBalloonEnabled(false);
updateVmParams.setVirtioScsiEnabled(false);
updateVmParams.setClearPayload(true);
updateVmParams.setUpdateRngDevice(true);
for (GraphicsType graphicsType : GraphicsType.values()) {
updateVmParams.getGraphicsDevices().put(graphicsType, null);
}
for (VmDevice device : getVm().getManagedVmDeviceMap().values()) {
switch(device.getType()) {
case WATCHDOG:
updateVmParams.setWatchdog(new VmWatchdog(device));
break;
case SOUND:
updateVmParams.setSoundDeviceEnabled(true);
break;
case BALLOON:
updateVmParams.setBalloonEnabled(true);
break;
case CONTROLLER:
if (VmDeviceType.VIRTIOSCSI.getName().equals(device.getDevice())) {
updateVmParams.setVirtioScsiEnabled(true);
}
break;
case DISK:
if (VmPayload.isPayload(device.getSpecParams())) {
updateVmParams.setVmPayload(new VmPayload(device));
}
break;
case CONSOLE:
updateVmParams.setConsoleEnabled(true);
break;
case RNG:
updateVmParams.setRngDevice(new VmRngDevice(device));
break;
case GRAPHICS:
updateVmParams.getGraphicsDevices().put(GraphicsType.fromString(device.getDevice()), new GraphicsDevice(device));
break;
default:
}
}
// clear these fields as these are non updatable
getVm().getManagedVmDeviceMap().clear();
getVm().getUnmanagedDeviceList().clear();
return updateVmParams;
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class VmDeviceUtils method copyVmDevices.
/**
* Copy devices from the given VmDevice list to the destination VM/VmBase.
*/
public void copyVmDevices(Guid srcId, Guid dstId, VmBase srcVmBase, VmBase dstVmBase, List<VmDevice> srcDevices, Map<Guid, Guid> srcDeviceIdToDstDeviceIdMapping, boolean isSoundEnabled, boolean isConsoleEnabled, Boolean isVirtioScsiEnabled, boolean isBalloonEnabled, Set<GraphicsType> graphicsToSkip, boolean copySnapshotDevices, boolean copyHostDevices, Version versionToUpdateRngDeviceWith) {
if (graphicsToSkip == null) {
graphicsToSkip = Collections.emptySet();
}
String dstCdPath = dstVmBase.getIsoPath();
boolean dstIsVm = !(dstVmBase instanceof VmTemplate);
boolean hasCd = hasCdDevice(dstVmBase.getId());
boolean hasSound = false;
boolean hasConsole = false;
boolean hasVirtioScsi = false;
boolean hasBalloon = false;
boolean hasRng = hasRngDevice(dstId);
Cluster cluster = null;
if (dstVmBase.getClusterId() != null) {
cluster = clusterDao.get(dstVmBase.getClusterId());
}
for (VmDevice device : srcDevices) {
if (device.getSnapshotId() != null && !copySnapshotDevices) {
continue;
}
Guid deviceId = Guid.newGuid();
Map<String, Object> specParams = new HashMap<>();
switch(device.getType()) {
case DISK:
if (VmDeviceType.DISK.getName().equals(device.getDevice())) {
if (srcDeviceIdToDstDeviceIdMapping.containsKey(device.getDeviceId())) {
deviceId = srcDeviceIdToDstDeviceIdMapping.get(device.getDeviceId());
}
} else if (VmDeviceType.CDROM.getName().equals(device.getDevice())) {
if (!hasCd) {
hasCd = true;
// check here is source VM had CD (VM from snapshot)
String srcCdPath = (String) device.getSpecParams().get(VdsProperties.Path);
specParams.putAll(getCdDeviceSpecParams(srcCdPath, dstCdPath));
} else {
// CD already exists
continue;
}
}
break;
case INTERFACE:
if (srcDeviceIdToDstDeviceIdMapping.containsKey(device.getDeviceId())) {
deviceId = srcDeviceIdToDstDeviceIdMapping.get(device.getDeviceId());
}
break;
case CONTROLLER:
if (VmDeviceType.USB.getName().equals(device.getDevice())) {
specParams = device.getSpecParams();
} else if (VmDeviceType.VIRTIOSCSI.getName().equals(device.getDevice())) {
hasVirtioScsi = true;
if (Boolean.FALSE.equals(isVirtioScsiEnabled)) {
continue;
}
}
break;
case VIDEO:
if (dstIsVm) {
// to the new Vm params.
continue;
}
specParams.putAll(getVideoDeviceSpecParams(dstVmBase));
break;
case BALLOON:
if (!isBalloonEnabled) {
continue;
}
hasBalloon = true;
specParams.putAll(getMemoryBalloonSpecParams());
break;
case SMARTCARD:
specParams.putAll(getSmartcardDeviceSpecParams());
break;
case WATCHDOG:
specParams.putAll(device.getSpecParams());
break;
case RNG:
if (hasRng) {
continue;
}
if (!new VirtIoRngValidator().canAddRngDevice(cluster, new VmRngDevice(device)).isValid()) {
continue;
}
final VmRngDevice rngDevice = new VmRngDevice(device);
if (versionToUpdateRngDeviceWith != null) {
rngDevice.updateSourceByVersion(versionToUpdateRngDeviceWith);
}
specParams.putAll(rngDevice.getSpecParams());
break;
case CONSOLE:
if (!isConsoleEnabled) {
continue;
}
specParams.putAll(device.getSpecParams());
hasConsole = true;
break;
case SOUND:
if (!isSoundEnabled) {
continue;
}
hasSound = true;
break;
case GRAPHICS:
GraphicsType type = GraphicsType.fromVmDeviceType(VmDeviceType.getByName(device.getDevice()));
// OR if we already have it
if (graphicsToSkip.contains(type) || hasGraphicsDevice(dstId, GraphicsType.fromString(device.getDevice()))) {
continue;
}
break;
case HOSTDEV:
if (!copyHostDevices) {
continue;
}
specParams.putAll(device.getSpecParams());
break;
default:
break;
}
device.setId(new VmDeviceId(deviceId, dstId));
device.setSpecParams(specParams);
vmDeviceDao.save(device);
}
if (!hasCd) {
addCdDevice(dstId, dstCdPath);
}
updateUsbSlots(srcVmBase, dstVmBase, () -> clusterDao.get(dstVmBase.getClusterId()));
if (isSoundEnabled && !hasSound) {
if (dstIsVm) {
addSoundDevice(dstVmBase);
} else {
addSoundDevice(dstVmBase.getId(), dstVmBase.getOsId(), cluster != null ? cluster.getCompatibilityVersion() : null);
}
}
if (isConsoleEnabled && !hasConsole) {
addConsoleDevice(dstId);
}
if (Boolean.TRUE.equals(isVirtioScsiEnabled) && !hasVirtioScsi) {
addVirtioScsiController(dstVmBase, getVmCompatibilityVersion(dstVmBase));
}
if (isBalloonEnabled && !hasBalloon) {
addMemoryBalloon(dstId);
}
if (dstIsVm) {
addVideoDevices(dstVmBase, getNeededNumberOfVideoDevices(dstVmBase));
}
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class BackendTemplatesResource method doPopulate.
@Override
protected Template doPopulate(Template model, VmTemplate entity) {
if (!model.isSetConsole()) {
model.setConsole(new Console());
}
model.getConsole().setEnabled(!getConsoleDevicesForEntity(entity.getId()).isEmpty());
if (!model.isSetVirtioScsi()) {
model.setVirtioScsi(new VirtioScsi());
}
model.getVirtioScsi().setEnabled(!VmHelper.getVirtioScsiControllersForEntity(this, entity.getId()).isEmpty());
model.setSoundcardEnabled(!VmHelper.getSoundDevicesForEntity(this, entity.getId()).isEmpty());
List<VmRngDevice> rngDevices = getRngDevices(entity.getId());
if (rngDevices != null && !rngDevices.isEmpty()) {
model.setRngDevice(RngDeviceMapper.map(rngDevices.get(0), null));
}
MemoryPolicyHelper.setupMemoryBalloon(model, this);
return model;
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class RngDeviceMapper method map.
@Mapping(from = VmRngDevice.class, to = RngDevice.class)
public static RngDevice map(VmRngDevice entity, RngDevice template) {
RngDevice model = (template == null) ? new RngDevice() : template;
if (entity.getBytes() != null) {
model.setRate(new Rate());
model.getRate().setBytes(entity.getBytes());
if (entity.getPeriod() != null) {
model.getRate().setPeriod(entity.getPeriod());
}
}
RngSource restSource = map(entity.getSource(), null);
model.setSource(restSource);
return model;
}
use of org.ovirt.engine.core.common.businessentities.VmRngDevice in project ovirt-engine by oVirt.
the class ExistingNonClusterModelBehavior method initialize.
@Override
public void initialize() {
super.initialize();
updateNumOfSockets();
getModel().getUsbPolicy().setItems(Arrays.asList(UsbPolicy.values()));
getModel().getIsSoundcardEnabled().setIsChangeable(true);
Frontend.getInstance().runQuery(QueryType.GetGraphicsDevices, new IdQueryParameters(entity.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
List<GraphicsDevice> graphicsDevices = returnValue.getReturnValue();
Set<GraphicsType> graphicsTypesCollection = new HashSet<>();
for (GraphicsDevice graphicsDevice : graphicsDevices) {
graphicsTypesCollection.add(graphicsDevice.getGraphicsType());
}
initDisplayTypes(entity.getDefaultDisplayType(), UnitVmModel.GraphicsTypes.fromGraphicsTypes(graphicsTypesCollection));
doBuild();
}));
initSoundCard(entity.getId());
updateConsoleDevice(entity.getId());
initPriority(entity.getPriority());
Frontend.getInstance().runQuery(QueryType.IsBalloonEnabled, new IdQueryParameters(entity.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> getModel().getMemoryBalloonDeviceEnabled().setEntity((Boolean) returnValue.getReturnValue())));
getInstance().isVirtioScsiEnabledForVm(new AsyncQuery<>(returnValue -> getModel().getIsVirtioScsiEnabled().setEntity(returnValue)), entity.getId());
getInstance().getWatchdogByVmId(new AsyncQuery<QueryReturnValue>(returnValue -> {
@SuppressWarnings("unchecked") Collection<VmWatchdog> watchdogs = returnValue.getReturnValue();
for (VmWatchdog watchdog : watchdogs) {
getModel().getWatchdogAction().setSelectedItem(watchdog.getAction());
getModel().getWatchdogModel().setSelectedItem(watchdog.getModel());
}
}), entity.getId());
Frontend.getInstance().runQuery(QueryType.GetRngDevice, new IdQueryParameters(entity.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
List<VmDevice> rngDevices = returnValue.getReturnValue();
getModel().getIsRngEnabled().setEntity(!rngDevices.isEmpty());
if (!rngDevices.isEmpty()) {
VmRngDevice rngDevice = new VmRngDevice(rngDevices.get(0));
getModel().setRngDevice(rngDevice);
}
}));
getModel().getEmulatedMachine().setSelectedItem(entity.getCustomEmulatedMachine());
getModel().getCustomCpu().setSelectedItem(entity.getCustomCpuName());
getModel().getMigrationMode().setSelectedItem(entity.getMigrationSupport());
getModel().getCpuSharesAmount().setEntity(entity.getCpuShares());
getModel().getIsHighlyAvailable().setEntity(entity.isAutoStartup());
updateCpuSharesSelection();
}
Aggregations