Search in sources :

Example 1 with CopyImageVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.CopyImageVDSCommandParameters in project ovirt-engine by oVirt.

the class CreateCloneOfTemplateCommand method performImageVdsmOperation.

@Override
protected boolean performImageVdsmOperation() {
    setDestinationImageId(Guid.newGuid());
    persistCommandIfNeeded();
    newDiskImage = cloneDiskImage(getDestinationImageId());
    newDiskImage.setId(Guid.newGuid());
    Guid storagePoolID = newDiskImage.getStoragePoolId() != null ? newDiskImage.getStoragePoolId() : Guid.Empty;
    if (isDataOperationsByHSM()) {
        CopyImageGroupWithDataCommandParameters p = new CopyImageGroupWithDataCommandParameters(storagePoolID, getParameters().getStorageDomainId(), getDestinationStorageDomainId(), getDiskImage().getId(), getImage().getImageId(), newDiskImage.getId(), getDestinationImageId(), newDiskImage.getVolumeFormat(), true);
        p.setParentParameters(getParameters());
        p.setParentCommand(getActionType());
        p.setEndProcedure(ActionParametersBase.EndProcedure.COMMAND_MANAGED);
        runInternalAction(ActionType.CopyImageGroupWithData, p);
        return true;
    } else {
        Guid taskId = persistAsyncTaskPlaceHolder(ActionType.AddVmFromTemplate);
        VDSReturnValue vdsReturnValue;
        try {
            vdsReturnValue = runVdsCommand(VDSCommandType.CopyImage, postDeleteActionHandler.fixParameters(new CopyImageVDSCommandParameters(storagePoolID, getParameters().getStorageDomainId(), getVmTemplateId(), getDiskImage().getId(), getImage().getImageId(), newDiskImage.getId(), getDestinationImageId(), "", getDestinationStorageDomainId(), CopyVolumeType.LeafVol, newDiskImage.getVolumeFormat(), newDiskImage.getVolumeType(), getDiskImage().isWipeAfterDelete(), storageDomainDao.get(getDestinationStorageDomainId()).getDiscardAfterDelete(), false)));
        } catch (EngineException e) {
            log.error("Failed creating snapshot from image id '{}'", getImage().getImageId());
            throw e;
        }
        if (vdsReturnValue.getSucceeded()) {
            getTaskIdList().add(createTask(taskId, vdsReturnValue.getCreationInfo(), ActionType.AddVmFromTemplate, VdcObjectType.Storage, getParameters().getStorageDomainId(), getDestinationStorageDomainId()));
        }
        return vdsReturnValue.getSucceeded();
    }
}
Also used : CopyImageVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.CopyImageVDSCommandParameters) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) CopyImageGroupWithDataCommandParameters(org.ovirt.engine.core.common.action.CopyImageGroupWithDataCommandParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 2 with CopyImageVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.CopyImageVDSCommandParameters in project ovirt-engine by oVirt.

the class CopyImageGroupCommand method performStorageOperation.

private boolean performStorageOperation() {
    Guid sourceDomainId = getParameters().getSourceDomainId() != null ? getParameters().getSourceDomainId() : getDiskImage().getStorageIds().get(0);
    if (isUsingSPDMFlow()) {
        CopyImageGroupWithDataCommandParameters p = new CopyImageGroupWithDataCommandParameters(getStorageDomain().getStoragePoolId(), sourceDomainId, getParameters().getStorageDomainId(), getParameters().getImageGroupID(), getParameters().getImageId(), getParameters().getImageGroupID(), getParameters().getImageId(), getVolumeFormatForDomain(), getParameters().getUseCopyCollapse());
        p.setParentParameters(getParameters());
        p.setParentCommand(getActionType());
        p.setEndProcedure(EndProcedure.COMMAND_MANAGED);
        p.setJobWeight(getParameters().getJobWeight());
        runInternalAction(ActionType.CopyImageGroupWithData, p);
        return true;
    } else {
        VDSReturnValue vdsReturnValue;
        Guid taskId = persistAsyncTaskPlaceHolder(getParameters().getParentCommand());
        if (getParameters().getUseCopyCollapse()) {
            vdsReturnValue = runVdsCommand(VDSCommandType.CopyImage, postDeleteActionHandler.fixParameters(new CopyImageVDSCommandParameters(getStorageDomain().getStoragePoolId(), sourceDomainId, getParameters().getContainerId(), getParameters().getImageGroupID(), getParameters().getImageId(), getParameters().getDestImageGroupId(), getParameters().getDestinationImageId(), "", getParameters().getStorageDomainId(), getParameters().getCopyVolumeType(), getVolumeFormatForDomain(), getParameters().getVolumeType(), isWipeAfterDelete(), getStorageDomain().getDiscardAfterDelete(), getParameters().getForceOverride())));
        } else {
            vdsReturnValue = runVdsCommand(VDSCommandType.MoveImageGroup, postDeleteActionHandler.fixParameters(new MoveImageGroupVDSCommandParameters(getDiskImage() != null ? getDiskImage().getStoragePoolId() : getStorageDomain().getStoragePoolId(), sourceDomainId, getDiskImage() != null ? getDiskImage().getId() : getParameters().getImageGroupID(), getParameters().getStorageDomainId(), getParameters().getContainerId(), ImageOperation.Copy, isWipeAfterDelete(), storageDomainDao.get(sourceDomainId).getDiscardAfterDelete(), getParameters().getForceOverride())));
        }
        if (vdsReturnValue.getSucceeded()) {
            AsyncTaskCreationInfo taskCreationInfo = vdsReturnValue.getCreationInfo();
            getTaskIdList().add(createTask(taskId, taskCreationInfo, getParameters().getParentCommand(), VdcObjectType.Storage, sourceDomainId, getParameters().getStorageDomainId()));
        }
        return vdsReturnValue.getSucceeded();
    }
}
Also used : MoveImageGroupVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.MoveImageGroupVDSCommandParameters) CopyImageVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.CopyImageVDSCommandParameters) AsyncTaskCreationInfo(org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo) Guid(org.ovirt.engine.core.compat.Guid) CopyImageGroupWithDataCommandParameters(org.ovirt.engine.core.common.action.CopyImageGroupWithDataCommandParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 3 with CopyImageVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.CopyImageVDSCommandParameters in project ovirt-engine by oVirt.

the class CreateImageTemplateCommand method executeCommand.

@Override
protected void executeCommand() {
    Guid storagePoolId = getDiskImage().getStoragePoolId() != null ? getDiskImage().getStoragePoolId() : Guid.Empty;
    Guid imageGroupId = getDiskImage().getId() != null ? getDiskImage().getId() : Guid.Empty;
    Guid snapshotId = getDiskImage().getImageId();
    // Create new image group id and image id:
    Guid destinationImageGroupID = Guid.newGuid();
    setDestinationImageId(Guid.newGuid());
    DiskImage newImage = cloneDiskImage(getDestinationImageId());
    if (getParameters().getVolumeFormat() == null || getParameters().getVolumeType() == null) {
        // At least one of the volume arguments should be copied from the ancestral image.
        fillVolumeInformation(newImage);
    }
    if (getParameters().getVolumeFormat() != null) {
        newImage.setVolumeFormat(getParameters().getVolumeFormat());
    }
    if (getParameters().getVolumeType() != null) {
        newImage.setVolumeType(getParameters().getVolumeType());
    }
    Guid taskId = persistAsyncTaskPlaceHolder(getParameters().getParentCommand());
    VolumeFormat targetFormat = getTargetVolumeFormat(newImage.getVolumeFormat(), newImage.getVolumeType(), getParameters().getDestinationStorageDomainId());
    newImage.setDiskAlias(getParameters().getDiskAlias() != null ? getParameters().getDiskAlias() : getDiskImage().getDiskAlias());
    VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.CopyImage, postDeleteActionHandler.fixParameters(new CopyImageVDSCommandParameters(storagePoolId, getParameters().getStorageDomainId(), getParameters().getVmId(), imageGroupId, snapshotId, destinationImageGroupID, getDestinationImageId(), getJsonDiskDescription(newImage), getParameters().getDestinationStorageDomainId(), getParameters().getCopyVolumeType(), targetFormat, newImage.getVolumeType(), getDiskImage().isWipeAfterDelete(), storageDomainDao.get(getParameters().getDestinationStorageDomainId()).getDiscardAfterDelete(), false)));
    getReturnValue().getInternalVdsmTaskIdList().add(createTask(taskId, vdsReturnValue.getCreationInfo(), getParameters().getParentCommand(), VdcObjectType.Storage, getParameters().getStorageDomainId(), getParameters().getDestinationStorageDomainId()));
    newImage.setId(destinationImageGroupID);
    newImage.setDiskDescription(getParameters().getDescription() != null ? getParameters().getDescription() : getDiskImage().getDiskDescription());
    newImage.setVmSnapshotId(getParameters().getVmSnapshotId());
    newImage.setQuotaId(getParameters().getQuotaId());
    newImage.setDiskProfileId(getParameters().getDiskProfileId());
    newImage.setParentId(Guid.Empty);
    newImage.setImageTemplateId(Guid.Empty);
    newImage.setStorageIds(new ArrayList<>(Arrays.asList(getParameters().getDestinationStorageDomainId())));
    newImage.setActive(true);
    imagesHandler.saveImage(newImage);
    baseDiskDao.save(newImage);
    DiskImageDynamic diskDynamic = new DiskImageDynamic();
    diskDynamic.setId(newImage.getImageId());
    diskDynamic.setActualSize(getDiskImage().getActualSizeInBytes());
    diskImageDynamicDao.save(diskDynamic);
    setActionReturnValue(newImage);
    // set source image as locked:
    lockImage();
    setSucceeded(true);
}
Also used : VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) CopyImageVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.CopyImageVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DiskImageDynamic(org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

CopyImageVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.CopyImageVDSCommandParameters)3 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)3 Guid (org.ovirt.engine.core.compat.Guid)3 CopyImageGroupWithDataCommandParameters (org.ovirt.engine.core.common.action.CopyImageGroupWithDataCommandParameters)2 AsyncTaskCreationInfo (org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo)1 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)1 DiskImageDynamic (org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic)1 VolumeFormat (org.ovirt.engine.core.common.businessentities.storage.VolumeFormat)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 MoveImageGroupVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.MoveImageGroupVDSCommandParameters)1