Search in sources :

Example 6 with GetImageInfoVDSCommandParameters

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

the class GetUnregisteredDiskQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Guid storagePoolId = getParameters().getStoragePoolId();
    Guid storageDomainId = getParameters().getStorageDomainId();
    Guid diskId = getParameters().getDiskId();
    StorageDomain storageDomain = storageDomainDao.get(storageDomainId);
    if (storageDomain == null) {
        getQueryReturnValue().setExceptionString(EngineMessage.STORAGE_DOMAIN_DOES_NOT_EXIST.toString());
        getQueryReturnValue().setSucceeded(false);
        return;
    }
    if (storageDomain.getStorageType().isCinderDomain()) {
        QueryReturnValue returnValue = runInternalQuery(QueryType.GetUnregisteredCinderDiskByIdAndStorageDomainId, new GetCinderEntityByStorageDomainIdParameters(diskId, getParameters().getStorageDomainId()));
        setReturnValue(returnValue.getReturnValue());
        return;
    }
    // Now get the list of volumes for each new image.
    StoragePoolDomainAndGroupIdBaseVDSCommandParameters getVolumesParameters = new StoragePoolDomainAndGroupIdBaseVDSCommandParameters(storagePoolId, storageDomainId, diskId);
    VDSReturnValue volumesListReturn = runVdsCommand(VDSCommandType.GetVolumesList, getVolumesParameters);
    if (!volumesListReturn.getSucceeded()) {
        getQueryReturnValue().setExceptionString(volumesListReturn.getExceptionString());
        getQueryReturnValue().setSucceeded(false);
        return;
    }
    @SuppressWarnings("unchecked") List<Guid> volumesList = (List<Guid>) volumesListReturn.getReturnValue();
    // image. If there are multiple volumes, skip the image and move on to the next.
    if (volumesList.size() != 1) {
        getQueryReturnValue().setSucceeded(false);
        return;
    }
    Guid volumeId = volumesList.get(0);
    // Get the information about the volume from VDSM.
    GetImageInfoVDSCommandParameters imageInfoParameters = new GetImageInfoVDSCommandParameters(storagePoolId, storageDomainId, diskId, volumeId);
    VDSReturnValue imageInfoReturn = runVdsCommand(VDSCommandType.GetImageInfo, imageInfoParameters);
    if (!imageInfoReturn.getSucceeded()) {
        getQueryReturnValue().setExceptionString(imageInfoReturn.getExceptionString());
        getQueryReturnValue().setSucceeded(false);
        return;
    }
    DiskImage newDiskImage = (DiskImage) imageInfoReturn.getReturnValue();
    if (!fetchQcowCompat(storagePoolId, storageDomainId, diskId, volumeId, newDiskImage)) {
        getQueryReturnValue().setSucceeded(false);
        return;
    }
    if (StringUtils.isNotEmpty(newDiskImage.getDescription())) {
        try {
            metadataDiskDescriptionHandler.enrichDiskByJsonDescription(newDiskImage.getDescription(), newDiskImage);
        } catch (IOException | DecoderException e) {
            log.warn("Could not parse the description ({}) of disk ID '{}'. The description is expected to be in " + "JSON format.", newDiskImage.getDescription(), newDiskImage.getId());
            log.debug("Exception while parsing JSON for disk", e);
        }
    }
    newDiskImage.setStoragePoolId(storagePoolId);
    getQueryReturnValue().setReturnValue(newDiskImage);
    getQueryReturnValue().setSucceeded(true);
}
Also used : GetImageInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) StoragePoolDomainAndGroupIdBaseVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.StoragePoolDomainAndGroupIdBaseVDSCommandParameters) IOException(java.io.IOException) GetCinderEntityByStorageDomainIdParameters(org.ovirt.engine.core.common.action.GetCinderEntityByStorageDomainIdParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) DecoderException(org.apache.commons.codec.DecoderException) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) List(java.util.List) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 7 with GetImageInfoVDSCommandParameters

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

the class ImportVmCommand method checkImagesGUIDsLegal.

protected boolean checkImagesGUIDsLegal() {
    for (DiskImage image : new ArrayList<>(getImages())) {
        Guid imageGUID = image.getImageId();
        Guid storagePoolId = image.getStoragePoolId() != null ? image.getStoragePoolId() : Guid.Empty;
        Guid storageDomainId = getSourceDomainId(image);
        Guid imageGroupId = image.getId() != null ? image.getId() : Guid.Empty;
        VDSReturnValue retValue = runVdsCommand(VDSCommandType.GetImageInfo, new GetImageInfoVDSCommandParameters(storagePoolId, storageDomainId, imageGroupId, imageGUID));
        if (!retValue.getSucceeded()) {
            if (!getParameters().isAllowPartialImport()) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST);
            }
            log.warn("Disk image '{}/{}' doesn't exist on storage domain '{}'. Ignoring since force flag in on", imageGroupId, imageGUID, storageDomainId);
            getVm().getImages().remove(image);
            failedDisksToImportForAuditLog.putIfAbsent(image.getId(), image.getDiskAlias());
        }
    }
    return true;
}
Also used : GetImageInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)7 GetImageInfoVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters)7 Guid (org.ovirt.engine.core.compat.Guid)5 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)4 ArrayList (java.util.ArrayList)3 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)2 EngineException (org.ovirt.engine.core.common.errors.EngineException)2 OvfReaderException (org.ovirt.engine.core.utils.ovf.OvfReaderException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DecoderException (org.apache.commons.codec.DecoderException)1 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)1 ImportValidator (org.ovirt.engine.core.bll.validator.ImportValidator)1 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)1 GetCinderEntityByStorageDomainIdParameters (org.ovirt.engine.core.common.action.GetCinderEntityByStorageDomainIdParameters)1 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)1 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)1 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)1 DiskImageDynamic (org.ovirt.engine.core.common.businessentities.storage.DiskImageDynamic)1