Search in sources :

Example 16 with CinderDisk

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

the class OvfOvaReader method readDisk.

@Override
protected void readDisk(XmlNode node, DiskImage image) {
    String diskId = node.attributes.get("ovf:diskId").getValue();
    String fileRef = node.attributes.get("ovf:fileRef").getValue();
    // If the disk storage type is Cinder then override the disk image with Cinder object,
    // otherwise use the disk image.
    image = new DiskImage();
    // image.
    if (node.attributes.get("ovf:disk_storage_type") != null) {
        String diskStorageType = node.attributes.get("ovf:disk_storage_type").getValue();
        if (diskStorageType != null && diskStorageType.equals(DiskStorageType.CINDER.name())) {
            image = new CinderDisk();
            if (node.attributes.get("ovf:cinder_volume_type") != null) {
                String cinderVolumeType = node.attributes.get("ovf:cinder_volume_type").getValue();
                image.setCinderVolumeType(cinderVolumeType);
            }
        }
    }
    try {
        image.setImageId(new Guid(fileRef));
    } catch (Exception ex) {
        log.warn("could not retrieve volume id of {} from ovf, generating new guid", fileRef);
        image.setImageId(Guid.newGuid());
    }
    try {
        image.setId(new Guid(diskId));
    } catch (Exception ex) {
        log.warn("could not retrieve disk id of {} from ovf, generating new guid", diskId);
        image.setId(Guid.newGuid());
    }
    XmlAttribute description = node.attributes.get("ovf:description");
    if (description != null) {
        image.setDescription(description.getValue());
    } else {
        image.setDescription(diskId);
    }
    XmlAttribute virtualSize = node.attributes.get("ovf:capacity");
    if (virtualSize != null) {
        // TODO take ovf:capacityAllocationUnits into account
        image.setSize(convertGigabyteToBytes(Long.parseLong(virtualSize.getValue())));
    }
    XmlAttribute populatedSize = node.attributes.get("ovf:populatedSize");
    if (populatedSize != null) {
        image.setActualSizeInBytes(Long.parseLong(populatedSize.getValue()));
    } else {
        Long actualSize = Long.parseLong(fileIdToFileAttributes.get(fileRef).get("ovf:size").getValue());
        image.setActualSizeInBytes(actualSize);
    }
    super.readDisk(node, image);
    if (StringUtils.isEmpty(image.getDiskAlias())) {
        image.setDiskAlias(diskId);
    }
    image.setRemotePath(fileIdToFileAttributes.get(fileRef).get("ovf:href").getValue());
    _images.add(image);
}
Also used : XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute) Guid(org.ovirt.engine.core.compat.Guid) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 17 with CinderDisk

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

the class RestoreAllCinderSnapshotsCommand method executeVmCommand.

@Override
protected void executeVmCommand() {
    for (CinderDisk cinderDisk : getParameters().getCinderDisksToRestore()) {
        ImagesContainterParametersBase params = getRestoreFromSnapshotParams(cinderDisk);
        restoreCinderDisk(cinderDisk, params);
        // In case we want to undo the previewed snapshot.
        if (getParameters().getSnapshot().getType() == Snapshot.SnapshotType.STATELESS) {
            Guid activeSnapshotId = snapshotDao.get(getParameters().getVmId(), Snapshot.SnapshotType.ACTIVE).getId();
            updateCinderDiskSnapshot(cinderDisk.getId(), activeSnapshotId, cinderDisk.getVmSnapshotId());
        } else if (getParameters().getSnapshot().getType() != Snapshot.SnapshotType.REGULAR) {
            updateCinderDiskSnapshot(cinderDisk.getId(), getParameters().getSnapshot().getId(), null);
        }
    }
    List<CinderDisk> cinderDisksToRemove = getParameters().getCinderDisksToRemove();
    for (CinderDisk cinderDisk : cinderDisksToRemove) {
        RemoveCinderDiskParameters removeDiskParam = new RemoveCinderDiskParameters(cinderDisk.getImageId());
        removeDiskParam.setRemovedVolume(cinderDisk);
        removeDiskParam.setParentCommand(getActionType());
        removeDiskParam.setStorageDomainId(cinderDisk.getStorageIds().get(0));
        removeDiskParam.setParentParameters(getParameters());
        removeDiskParam.setEndProcedure(EndProcedure.COMMAND_MANAGED);
        Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.RemoveCinderDisk, removeDiskParam, cloneContextAndDetachFromParent());
        try {
            future.get();
        } catch (InterruptedException | ExecutionException e) {
            log.error("Error removing Cinder disk", e);
        }
    }
    List<CinderDisk> cinderVolumesToRemove = getParameters().getCinderVolumesToRemove();
    for (CinderDisk cinderVolume : cinderVolumesToRemove) {
        RemoveCinderDiskVolumeParameters removeDiskVolumeParam = new RemoveCinderDiskVolumeParameters(cinderVolume);
        removeDiskVolumeParam.setParentCommand(getActionType());
        removeDiskVolumeParam.setParentParameters(getParameters());
        removeDiskVolumeParam.setEndProcedure(EndProcedure.COMMAND_MANAGED);
        Future<ActionReturnValue> future = commandCoordinatorUtil.executeAsyncCommand(ActionType.RemoveCinderDiskVolume, removeDiskVolumeParam, cloneContextAndDetachFromParent());
        try {
            future.get();
        } catch (InterruptedException | ExecutionException e) {
            log.error("Error removing Cinder disk", e);
        }
    }
    setSucceeded(true);
}
Also used : RemoveCinderDiskParameters(org.ovirt.engine.core.common.action.RemoveCinderDiskParameters) RemoveCinderDiskVolumeParameters(org.ovirt.engine.core.common.action.RemoveCinderDiskVolumeParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) Guid(org.ovirt.engine.core.compat.Guid) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) ExecutionException(java.util.concurrent.ExecutionException)

Example 18 with CinderDisk

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

the class TryBackToCinderSnapshotCommand method createVolumeFromSnapshotInCinder.

private CinderDisk createVolumeFromSnapshotInCinder() {
    Guid newVolumeId = cinderCloneDiskFromSnapshot();
    CinderDisk clonedDiskFromSnapshot = initializeNewCinderVolumeDisk(newVolumeId);
    // Setting this for the callback from coco.
    getParameters().setDestinationImageId(newVolumeId);
    return clonedDiskFromSnapshot;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk)

Example 19 with CinderDisk

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

the class RegisterCinderDiskCommand method executeCommand.

@Override
public void executeCommand() {
    QueryReturnValue returnValue = runInternalQuery(QueryType.GetUnregisteredCinderDiskByIdAndStorageDomainId, new GetCinderEntityByStorageDomainIdParameters(getCinderDisk().getId(), getParameters().getStorageDomainId()));
    CinderDisk cinderDisk = returnValue.getReturnValue();
    if (cinderDisk != null) {
        addCinderDiskToDB(cinderDisk);
        getReturnValue().setActionReturnValue(cinderDisk.getId());
        setSucceeded(true);
    }
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) GetCinderEntityByStorageDomainIdParameters(org.ovirt.engine.core.common.action.GetCinderEntityByStorageDomainIdParameters)

Example 20 with CinderDisk

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

the class RegisterCinderDiskCommand method validate.

@Override
public boolean validate() {
    CinderDisk cinderDisk = getCinderDisk();
    cinderDisk.setStorageIds(new ArrayList<>(Arrays.asList(getParameters().getStorageDomainId())));
    CinderDisksValidator cinderDiskValidator = getCinderDisksValidator(cinderDisk);
    return validate(cinderDiskValidator.validateCinderDisksAlreadyRegistered());
}
Also used : CinderDisksValidator(org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk)

Aggregations

CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)74 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)28 Guid (org.ovirt.engine.core.compat.Guid)19 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)15 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)14 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)13 ArrayList (java.util.ArrayList)12 ImagesContainterParametersBase (org.ovirt.engine.core.common.action.ImagesContainterParametersBase)9 ExecutionException (java.util.concurrent.ExecutionException)7 VM (org.ovirt.engine.core.common.businessentities.VM)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ImageStatus (org.ovirt.engine.core.common.businessentities.storage.ImageStatus)5 Map (java.util.Map)4 Test (org.junit.Test)4 StoragePoolValidator (org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator)4 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)4 EngineException (org.ovirt.engine.core.common.errors.EngineException)4 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3