Search in sources :

Example 66 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class GetVmPayloadQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    if (multiLevelAdministrationHandler.isAdminUser(getUser())) {
        List<VmDevice> disks = dao.getVmDeviceByVmIdAndType(getParameters().getId(), VmDeviceGeneralType.DISK);
        for (VmDevice disk : disks) {
            if (disk.isManaged() && VmPayload.isPayload(disk.getSpecParams())) {
                VmPayload payload = new VmPayload(disk);
                for (Map.Entry<String, String> entry : payload.getFiles().entrySet()) {
                    entry.setValue(new String(Base64.decodeBase64(entry.getValue())));
                }
                getQueryReturnValue().setReturnValue(payload);
            }
        }
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Map(java.util.Map)

Example 67 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class AddVmHostDevicesCommand method executeCommand.

@Override
protected void executeCommand() {
    Set<HostDevice> affectedHostDevices = getAffectedHostDevices();
    Map<String, VmHostDevice> existingDevices = getExistingVmHostDevicesByName();
    List<VmDevice> devicesToAdd = new ArrayList<>();
    List<VmDevice> devicesToUpdate = new ArrayList<>();
    for (HostDevice hostDevice : affectedHostDevices) {
        if (!existingDevices.containsKey(hostDevice.getDeviceName())) {
            VmHostDevice device = new VmHostDevice(getVmId(), hostDevice);
            // if the device was not explicitly intended by the user (only added due to the IOMMU group
            // we mark it as as placeholder
            boolean required = getPrimaryDeviceNames().contains(device.getDevice());
            device.setIommuPlaceholder(!required);
            devicesToAdd.add(device);
        } else {
            VmHostDevice device = new VmHostDevice(existingDevices.get(hostDevice.getDeviceName()));
            // as it is now explicitly requested by the user
            if (getPrimaryDeviceNames().contains(device.getDevice()) && device.isIommuPlaceholder()) {
                device.setIommuPlaceholder(false);
                devicesToUpdate.add(device);
            }
        }
    }
    vmDeviceDao.saveAllInBatch(devicesToAdd);
    vmDeviceDao.updateAllInBatch(devicesToUpdate);
    setSucceeded(true);
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) ArrayList(java.util.ArrayList) VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice)

Example 68 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class SnapshotsManager method attempToRestoreVmConfigurationFromSnapshot.

/**
 * Attempt to read the configuration that is stored in the snapshot, and restore the VM from it.<br>
 * The NICs and Disks will be restored from the configuration (if available).<br>
 * <br>
 * <b>Note:</b>If the configuration is <code>null</code> or can't be decoded, then the VM configuration will remain
 * as it was but the underlying storage would still have changed..
 *
 * @param snapshot
 *            The snapshot containing the configuration.
 * @param user
 *            The user that performs the action
 * @param vmInterfaceManager vmInterfaceManager instance
 */
public void attempToRestoreVmConfigurationFromSnapshot(VM vm, Snapshot snapshot, Guid activeSnapshotId, List<DiskImage> images, CompensationContext compensationContext, DbUser user, VmInterfaceManager vmInterfaceManager, boolean withMemory) {
    boolean vmUpdatedFromConfiguration = false;
    if (snapshot.getVmConfiguration() != null) {
        vmUpdatedFromConfiguration = updateVmFromConfiguration(vm, snapshot.getVmConfiguration());
        if (images != null) {
            vmUpdatedFromConfiguration &= updateImagesByConfiguration(vm, images);
        }
    }
    if (!vmUpdatedFromConfiguration) {
        if (images == null) {
            images = diskImageDao.getAllSnapshotsForVmSnapshot(snapshot.getId());
        }
        vm.setImages(new ArrayList<>(images));
    }
    vm.setAppList(snapshot.getAppList());
    vmDynamicDao.update(vm.getDynamicData());
    synchronizeDisksFromSnapshot(vm.getId(), snapshot.getId(), activeSnapshotId, vm.getImages(), vm.getName());
    if (vmUpdatedFromConfiguration) {
        vmStaticDao.update(vm.getStaticData());
        boolean macsInSnapshotAreExpectedToBeAlreadyAllocated = SnapshotType.STATELESS.equals(snapshot.getType());
        synchronizeNics(vm, compensationContext, user, vmInterfaceManager, macsInSnapshotAreExpectedToBeAlreadyAllocated);
        for (VmDevice vmDevice : vmDeviceDao.getVmDeviceByVmId(vm.getId())) {
            if (deviceCanBeRemoved(vmDevice)) {
                vmDeviceDao.remove(vmDevice.getId());
            }
        }
        vmDeviceUtils.addImportedDevices(vm.getStaticData(), false, withMemory);
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Example 69 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class AbstractDiskVmCommand method getDiskAddressMap.

/**
 * Returns disk's address map by specified VmDevice and DiskInterface
 * (note: for VirtIO_SCSI/SPAPR_VSCSI interfaces, the method updates the VM device's address accordingly).
 * @return disk's address map
 */
public Map<String, String> getDiskAddressMap(VmDevice vmDevice, DiskInterface diskInterface) {
    String address = vmDevice.getAddress();
    if (diskInterface != DiskInterface.VirtIO_SCSI && diskInterface != DiskInterface.SPAPR_VSCSI) {
        if (StringUtils.isNotBlank(address)) {
            return StringMapUtils.string2Map(address);
        }
    } else {
        EngineLock vmDiskHotPlugEngineLock = null;
        try {
            vmDiskHotPlugEngineLock = lockVmDiskHotPlugWithWait();
            VM vm = vmDao.get(getParameters().getVmId());
            Map<DiskInterface, Integer> controllerIndexMap = ArchStrategyFactory.getStrategy(vm.getClusterArch()).run(new GetControllerIndices()).returnValue();
            int virtioScsiIndex = controllerIndexMap.get(DiskInterface.VirtIO_SCSI);
            int sPaprVscsiIndex = controllerIndexMap.get(DiskInterface.SPAPR_VSCSI);
            if (diskInterface == DiskInterface.VirtIO_SCSI) {
                Map<Integer, Map<VmDevice, Integer>> vmDeviceUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForVirtioScsiDisks(getVm());
                return getAddressMapForScsiDisk(address, vmDeviceUnitMapForController(vmDevice, vmDeviceUnitMap), vmDevice, virtioScsiIndex, false, false);
            } else if (diskInterface == DiskInterface.SPAPR_VSCSI) {
                Map<Integer, Map<VmDevice, Integer>> vmDeviceUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForSpaprScsiDisks(getVm());
                return getAddressMapForScsiDisk(address, vmDeviceUnitMapForController(vmDevice, vmDeviceUnitMap), vmDevice, sPaprVscsiIndex, true, true);
            }
        } finally {
            lockManager.releaseLock(vmDiskHotPlugEngineLock);
        }
    }
    return null;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VM(org.ovirt.engine.core.common.businessentities.VM) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Map(java.util.Map) HashMap(java.util.HashMap) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) GetControllerIndices(org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices)

Example 70 with VmDevice

use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.

the class VmHandlerTest method populateVmWithDisks.

private void populateVmWithDisks(List<Disk> disks, VM vm) {
    vmHandler.updateDisksForVm(vm, disks);
    for (Disk disk : disks) {
        VmDevice device = new VmDevice(new VmDeviceId(disk.getId(), vm.getId()), VmDeviceGeneralType.DISK, VmDeviceType.DISK.getName(), "", null, true, true, false, "", null, disk.getDiskStorageType() == DiskStorageType.IMAGE ? ((DiskImage) disk).getSnapshotId() : null, null);
        vm.getManagedVmDeviceMap().put(disk.getId(), device);
    }
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Aggregations

VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)170 HashMap (java.util.HashMap)59 Guid (org.ovirt.engine.core.compat.Guid)53 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)48 ArrayList (java.util.ArrayList)34 Map (java.util.Map)33 VM (org.ovirt.engine.core.common.businessentities.VM)29 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)28 List (java.util.List)26 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)21 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)21 VmDeviceType (org.ovirt.engine.core.common.utils.VmDeviceType)20 Collections (java.util.Collections)19 Test (org.junit.Test)19 Collectors (java.util.stream.Collectors)18 Arrays (java.util.Arrays)17 Optional (java.util.Optional)17 StringUtils (org.apache.commons.lang.StringUtils)17 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)17 Inject (javax.inject.Inject)16