Search in sources :

Example 1 with ReadMacPool

use of org.ovirt.engine.core.bll.network.macpool.ReadMacPool in project ovirt-engine by oVirt.

the class ExternalVmMacsFinder method findExternalMacAddresses.

public Set<String> findExternalMacAddresses(VM vm) {
    final List<VmNetworkInterface> interfaces = vm.getInterfaces();
    if (interfaces == null) {
        return Collections.emptySet();
    }
    final ReadMacPool readMacPool = macPoolPerCluster.getMacPoolForCluster(vm.getClusterId());
    return interfaces.stream().map(VmNetworkInterface::getMacAddress).filter(Objects::nonNull).filter(((Predicate<String>) readMacPool::isMacInRange).negate()).collect(Collectors.toSet());
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) ReadMacPool(org.ovirt.engine.core.bll.network.macpool.ReadMacPool) Objects(java.util.Objects) Predicate(java.util.function.Predicate)

Example 2 with ReadMacPool

use of org.ovirt.engine.core.bll.network.macpool.ReadMacPool in project ovirt-engine by oVirt.

the class ValidateVmMacsQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    // Map with a VM id as the key and violation messages (that are related to the VM) as the values.
    final Map<Guid, List<List<String>>> result = new HashMap<>();
    for (Entry<Guid, List<VM>> clusterEntry : getParameters().getVmsByCluster().entrySet()) {
        final Guid clusterId = clusterEntry.getKey();
        final List<VM> clusterVms = clusterEntry.getValue();
        final ReadMacPool macPool = macPoolPerCluster.getMacPoolForCluster(clusterId);
        final List<VmMacsValidation> vmMacsValidations = vmMacsValidationsFactory.createVmMacsValidationList(clusterId, macPool);
        clusterVms.forEach(vm -> result.put(vm.getId(), validateVm(vm, vmMacsValidations)));
    }
    getQueryReturnValue().setReturnValue(result);
}
Also used : VmMacsValidation(org.ovirt.engine.core.bll.network.vm.mac.VmMacsValidation) HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) ReadMacPool(org.ovirt.engine.core.bll.network.macpool.ReadMacPool) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid)

Example 3 with ReadMacPool

use of org.ovirt.engine.core.bll.network.macpool.ReadMacPool in project ovirt-engine by oVirt.

the class MoveMacs method canMigrateMacsToAnotherMacPool.

public ValidationResult canMigrateMacsToAnotherMacPool(ReadMacPool targetPool, List<String> macsToMigrate) {
    if (targetPool.isDuplicateMacAddressesAllowed()) {
        return ValidationResult.VALID;
    }
    Map<String, Long> occurrenceCount = macsToMigrate.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    List<String> problematicMacs = macsToMigrate.stream().distinct().filter(mac -> targetPool.isMacInUse(mac) || occurrenceCount.get(mac) > 1).collect(Collectors.toList());
    EngineMessage engineMessage = ACTION_TYPE_FAILED_CANNOT_MIGRATE_MACS_DUE_TO_DUPLICATES;
    Collection<String> replacements = ReplacementUtils.getListVariableAssignmentString(engineMessage, problematicMacs);
    return ValidationResult.failWith(engineMessage, replacements).when(!problematicMacs.isEmpty());
}
Also used : ReadMacPool(org.ovirt.engine.core.bll.network.macpool.ReadMacPool) ACTION_TYPE_FAILED_CANNOT_MIGRATE_MACS_DUE_TO_DUPLICATES(org.ovirt.engine.core.common.errors.EngineMessage.ACTION_TYPE_FAILED_CANNOT_MIGRATE_MACS_DUE_TO_DUPLICATES) Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) Singleton(javax.inject.Singleton) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) VmNicDao(org.ovirt.engine.core.dao.network.VmNicDao) Objects(java.util.Objects) Inject(javax.inject.Inject) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Map(java.util.Map) MacPoolPerCluster(org.ovirt.engine.core.bll.network.macpool.MacPoolPerCluster) MacPool(org.ovirt.engine.core.bll.network.macpool.MacPool) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage)

Example 4 with ReadMacPool

use of org.ovirt.engine.core.bll.network.macpool.ReadMacPool in project ovirt-engine by oVirt.

the class ChangeVMClusterCommand method validate.

@Override
protected boolean validate() {
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    if (!isInternalExecution() && !ObjectIdentityChecker.canUpdateField(getVm(), "clusterId", getVm().getStatus())) {
        addValidationMessage(EngineMessage.VM_STATUS_NOT_VALID_FOR_UPDATE);
        return false;
    }
    ChangeVmClusterValidator validator = ChangeVmClusterValidator.create(this, newClusterId, getParameters().getVmCustomCompatibilityVersion());
    if (macPoolChanged()) {
        ReadMacPool macPoolForTargetCluster = macPoolPerCluster.getMacPoolForCluster(newClusterId);
        ValidationResult validationResult = moveMacs.canMigrateMacsToAnotherMacPool(macPoolForTargetCluster, getMacsToMigrate());
        if (!validationResult.isValid()) {
            return validate(validationResult);
        }
    }
    return validator.validate();
}
Also used : ReadMacPool(org.ovirt.engine.core.bll.network.macpool.ReadMacPool)

Example 5 with ReadMacPool

use of org.ovirt.engine.core.bll.network.macpool.ReadMacPool in project ovirt-engine by oVirt.

the class VmDeviceUtils method canPlugInterface.

private boolean canPlugInterface(VmNic iface, VmBase vmBase) {
    ReadMacPool macPool = macPoolPerCluster.getMacPoolForCluster(vmBase.getClusterId());
    VmInterfaceManager vmIfaceManager = new VmInterfaceManager();
    if (vmIfaceManager.tooManyPluggedInterfaceWithSameMac(iface, macPool)) {
        vmIfaceManager.auditLogMacInUseUnplug(iface, vmBase.getName());
        return false;
    } else {
        return true;
    }
}
Also used : ReadMacPool(org.ovirt.engine.core.bll.network.macpool.ReadMacPool) VmInterfaceManager(org.ovirt.engine.core.bll.network.VmInterfaceManager)

Aggregations

ReadMacPool (org.ovirt.engine.core.bll.network.macpool.ReadMacPool)5 List (java.util.List)2 Objects (java.util.Objects)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Singleton (javax.inject.Singleton)1 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)1 VmInterfaceManager (org.ovirt.engine.core.bll.network.VmInterfaceManager)1 MacPool (org.ovirt.engine.core.bll.network.macpool.MacPool)1 MacPoolPerCluster (org.ovirt.engine.core.bll.network.macpool.MacPoolPerCluster)1 VmMacsValidation (org.ovirt.engine.core.bll.network.vm.mac.VmMacsValidation)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1 VM (org.ovirt.engine.core.common.businessentities.VM)1