Search in sources :

Example 1 with BaseDisk

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

the class ImportHostedEngineStorageDomainCommand method removeHostedEngineLunDisk.

private void removeHostedEngineLunDisk() {
    List<BaseDisk> disks = baseDiskDao.getDisksByAlias(StorageConstants.HOSTED_ENGINE_LUN_DISK_ALIAS);
    if (disks != null && !disks.isEmpty()) {
        BaseDisk heDirectLun = disks.get(0);
        ActionReturnValue removeDisk = backend.runInternalAction(ActionType.RemoveDisk, new RemoveDiskParameters(heDirectLun.getId()));
        if (!removeDisk.getSucceeded()) {
            setSucceeded(false);
            log.error("Failed to remove the hosted engine direct lun disk");
            return;
        }
    }
    setSucceeded(true);
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) RemoveDiskParameters(org.ovirt.engine.core.common.action.RemoveDiskParameters)

Example 2 with BaseDisk

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

the class CreateSnapshotForVmCommand method validate.

@Override
protected boolean validate() {
    if (getVm() == null) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
        return false;
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    Set<Guid> specifiedDiskIds = getParameters().getDiskIds();
    if (specifiedDiskIds != null && !specifiedDiskIds.isEmpty()) {
        if (!isSpecifiedDisksExist(specifiedDiskIds)) {
            return false;
        }
        List<Disk> allDisksForVm = diskDao.getAllForVm(getVm().getId());
        String notAllowSnapshot = allDisksForVm.stream().filter(disk -> specifiedDiskIds.contains(disk.getId())).filter(disk -> !disk.isAllowSnapshot()).map(BaseDisk::getDiskAlias).collect(Collectors.joining(", "));
        if (!notAllowSnapshot.isEmpty()) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISK_SNAPSHOT_NOT_SUPPORTED, String.format("$diskAliases %s", notAllowSnapshot));
        }
        Set<Guid> guidsOfVmDisks = allDisksForVm.stream().map(BaseDisk::getId).collect(Collectors.toSet());
        String notAttachedToVm = specifiedDiskIds.stream().filter(guid -> !guidsOfVmDisks.contains(guid)).map(guid -> diskDao.get(guid)).map(BaseDisk::getDiskAlias).collect(Collectors.joining(", "));
        if (!notAttachedToVm.isEmpty()) {
            String[] replacements = { ReplacementUtils.createSetVariableString("VmName", getVm().getName()), ReplacementUtils.createSetVariableString("diskAliases", notAttachedToVm) };
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_DISKS_NOT_ATTACHED_TO_VM, replacements);
        }
    }
    // Initialize validators.
    VmValidator vmValidator = createVmValidator();
    StoragePoolValidator spValidator = createStoragePoolValidator();
    if (!(validateVM(vmValidator) && validate(spValidator.existsAndUp()) && validate(vmValidator.vmNotIlegal()) && validate(vmValidator.vmNotLocked()) && validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) && validate(snapshotsValidator.vmNotInPreview(getVmId())) && validate(vmValidator.vmNotDuringMigration()) && validate(vmValidator.vmNotRunningStateless()) && (!getParameters().isSaveMemory() || validate(vmValidator.vmNotHavingPciPassthroughDevices())))) {
        return false;
    }
    List<DiskImage> disksList = getDisksListForChecks();
    if (disksList.size() > 0) {
        DiskImagesValidator diskImagesValidator = createDiskImageValidator(disksList);
        if (!(validate(diskImagesValidator.diskImagesNotLocked()) && validate(diskImagesValidator.diskImagesNotIllegal()) && validate(vmValidator.vmWithoutLocalDiskUserProperty()))) {
            return false;
        }
    }
    return validateStorage();
}
Also used : LockMessagesMatchUtil(org.ovirt.engine.core.bll.LockMessagesMatchUtil) DiskExistenceValidator(org.ovirt.engine.core.bll.validator.storage.DiskExistenceValidator) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) EngineException(org.ovirt.engine.core.common.errors.EngineException) SnapshotDao(org.ovirt.engine.core.dao.SnapshotDao) SerialChildExecutingCommand(org.ovirt.engine.core.bll.SerialChildExecutingCommand) StatelessSnapshotMemoryImageBuilder(org.ovirt.engine.core.bll.memory.StatelessSnapshotMemoryImageBuilder) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) MemoryImageBuilder(org.ovirt.engine.core.bll.memory.MemoryImageBuilder) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) CinderDisksValidator(org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator) Map(java.util.Map) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) Instance(javax.enterprise.inject.Instance) RemoveMemoryVolumesParameters(org.ovirt.engine.core.common.action.RemoveMemoryVolumesParameters) BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) CreateEntity(org.ovirt.engine.core.common.validation.group.CreateEntity) LiveSnapshotMemoryImageBuilder(org.ovirt.engine.core.bll.memory.LiveSnapshotMemoryImageBuilder) ONLY_SNAPABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_SNAPABLE) LockMessage(org.ovirt.engine.core.bll.LockMessage) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmOverheadCalculator(org.ovirt.engine.core.common.scheduling.VmOverheadCalculator) CreateSnapshotForVmParameters(org.ovirt.engine.core.common.action.CreateSnapshotForVmParameters) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) Set(java.util.Set) Collectors(java.util.stream.Collectors) VmDao(org.ovirt.engine.core.dao.VmDao) CreateSnapshotDiskParameters(org.ovirt.engine.core.common.action.CreateSnapshotDiskParameters) ONLY_NOT_SHAREABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_NOT_SHAREABLE) List(java.util.List) Injector(org.ovirt.engine.core.di.Injector) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) QuotaStorageDependent(org.ovirt.engine.core.bll.quota.QuotaStorageDependent) SnapshotVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SnapshotVDSCommandParameters) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) LockProperties(org.ovirt.engine.core.common.action.LockProperties) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) TransactionSupport(org.ovirt.engine.core.utils.transaction.TransactionSupport) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) MemoryStorageHandler(org.ovirt.engine.core.bll.memory.MemoryStorageHandler) ArrayList(java.util.ArrayList) CommandCoordinatorUtil(org.ovirt.engine.core.bll.tasks.CommandCoordinatorUtil) Inject(javax.inject.Inject) ExecutionHandler(org.ovirt.engine.core.bll.job.ExecutionHandler) MemoryUtils(org.ovirt.engine.core.bll.memory.MemoryUtils) SerialChildCommandsExecutionCallback(org.ovirt.engine.core.bll.SerialChildCommandsExecutionCallback) NullableMemoryImageBuilder(org.ovirt.engine.core.bll.memory.NullableMemoryImageBuilder) ONLY_ACTIVE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_ACTIVE) LinkedList(java.util.LinkedList) VmCommand(org.ovirt.engine.core.bll.VmCommand) Pair(org.ovirt.engine.core.common.utils.Pair) ImagesHandler(org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) LockingGroup(org.ovirt.engine.core.common.locks.LockingGroup) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Typed(javax.enterprise.inject.Typed) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) ImagesActionsParametersBase(org.ovirt.engine.core.common.action.ImagesActionsParametersBase) CommandStatus(org.ovirt.engine.core.compat.CommandStatus) QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) EngineError(org.ovirt.engine.core.common.errors.EngineError) TransactionScopeOption(org.ovirt.engine.core.compat.TransactionScopeOption) CommandCallback(org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback) DiskDao(org.ovirt.engine.core.dao.DiskDao) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) VdsAndVmIDVDSParametersBase(org.ovirt.engine.core.common.vdscommands.VdsAndVmIDVDSParametersBase) Comparator(java.util.Comparator) Collections(java.util.Collections) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) ImageDao(org.ovirt.engine.core.dao.ImageDao) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) Guid(org.ovirt.engine.core.compat.Guid) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator)

Example 3 with BaseDisk

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

the class MultipleVmsValidator method vmNotHavingPluggedDiskSnapshots.

/**
 * @return ValidationResult indicating whether there are plugged disk snapshots
 */
public ValidationResult vmNotHavingPluggedDiskSnapshots(EngineMessage message) {
    List<String> vmPluggedDiskSnapshotsInfo = null;
    for (VM vm : vms) {
        List<DiskImage> pluggedDiskSnapshots = DbFacade.getInstance().getDiskImageDao().getAttachedDiskSnapshotsToVm(vm.getId(), Boolean.TRUE);
        if (!pluggedDiskSnapshots.isEmpty()) {
            if (vmPluggedDiskSnapshotsInfo == null) {
                vmPluggedDiskSnapshotsInfo = new LinkedList<>();
            }
            List<String> pluggedDiskSnapshotAliases = new LinkedList<>();
            for (BaseDisk disk : pluggedDiskSnapshots) {
                pluggedDiskSnapshotAliases.add(disk.getDiskAlias());
            }
            vmPluggedDiskSnapshotsInfo.add(String.format("%s / %s", vm.getName(), StringUtils.join(pluggedDiskSnapshotAliases, ",")));
        }
    }
    if (vmPluggedDiskSnapshotsInfo != null) {
        return new ValidationResult(message, String.format("$disksInfo %s", String.format(StringUtils.join(vmPluggedDiskSnapshotsInfo, "%n"))));
    }
    return ValidationResult.VALID;
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) LinkedList(java.util.LinkedList)

Example 4 with BaseDisk

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

the class RunVmValidator method validateIsoPath.

protected ValidationResult validateIsoPath(VM vm, String diskPath, String floppyPath, Guid activeIsoDomainId) {
    if (vm.isAutoStartup()) {
        return ValidationResult.VALID;
    }
    if (StringUtils.isEmpty(vm.getIsoPath()) && StringUtils.isEmpty(diskPath) && StringUtils.isEmpty(floppyPath)) {
        return ValidationResult.VALID;
    }
    if (!StringUtils.isEmpty(floppyPath) && activeIsoDomainId == null) {
        return new ValidationResult(EngineMessage.VM_CANNOT_RUN_FROM_CD_WITHOUT_ACTIVE_STORAGE_DOMAIN_ISO);
    }
    String effectiveIsoPath = StringUtils.isEmpty(diskPath) ? vm.getIsoPath() : diskPath;
    if (!StringUtils.isEmpty(effectiveIsoPath)) {
        if (effectiveIsoPath.matches(ValidationUtils.GUID)) {
            BaseDisk disk = diskDao.get(Guid.createGuidFromString(effectiveIsoPath));
            if (disk == null || disk.getContentType() != DiskContentType.ISO) {
                return new ValidationResult(EngineMessage.ERROR_CANNOT_FIND_ISO_IMAGE_PATH);
            }
            Guid domainId = ((DiskImage) disk).getStorageIds().get(0);
            StoragePoolIsoMap spim = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(domainId, vm.getStoragePoolId()));
            if (spim == null || spim.getStatus() != StorageDomainStatus.Active) {
                return new ValidationResult(EngineMessage.VM_CANNOT_RUN_FROM_CD_WITHOUT_ACTIVE_STORAGE_DOMAIN_ISO);
            }
        } else if (activeIsoDomainId == null) {
            return new ValidationResult(EngineMessage.VM_CANNOT_RUN_FROM_CD_WITHOUT_ACTIVE_STORAGE_DOMAIN_ISO);
        } else if (!isRepoImageExists(effectiveIsoPath, activeIsoDomainId, ImageFileType.ISO)) {
            return new ValidationResult(EngineMessage.ERROR_CANNOT_FIND_ISO_IMAGE_PATH);
        }
        return ValidationResult.VALID;
    }
    if (!StringUtils.isEmpty(floppyPath) && !isRepoImageExists(floppyPath, activeIsoDomainId, ImageFileType.Floppy)) {
        return new ValidationResult(EngineMessage.ERROR_CANNOT_FIND_FLOPPY_IMAGE_PATH);
    }
    return ValidationResult.VALID;
}
Also used : StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 5 with BaseDisk

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

the class BaseDiskDaoTest method generateNewEntity.

@Override
protected BaseDisk generateNewEntity() {
    BaseDisk d = new BaseDisk();
    d.setId(Guid.newGuid());
    d.setWipeAfterDelete(true);
    d.setPropagateErrors(PropagateErrors.Off);
    d.setDiskAlias("DiskName");
    d.setSgio(ScsiGenericIO.FILTERED);
    return d;
}
Also used : BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk)

Aggregations

BaseDisk (org.ovirt.engine.core.common.businessentities.storage.BaseDisk)15 Guid (org.ovirt.engine.core.compat.Guid)7 Test (org.junit.Test)6 VM (org.ovirt.engine.core.common.businessentities.VM)4 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Instance (javax.enterprise.inject.Instance)1 Typed (javax.enterprise.inject.Typed)1 Inject (javax.inject.Inject)1