use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmDevicesMonitoring method processVmDevices.
/**
* Actually process the VM device update and store individual device additions/updates/removals
* in the <code>change</code>.
*/
private void processVmDevices(Change change, Map<String, Object> vmInfo) {
Guid vmId = getVmId(vmInfo);
Set<Guid> processedDeviceIds = new HashSet<>();
List<VmDevice> dbDevices = getVmDeviceDao().getVmDeviceByVmId(vmId);
Map<VmDeviceId, VmDevice> dbDeviceMap = Entities.businessEntitiesById(dbDevices);
for (Object o : (Object[]) vmInfo.get(VdsProperties.Devices)) {
Map<String, Object> vdsmDevice = (Map<String, Object>) o;
if (vdsmDevice.get(VdsProperties.Address) == null) {
logDeviceInformation(vmId, vdsmDevice);
continue;
}
Guid deviceId = getDeviceId(vdsmDevice);
VmDevice dbDevice = dbDeviceMap.get(new VmDeviceId(deviceId, vmId));
if (dbDevice == null) {
dbDevice = getByDeviceType((String) vdsmDevice.get(VdsProperties.Device), dbDeviceMap);
deviceId = dbDevice != null ? dbDevice.getDeviceId() : deviceId;
}
String logicalName = getDeviceLogicalName(vmInfo, vdsmDevice);
if (deviceId == null || dbDevice == null) {
VmDevice newDevice = buildNewVmDevice(vmId, vdsmDevice, logicalName);
if (newDevice != null) {
change.addDeviceToAdd(newDevice);
processedDeviceIds.add(newDevice.getDeviceId());
}
} else {
dbDevice.setPlugged(Boolean.TRUE);
dbDevice.setAddress(vdsmDevice.get(VdsProperties.Address).toString());
dbDevice.setAlias(StringUtils.defaultString((String) vdsmDevice.get(VdsProperties.Alias)));
dbDevice.setLogicalName(logicalName);
dbDevice.setHostDevice(StringUtils.defaultString((String) vdsmDevice.get(VdsProperties.HostDev)));
change.addDeviceToUpdate(dbDevice);
processedDeviceIds.add(deviceId);
}
}
handleRemovedDevices(change, vmId, processedDeviceIds, dbDevices);
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class VmDevicesMonitoring method buildNewVmDevice.
/**
* Builds a new device structure for the device recognized by libvirt.
*/
private VmDevice buildNewVmDevice(Guid vmId, Map device, String logicalName) {
String typeName = (String) device.get(VdsProperties.Type);
String deviceName = (String) device.get(VdsProperties.Device);
// do not allow null or empty device or type values
if (StringUtils.isEmpty(typeName) || StringUtils.isEmpty(deviceName)) {
log.error("Empty or NULL values were passed for a VM '{}' device, Device is skipped", vmId);
return null;
}
String address = device.get(VdsProperties.Address).toString();
String alias = StringUtils.defaultString((String) device.get(VdsProperties.Alias));
Map<String, Object> specParams = (Map<String, Object>) device.get(VdsProperties.SpecParams);
specParams = specParams != null ? specParams : new HashMap<>();
Guid newDeviceId = Guid.newGuid();
VmDeviceId id = new VmDeviceId(newDeviceId, vmId);
Object deviceReadonlyValue = device.get(VdsProperties.ReadOnly);
boolean isReadOnly = deviceReadonlyValue != null && Boolean.getBoolean(deviceReadonlyValue.toString());
VmDevice newDevice = new VmDevice(id, VmDeviceGeneralType.forValue(typeName), deviceName, address, specParams, false, true, isReadOnly, alias, null, null, logicalName);
if (VmDeviceCommonUtils.isMemory(newDevice)) {
fixMemorySpecParamsTypes(newDevice);
}
log.debug("New device was marked for adding to VM '{}' Device : '{}'", vmId, newDevice);
return newDevice;
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class OvfUpdateProcessHelper method getVmImagesFromDb.
public ArrayList<DiskImage> getVmImagesFromDb(VM vm) {
ArrayList<DiskImage> allVmImages = new ArrayList<>();
List<DiskImage> filteredDisks = DisksFilter.filterImageDisks(vm.getDiskList(), ONLY_SNAPABLE, ONLY_ACTIVE);
for (DiskImage diskImage : filteredDisks) {
allVmImages.addAll(diskImageDao.getAllSnapshotsForLeaf(diskImage.getImageId()));
}
for (DiskImage disk : allVmImages) {
DiskVmElement dve = diskVmElementDao.get(new VmDeviceId(disk.getId(), vm.getId()));
disk.setDiskVmElements(Collections.singletonList(dve));
}
return allVmImages;
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class GetWatchdogQueryTest method executeQueryCommandWithWatchdog.
@Test
public void executeQueryCommandWithWatchdog() {
Map<String, Object> watchdogSpecParams = new HashMap<>();
watchdogSpecParams.put("model", "i6300esb");
watchdogSpecParams.put("action", "reset");
VmDevice vmDevice = new VmDevice(new VmDeviceId(new Guid("6f86b8a4-e721-4149-b2df-056eb621b16a"), TEST_VM_ID), VmDeviceGeneralType.WATCHDOG, VmDeviceType.WATCHDOG.getName(), "", watchdogSpecParams, true, true, true, "", null, null, null);
when(vmDeviceDao.getVmDeviceByVmIdAndType(TEST_VM_ID, VmDeviceGeneralType.WATCHDOG)).thenReturn(Collections.singletonList(vmDevice));
getQuery().executeQueryCommand();
List<VmWatchdog> result = getQuery().getQueryReturnValue().getReturnValue();
assertNotNull(result);
assertFalse(result.isEmpty());
VmWatchdog watchdog = result.get(0);
assertEquals("reset", watchdog.getAction().name().toLowerCase());
assertEquals("i6300esb", watchdog.getModel().name().toLowerCase());
}
use of org.ovirt.engine.core.common.businessentities.VmDeviceId in project ovirt-engine by oVirt.
the class DiskImagesValidatorTest method createVmDeviceForDisk.
private VmDevice createVmDeviceForDisk(DiskImage disk) {
VmDevice device = new VmDevice();
device.setId(new VmDeviceId(null, disk.getId()));
return device;
}
Aggregations