Search in sources :

Example 26 with CinderDisk

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

the class AddDiskCommand method validate.

@Override
protected boolean validate() {
    if (!isFloatingDisk() && (!validate(new VmValidator(getVm()).isVmExists()) || !validateDiskVmData())) {
        return false;
    }
    Disk diskInfo = getParameters().getDiskInfo();
    if (diskInfo.getDiskStorageType() == DiskStorageType.IMAGE || diskInfo.getDiskStorageType() == DiskStorageType.CINDER) {
        getDiskImageInfo().setDiskSnapshot(false);
    }
    VM vm = getVm();
    DiskValidator diskValidator = getDiskValidator(getParameters().getDiskInfo());
    DiskVmElementValidator diskVmElementValidator = getDiskVmElementValidator(getParameters().getDiskInfo(), getDiskVmElement());
    if (vm != null) {
        if (!validateDiskVmData() || !canRunActionOnNonManagedVm()) {
            return false;
        }
        updateDisksFromDb();
        if (getDiskVmElement().isBoot() && !validate(diskValidator.isVmNotContainsBootDisk(vm))) {
            return false;
        }
        if (!validatePassDiscardSupported(diskVmElementValidator)) {
            return false;
        }
        // if user sent drive check that its not in use
        if (!isDiskPassPciAndIdeLimit()) {
            return false;
        }
        if (!validate(diskVmElementValidator.isReadOnlyPropertyCompatibleWithInterface())) {
            return false;
        }
    } else if (Boolean.TRUE.equals(getParameters().getPlugDiskToVm())) {
        return failValidation(EngineMessage.CANNOT_ADD_FLOATING_DISK_WITH_PLUG_VM_SET);
    }
    if (!validateQuota()) {
        return false;
    }
    if (DiskStorageType.IMAGE == getParameters().getDiskInfo().getDiskStorageType()) {
        if (!checkIfImageDiskCanBeAdded(vm, diskVmElementValidator)) {
            return false;
        }
        return setAndValidateDiskProfiles();
    }
    if (DiskStorageType.LUN == getParameters().getDiskInfo().getDiskStorageType()) {
        return checkIfLunDiskCanBeAdded(diskValidator);
    }
    if (DiskStorageType.CINDER == getParameters().getDiskInfo().getDiskStorageType()) {
        CinderDisk cinderDisk = (CinderDisk) getParameters().getDiskInfo();
        cinderDisk.setStorageIds(new ArrayList<>(Collections.singletonList(getStorageDomainId())));
        StorageDomainValidator storageDomainValidator = createStorageDomainValidator();
        CinderDisksValidator cinderDisksValidator = new CinderDisksValidator(cinderDisk);
        return validate(storageDomainValidator.isDomainExistAndActive()) && validate(cinderDisksValidator.validateCinderDiskLimits()) && validate(cinderDisksValidator.validateCinderVolumeTypesExist());
    }
    return true;
}
Also used : DiskValidator(org.ovirt.engine.core.bll.validator.storage.DiskValidator) DiskVmElementValidator(org.ovirt.engine.core.bll.validator.storage.DiskVmElementValidator) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) VM(org.ovirt.engine.core.common.businessentities.VM) CinderDisksValidator(org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 27 with CinderDisk

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

the class CreateAllTemplateDisksCommand method addVmTemplateCinderDisks.

private boolean addVmTemplateCinderDisks(Map<Guid, Guid> srcDeviceIdToTargetDeviceIdMapping) {
    List<CinderDisk> cinderDisks = getCinderDisks();
    if (cinderDisks.isEmpty()) {
        return true;
    }
    // Create Cinder disk templates
    Map<Guid, Guid> diskImageMap = new HashMap<>();
    for (CinderDisk cinderDisk : cinderDisks) {
        ImagesContainterParametersBase params = buildCloneCinderDiskCommandParameters(cinderDisk);
        ActionReturnValue returnValue = runInternalAction(ActionType.CloneSingleCinderDisk, params, cloneContext().withoutExecutionContext().withoutLock());
        if (!returnValue.getSucceeded()) {
            log.error("Error cloning Cinder disk '{}'", cinderDisk.getDiskAlias());
            getReturnValue().setFault(returnValue.getFault());
            return false;
        }
        Guid imageId = returnValue.getActionReturnValue();
        diskImageMap.put(cinderDisk.getId(), imageId);
    }
    srcDeviceIdToTargetDeviceIdMapping.putAll(diskImageMap);
    return true;
}
Also used : HashMap(java.util.HashMap) 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)

Example 28 with CinderDisk

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

the class AbstractDiskVmCommand method performPlugCommand.

protected void performPlugCommand(VDSCommandType commandType, Disk disk, VmDevice vmDevice) {
    if (disk.getDiskStorageType() == DiskStorageType.LUN) {
        LunDisk lunDisk = (LunDisk) disk;
        if (commandType == VDSCommandType.HotPlugDisk) {
            LUNs lun = lunDisk.getLun();
            updateLUNConnectionsInfo(lun);
            lun.getLunConnections().stream().map(StorageServerConnections::getStorageType).distinct().forEach(t -> {
                if (!getStorageHelper(t).connectStorageToLunByVdsId(null, getVm().getRunOnVds(), lun, getVm().getStoragePoolId())) {
                    throw new EngineException(EngineError.StorageServerConnectionError);
                }
            });
        }
    } else if (disk.getDiskStorageType() == DiskStorageType.CINDER) {
        CinderDisk cinderDisk = (CinderDisk) disk;
        setStorageDomainId(cinderDisk.getStorageIds().get(0));
        getCinderBroker().updateConnectionInfoForDisk(cinderDisk);
    }
    Map<String, String> diskAddressMap = getDiskAddressMap(vmDevice, getDiskVmElement().getDiskInterface());
    runVdsCommand(commandType, new HotPlugDiskVDSParameters(getVm().getRunOnVds(), getVm(), disk, vmDevice, diskAddressMap, getDiskVmElement().getDiskInterface(), getDiskVmElement().isPassDiscard()));
}
Also used : StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) EngineException(org.ovirt.engine.core.common.errors.EngineException) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) HotPlugDiskVDSParameters(org.ovirt.engine.core.common.vdscommands.HotPlugDiskVDSParameters)

Example 29 with CinderDisk

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

the class CinderBroker method volumeToCinderDisk.

public static CinderDisk volumeToCinderDisk(Volume volume, Guid storageDomainId) {
    CinderDisk cinderDisk = new CinderDisk();
    cinderDisk.setId(Guid.createGuidFromString(volume.getId()));
    cinderDisk.setImageId(Guid.createGuidFromString(volume.getId()));
    cinderDisk.setDiskAlias(volume.getName());
    cinderDisk.setDescription(volume.getDescription());
    cinderDisk.setSizeInGigabytes(volume.getSize());
    cinderDisk.setCinderVolumeType(volume.getVolumeType());
    cinderDisk.setStorageIds(new ArrayList<>(Arrays.asList(storageDomainId)));
    cinderDisk.setActive(true);
    cinderDisk.setImageStatus(ImageStatus.OK);
    cinderDisk.setVolumeFormat(VolumeFormat.RAW);
    try {
        cinderDisk.setCreationDate(new SimpleDateFormat(DATE_FORMAT).parse(volume.getCreatedAt()));
    } catch (ParseException e) {
        cinderDisk.setCreationDate(null);
        log.error("Invalid disk creation date format, id: '{}' (info: {})", volume.getId(), e.getMessage());
    }
    return cinderDisk;
}
Also used : ParseException(java.text.ParseException) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) SimpleDateFormat(java.text.SimpleDateFormat)

Example 30 with CinderDisk

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

the class CloneSingleCinderDiskCommandCallback method childCommandsExecutionEnded.

@Override
protected void childCommandsExecutionEnded(CommandBase<?> command, boolean anyFailed, List<Guid> childCmdIds, CommandExecutionStatus status, int completedChildren) {
    BaseImagesCommand<ImagesContainterParametersBase> cloneCinderDiskCommand = (BaseImagesCommand<ImagesContainterParametersBase>) command;
    ImagesContainterParametersBase parameters = cloneCinderDiskCommand.getParameters();
    ImageStatus imageStatus = cloneCinderDiskCommand.getCinderBroker().getDiskStatus(parameters.getDestinationImageId());
    DiskImage disk = (CinderDisk) diskDao.get(parameters.getContainerId());
    if (imageStatus != null && imageStatus != disk.getImageStatus()) {
        switch(imageStatus) {
            case OK:
                setCommandEndStatus(command, false, status, childCmdIds);
                break;
            case ILLEGAL:
                setCommandEndStatus(command, true, status, childCmdIds);
                break;
        }
    }
}
Also used : ImageStatus(org.ovirt.engine.core.common.businessentities.storage.ImageStatus) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) BaseImagesCommand(org.ovirt.engine.core.bll.storage.disk.image.BaseImagesCommand) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

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