use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class AttachDiskToVmCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
if (!isOperationPerformedOnDiskSnapshot()) {
vmStaticDao.incrementDbGeneration(getVm().getId());
}
final VmDevice vmDevice = createVmDevice();
vmDeviceDao.save(vmDevice);
DiskVmElement diskVmElement = getDiskVmElement();
diskVmElement.getId().setDeviceId(disk.getId());
diskVmElementDao.save(diskVmElement);
// When performing hot plug for VirtIO-SCSI or SPAPR_VSCSI the address map calculation needs this info to be populated
disk.setDiskVmElements(Collections.singletonList(diskVmElement));
// update cached image
List<Disk> imageList = new ArrayList<>();
imageList.add(disk);
vmHandler.updateDisksForVm(getVm(), imageList);
if (!isOperationPerformedOnDiskSnapshot()) {
if (disk.isAllowSnapshot()) {
updateDiskVmSnapshotId();
}
}
if (getParameters().isPlugUnPlug() && getVm().getStatus() != VMStatus.Down) {
performPlugCommand(VDSCommandType.HotPlugDisk, disk, vmDevice);
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class HotPlugDiskToVmCommand method updateDeviceProperties.
protected void updateDeviceProperties() {
VmDevice device = vmDeviceDao.get(oldVmDevice.getId());
device.setPlugged(true);
vmDeviceDao.updateHotPlugDisk(device);
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class UpdateVmDiskCommandTest method validateFailedROVmAttachedToPool.
@Test
public void validateFailedROVmAttachedToPool() {
when(diskDao.get(diskImageGuid)).thenReturn(createDiskImage());
command.getParameters().getDiskVmElement().setReadOnly(true);
VM vm = createVm(VMStatus.Down);
vm.setVmPoolId(Guid.newGuid());
initializeCommand(vm);
// Default RO is false
VmDevice vmDevice = stubVmDevice(diskImageGuid, vmId);
ValidateTestUtils.runAndAssertValidateFailure(command, EngineMessage.ACTION_TYPE_FAILED_VM_ATTACHED_TO_POOL);
vmDevice.setReadOnly(true);
command.getParameters().getDiskVmElement().setReadOnly(false);
ValidateTestUtils.runAndAssertValidateFailure(command, EngineMessage.ACTION_TYPE_FAILED_VM_ATTACHED_TO_POOL);
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class UpdateVmDiskCommandTest method stubVmDevice.
private VmDevice stubVmDevice(Guid diskId, Guid vmId) {
VmDevice vmDevice = createVmDevice(diskId, vmId);
doReturn(vmDevice).when(command).getVmDeviceForVm();
return vmDevice;
}
use of org.ovirt.engine.core.common.businessentities.VmDevice in project ovirt-engine by oVirt.
the class SnapshotsManager method removeDisksNotInSnapshot.
/**
* Remove all the disks which are allowed to be snapshot but not exist in the snapshot and are not disk snapshots
* @param vmId - The vm id which is being snapshot.
* @param diskIdsFromSnapshot - An image group id list for images which are part of the VM.
*/
private void removeDisksNotInSnapshot(Guid vmId, List<Guid> diskIdsFromSnapshot) {
for (VmDevice vmDevice : vmDeviceDao.getVmDeviceByVmIdTypeAndDevice(vmId, VmDeviceGeneralType.DISK, VmDeviceType.DISK)) {
if (!diskIdsFromSnapshot.contains(vmDevice.getDeviceId()) && vmDevice.getSnapshotId() == null) {
Disk disk = diskDao.get(vmDevice.getDeviceId());
if (disk != null && disk.isAllowSnapshot()) {
baseDiskDao.remove(vmDevice.getDeviceId());
vmDeviceDao.remove(vmDevice.getId());
}
}
}
}
Aggregations