use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class VmTemplateHandler method updateDisksFromDb.
public void updateDisksFromDb(VmTemplate vmt) {
vmt.getDiskTemplateMap().clear();
vmt.getDiskImageMap().clear();
vmt.getDiskList().clear();
List<Disk> diskList = diskDao.getAllForVm(vmt.getId());
for (Disk dit : diskList) {
DiskImage diskImage = (DiskImage) dit;
vmt.getDiskTemplateMap().put(dit.getId(), diskImage);
vmt.getDiskImageMap().put(dit.getId(), diskImage);
DiskVmElement dve = diskVmElementDao.get(new VmDeviceId(dit.getId(), vmt.getId()));
dit.setDiskVmElements(Collections.singletonList(dve));
vmt.getDiskList().add(diskImage);
}
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class OvfManagerTest method createVmDisk.
private static DiskImage createVmDisk(VM vm) {
RandomUtils rnd = RandomUtils.instance();
DiskImage disk = new DiskImage();
disk.setId(Guid.newGuid());
disk.setVmSnapshotId(Guid.newGuid());
disk.setSize(rnd.nextLong(1000));
disk.setActualSize(rnd.nextLong(1000));
disk.setVolumeFormat(rnd.nextEnum(VolumeFormat.class));
disk.setVolumeType(rnd.nextEnum(VolumeType.class));
disk.setWipeAfterDelete(rnd.nextBoolean());
disk.setDiskAlias(generateRandomName());
disk.setDescription(generateRandomName());
disk.setImageId(Guid.newGuid());
disk.setStoragePoolId(Guid.newGuid());
disk.setPlugged(true);
disk.setAppList(rnd.nextPropertyString(100));
Image image = new Image();
image.setActive(true);
image.setVolumeFormat(rnd.nextEnum(VolumeFormat.class));
image.setId(disk.getImageId());
image.setSnapshotId(disk.getSnapshotId());
image.setStatus(ImageStatus.OK);
disk.setImage(image);
DiskVmElement diskVmElement = new DiskVmElement(disk.getId(), vm.getId());
diskVmElement.setBoot(rnd.nextBoolean());
diskVmElement.setDiskInterface(rnd.nextEnum(DiskInterface.class));
diskVmElement.setReadOnly(false);
diskVmElement.setPlugged(true);
disk.setDiskVmElements(Collections.singletonList(diskVmElement));
return disk;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class MoveDiskCommand method getMoveActionType.
protected ActionType getMoveActionType(List<DiskVmElement> diskVmElements) {
// Floating disk
if (diskVmElements.isEmpty()) {
return ActionType.MoveOrCopyDisk;
}
// In case of a shareable disk, the validation
// will be performed in MoveOrCopyDiskCommand
// which both action types use.
DiskVmElement diskVmElement = diskVmElements.get(0);
VM vm = vmDao.get(diskVmElement.getVmId());
if (vm.isDown() || !diskVmElement.isPlugged()) {
return ActionType.MoveOrCopyDisk;
}
return ActionType.LiveMigrateDisk;
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class SnapshotsManager method synchronizeDisksFromSnapshot.
/**
* Synchronize the VM's Disks with the images from the snapshot:<br>
* <ul>
* <li>Existing disks are updated.</li>
* <li>Disks that don't exist anymore get re-added.</li>
* <ul>
* <li>If the image is still in the DB, the disk is linked to it.</li>
* <li>If the image is not in the DB anymore, the disk will be marked as "broken"</li>
* </ul>
* </ul>
*
* @param vmId
* The VM ID is needed to re-add disks.
* @param snapshotId
* The snapshot ID is used to find only the VM disks at the time.
* @param disksFromSnapshot
* The disks that existed in the snapshot.
*/
protected void synchronizeDisksFromSnapshot(Guid vmId, Guid snapshotId, Guid activeSnapshotId, List<DiskImage> disksFromSnapshot, String vmName) {
List<Guid> diskIdsFromSnapshot = new ArrayList<>();
// Sync disks that exist or existed in the snapshot.
int count = 1;
for (DiskImage diskImage : disksFromSnapshot) {
diskIdsFromSnapshot.add(diskImage.getId());
if (baseDiskDao.exists(diskImage.getId())) {
baseDiskDao.update(diskImage);
DiskVmElement dve = diskVmElementDao.get(diskImage.getDiskVmElementForVm(vmId).getId());
if (dve != null && !dve.equals(diskImage.getDiskVmElementForVm(vmId))) {
diskVmElementDao.update(diskImage.getDiskVmElementForVm(vmId));
}
} else {
// If can't find the image, insert it as illegal so that it can't be used and make the device unplugged.
if (diskImageDao.getSnapshotById(diskImage.getImageId()) == null) {
diskImage.setImageStatus(ImageStatus.ILLEGAL);
diskImage.setVmSnapshotId(activeSnapshotId);
imagesHandler.addImage(diskImage, true, (diskImage.getStorageIds() == null) ? null : new ImageStorageDomainMap(diskImage.getImageId(), diskImage.getStorageIds().get(0), diskImage.getQuotaId(), diskImage.getDiskProfileId()));
}
imagesHandler.addDiskToVm(diskImage, vmId);
}
diskImage.setDiskAlias(imagesHandler.getSuggestedDiskAlias(diskImage, vmName, count));
count++;
}
removeDisksNotInSnapshot(vmId, diskIdsFromSnapshot);
}
use of org.ovirt.engine.core.common.businessentities.storage.DiskVmElement in project ovirt-engine by oVirt.
the class AddDiskCommand method plugDiskToVmIfNeeded.
private void plugDiskToVmIfNeeded() {
if (Boolean.TRUE.equals(getParameters().getPlugDiskToVm()) && getVm() != null && getVm().getStatus() != VMStatus.Down) {
VmDiskOperationParameterBase params = new VmDiskOperationParameterBase(new DiskVmElement(getParameters().getDiskInfo().getId(), getVmId()));
params.setShouldBeLogged(false);
ActionReturnValue returnValue = runInternalAction(ActionType.HotPlugDiskToVm, params);
if (!returnValue.getSucceeded()) {
auditLogDirector.log(this, AuditLogType.USER_FAILED_HOTPLUG_DISK);
}
}
}
Aggregations