Search in sources :

Example 36 with DiskVmElement

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

Example 37 with DiskVmElement

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;
}
Also used : VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) VolumeType(org.ovirt.engine.core.common.businessentities.storage.VolumeType) RandomUtils(org.ovirt.engine.core.utils.RandomUtils) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Image(org.ovirt.engine.core.common.businessentities.storage.Image) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 38 with DiskVmElement

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

Example 39 with DiskVmElement

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

Example 40 with DiskVmElement

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);
        }
    }
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmDiskOperationParameterBase(org.ovirt.engine.core.common.action.VmDiskOperationParameterBase)

Aggregations

DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)91 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)30 Test (org.junit.Test)26 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)23 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)22 Guid (org.ovirt.engine.core.compat.Guid)17 ArrayList (java.util.ArrayList)16 VM (org.ovirt.engine.core.common.businessentities.VM)12 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)11 HashMap (java.util.HashMap)8 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)8 Map (java.util.Map)7 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)7 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)7 ActionType (org.ovirt.engine.core.common.action.ActionType)6 AttachDetachVmDiskParameters (org.ovirt.engine.core.common.action.AttachDetachVmDiskParameters)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 VmDiskOperationParameterBase (org.ovirt.engine.core.common.action.VmDiskOperationParameterBase)5 Collection (java.util.Collection)4