Search in sources :

Example 56 with ValidationResult

use of org.ovirt.engine.core.bll.ValidationResult 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 57 with ValidationResult

use of org.ovirt.engine.core.bll.ValidationResult in project ovirt-engine by oVirt.

the class ImportValidator method validateStorageExistsForMemoryDisks.

public ValidationResult validateStorageExistsForMemoryDisks(List<Snapshot> snapshots, boolean allowPartial, Map<Guid, String> failedDisksToImport) {
    for (Snapshot snap : snapshots) {
        if (snap.containsMemory()) {
            DiskImage memoryDump = (DiskImage) getDiskDao().get(snap.getMemoryDiskId());
            StorageDomain dumpSd = getStorageDomainDao().getForStoragePool(memoryDump.getStorageIds().get(0), params.getStoragePoolId());
            ValidationResult dumpSdResult = new StorageDomainValidator(dumpSd).isDomainExistAndActive();
            if (!handleStorageValidationResult(dumpSdResult, memoryDump, snap, failedDisksToImport) && !allowPartial) {
                return dumpSdResult;
            }
            DiskImage memoryConf = (DiskImage) getDiskDao().get(snap.getMetadataDiskId());
            StorageDomain confSd = getStorageDomainDao().getForStoragePool(memoryConf.getStorageIds().get(0), params.getStoragePoolId());
            ValidationResult confSdResult = new StorageDomainValidator(confSd).isDomainExistAndActive();
            if (!handleStorageValidationResult(confSdResult, memoryConf, snap, failedDisksToImport) && !allowPartial) {
                return confSdResult;
            }
        }
    }
    return ValidationResult.VALID;
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 58 with ValidationResult

use of org.ovirt.engine.core.bll.ValidationResult in project ovirt-engine by oVirt.

the class ImportValidator method validateSpaceRequirements.

public ValidationResult validateSpaceRequirements(Collection<DiskImage> diskImages) {
    MultipleStorageDomainsValidator sdValidator = createMultipleStorageDomainsValidator(diskImages);
    ValidationResult result = sdValidator.allDomainsExistAndActive();
    if (!result.isValid()) {
        return result;
    }
    result = sdValidator.allDomainsWithinThresholds();
    if (!result.isValid()) {
        return result;
    }
    if (params.getCopyCollapse()) {
        return sdValidator.allDomainsHaveSpaceForClonedDisks(diskImages);
    }
    return sdValidator.allDomainsHaveSpaceForDisksWithSnapshots(diskImages);
}
Also used : MultipleStorageDomainsValidator(org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 59 with ValidationResult

use of org.ovirt.engine.core.bll.ValidationResult in project ovirt-engine by oVirt.

the class InClusterUpgradeValidator method isUpgradePossible.

public ValidationResult isUpgradePossible(Collection<VDS> hosts, Collection<VM> vms) {
    requireNonNull(hosts);
    requireNonNull(vms);
    final List<String> errors = new ArrayList<>();
    for (final VDS host : hosts) {
        final OS hostOs = OS.fromPackageVersionString(host.getHostOs());
        if (!hostOs.isValid()) {
            errors.addAll(toHostEngineMessage(host, EngineMessage.CLUSTER_UPGRADE_DETAIL_HOST_INVALID_OS));
        }
    }
    for (final VM vm : vms) {
        errors.addAll(checkVmReadyForUpgrade(vm));
    }
    if (errors.isEmpty()) {
        return ValidationResult.VALID;
    } else {
        return new ValidationResult(EngineMessage.CLUSTER_UPGRADE_CAN_NOT_BE_STARTED, errors);
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) OS(org.ovirt.engine.core.utils.OS) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 60 with ValidationResult

use of org.ovirt.engine.core.bll.ValidationResult in project ovirt-engine by oVirt.

the class NetworkAttachmentIpConfigurationValidator method validateIpv4Configuration.

private ValidationResult validateIpv4Configuration(NetworkAttachment networkAttachment) {
    IpConfiguration ipConfiguration = networkAttachment.getIpConfiguration();
    if (!ipConfiguration.hasIpv4PrimaryAddressSet()) {
        return ValidationResult.VALID;
    }
    IPv4Address iPv4Address = ipConfiguration.getIpv4PrimaryAddress();
    String networkName = networkAttachment.getNetworkName();
    String nicName = networkAttachment.getNicName();
    if (iPv4Address.getBootProtocol() == null) {
        return incompleteIpConfigurationValidationResult(EngineMessage.NETWORK_ATTACHMENT_IP_CONFIGURATION_MISSING_BOOT_PROTOCOL, networkName, nicName);
    }
    Ipv4BootProtocol bootProtocol = iPv4Address.getBootProtocol();
    if (bootProtocol == Ipv4BootProtocol.STATIC_IP) {
        if (!validStaticIpv4AddressDetails(iPv4Address)) {
            return incompleteIpConfigurationValidationResult(EngineMessage.NETWORK_ATTACHMENT_IP_CONFIGURATION_STATIC_BOOT_PROTOCOL_MISSING_IP_ADDRESS_DETAILS, networkName, nicName);
        }
    } else {
        if (!isEmptyIpv4AddressDetails(iPv4Address)) {
            return new ValidationResult(EngineMessage.NETWORK_ATTACHMENT_IP_CONFIGURATION_INCOMPATIBLE_BOOT_PROTOCOL_AND_IP_ADDRESS_DETAILS, ReplacementUtils.createSetVariableString(VAR_NETWORK_NAME, networkName), ReplacementUtils.createSetVariableString(VAR_INTERFACE_NAME, nicName), ReplacementUtils.createSetVariableString(VAR_BOOT_PROTOCOL, bootProtocol.getDisplayName()));
        }
    }
    return ValidationResult.VALID;
}
Also used : IpConfiguration(org.ovirt.engine.core.common.businessentities.network.IpConfiguration) Ipv4BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) IPv4Address(org.ovirt.engine.core.common.businessentities.network.IPv4Address)

Aggregations

ValidationResult (org.ovirt.engine.core.bll.ValidationResult)239 Test (org.junit.Test)132 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)49 Guid (org.ovirt.engine.core.compat.Guid)40 ArrayList (java.util.ArrayList)31 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)31 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)30 Network (org.ovirt.engine.core.common.businessentities.network.Network)21 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)19 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)16 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)15 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)13 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)12 List (java.util.List)11 VM (org.ovirt.engine.core.common.businessentities.VM)11 HashSet (java.util.HashSet)10 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)10 GlusterBrickEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity)9 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)7 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)7