Search in sources :

Example 1 with VmDeviceId

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);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) HashSet(java.util.HashSet)

Example 2 with VmDeviceId

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;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 3 with VmDeviceId

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;
}
Also used : ArrayList(java.util.ArrayList) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 4 with VmDeviceId

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());
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) Guid(org.ovirt.engine.core.compat.Guid) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) Test(org.junit.Test)

Example 5 with VmDeviceId

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;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Aggregations

VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)75 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)40 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)21 Guid (org.ovirt.engine.core.compat.Guid)19 HashMap (java.util.HashMap)13 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)12 Test (org.junit.Test)10 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)9 ArrayList (java.util.ArrayList)7 Map (java.util.Map)5 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)5 VM (org.ovirt.engine.core.common.businessentities.VM)5 VmPayload (org.ovirt.engine.core.common.businessentities.VmPayload)4 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)4 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)4 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)3 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)3 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)3