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);
}
}
}
}
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);
}
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);
}
}
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;
}
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);
}
}
Aggregations