Search in sources :

Example 66 with VdsNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface in project ovirt-engine by oVirt.

the class AddNetworkAttachmentCommand method resolveCreatedAttachmentId.

private Guid resolveCreatedAttachmentId(final Guid requiredNetworkId, Guid configuredNicId) {
    VdsNetworkInterface configuredNic = interfaceDao.get(configuredNicId);
    List<NetworkAttachment> attachmentsOnNic = networkAttachmentDao.getAllForNic(configuredNic.getId());
    NetworkAttachment createNetworkAttachment = attachmentsOnNic.stream().filter(networkAttachment -> networkAttachment.getNetworkId().equals(requiredNetworkId)).findFirst().orElse(null);
    if (createNetworkAttachment == null) {
        throw new IllegalStateException();
    }
    return createNetworkAttachment.getId();
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 67 with VdsNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface in project ovirt-engine by oVirt.

the class HostSetupNetworksValidator method validateAttachmentNotReferenceVlanDevice.

private ValidationResult validateAttachmentNotReferenceVlanDevice(NetworkAttachment attachment) {
    VdsNetworkInterface nic = existingInterfacesMap.get(attachment.getNicName());
    EngineMessage engineMessage = EngineMessage.ATTACHMENT_REFERENCE_VLAN_DEVICE;
    return ValidationResult.failWith(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, attachment.getNetworkName()), ReplacementUtils.createSetVariableString(VAR_NIC_NAME, attachment.getNicName())).when(nic != null && NetworkCommonUtils.isVlan(nic));
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage)

Example 68 with VdsNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface in project ovirt-engine by oVirt.

the class HostSetupNetworksValidator method validateModifiedBondSlaves.

ValidationResult validateModifiedBondSlaves(CreateOrUpdateBond modifiedOrNewBond) {
    for (String slaveName : modifiedOrNewBond.getSlaves()) {
        VdsNetworkInterface potentialSlave = existingInterfacesMap.get(slaveName);
        HostInterfaceValidator slaveHostInterfaceValidator = createHostInterfaceValidator(potentialSlave);
        ValidationResult interfaceExists = slaveHostInterfaceValidator.interfaceExists(slaveName);
        if (!interfaceExists.isValid()) {
            return interfaceExists;
        }
        ValidationResult interfaceIsValidSlave = slaveHostInterfaceValidator.interfaceIsValidSlave();
        if (!interfaceIsValidSlave.isValid()) {
            return interfaceIsValidSlave;
        }
        /*
             * definition of currently processed bond references this slave, but this slave already 'slaves' for
             * another bond. This is ok only when this bond will be removed as a part of this request
             * or the slave will be removed from its former bond, as a part of this request.
             */
        String currentSlavesBondName = potentialSlave.getBondName();
        if (potentialSlave.isPartOfBond() && /*
                         * we're creating new bond, and it's definition contains reference to slave already assigned
                         * to a different bond.
                         */
        (!potentialSlave.isPartOfBond(modifiedOrNewBond.getName()) && // … but this bond is also removed in this request, so it's ok.
        !isBondRemoved(currentSlavesBondName) && // … or slave was removed from its former bond
        !bondIsUpdatedAndDoesNotContainCertainSlave(slaveName, currentSlavesBondName))) {
            EngineMessage engineMessage = EngineMessage.NETWORK_INTERFACE_ALREADY_IN_BOND;
            return new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, slaveName));
        }
        ValidationResult slaveHasAttachedNetworksValidationResult = validateSlaveHasNoNetworks(potentialSlave.getName());
        if (!slaveHasAttachedNetworksValidationResult.isValid()) {
            return slaveHasAttachedNetworksValidationResult;
        }
        if (slaveUsedMultipleTimesInDifferentBonds(slaveName)) {
            return new ValidationResult(EngineMessage.NETWORK_INTERFACE_REFERENCED_AS_A_SLAVE_MULTIPLE_TIMES, ReplacementUtils.createSetVariableString("NETWORK_INTERFACE_REFERENCED_AS_A_SLAVE_MULTIPLE_TIMES_ENTITY", slaveName));
        }
        ValidationResult slaveHasNoLabelsValidationResult = validateSlaveHasNoLabels(slaveName);
        if (!slaveHasNoLabelsValidationResult.isValid()) {
            return slaveHasNoLabelsValidationResult;
        }
    }
    return ValidationResult.VALID;
}
Also used : HostInterfaceValidator(org.ovirt.engine.core.bll.validator.HostInterfaceValidator) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage)

Example 69 with VdsNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface in project ovirt-engine by oVirt.

the class GetInterfacesByLabelForNetworkQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Network network = networkDao.get(getParameters().getId());
    Set<VdsNetworkInterface> interfacesByLabelForNetwork = new HashSet<>();
    if (network == null) {
        getQueryReturnValue().setReturnValue(interfacesByLabelForNetwork);
        return;
    }
    List<NetworkCluster> clusters = networkClusterDao.getAllForNetwork(network.getId());
    if (clusters.isEmpty()) {
        getQueryReturnValue().setReturnValue(interfacesByLabelForNetwork);
        return;
    }
    List<VdsNetworkInterface> labeledNics = new ArrayList<>();
    for (NetworkCluster networkCluster : clusters) {
        labeledNics.addAll(interfaceDao.getAllInterfacesByLabelForCluster(networkCluster.getClusterId(), network.getLabel()));
    }
    if (labeledNics.isEmpty()) {
        getQueryReturnValue().setReturnValue(interfacesByLabelForNetwork);
        return;
    }
    List<VdsNetworkInterface> networkNics = interfaceDao.getVdsInterfacesByNetworkId(network.getId());
    Map<String, VdsNetworkInterface> labeledNicsByName = Entities.entitiesByName(labeledNics);
    for (VdsNetworkInterface networkNic : networkNics) {
        if (labeledNicsByName.containsKey(NetworkCommonUtils.stripVlan(networkNic))) {
            interfacesByLabelForNetwork.add(networkNic);
        }
    }
    getQueryReturnValue().setReturnValue(interfacesByLabelForNetwork);
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) HashSet(java.util.HashSet)

Example 70 with VdsNetworkInterface

use of org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface in project ovirt-engine by oVirt.

the class GetNetworkLabelsByHostNicIdQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    VdsNetworkInterface nic = interfaceDao.get(getParameters().getId());
    getQueryReturnValue().setReturnValue(nic == null || !NetworkUtils.isLabeled(nic) ? Collections.<NetworkLabel>emptyList() : convertToNetworkLabels(nic.getLabels()));
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NetworkLabel(org.ovirt.engine.core.common.businessentities.network.pseudo.NetworkLabel)

Aggregations

VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)233 Test (org.junit.Test)68 Network (org.ovirt.engine.core.common.businessentities.network.Network)47 ArrayList (java.util.ArrayList)46 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)35 Guid (org.ovirt.engine.core.compat.Guid)30 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)24 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)23 List (java.util.List)19 HashMap (java.util.HashMap)18 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)18 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)17 NicLabel (org.ovirt.engine.core.common.businessentities.network.NicLabel)16 VDS (org.ovirt.engine.core.common.businessentities.VDS)15 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)14 Nic (org.ovirt.engine.core.common.businessentities.network.Nic)13 Map (java.util.Map)12 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)9 HostNetworkQos (org.ovirt.engine.core.common.businessentities.network.HostNetworkQos)8 Vlan (org.ovirt.engine.core.common.businessentities.network.Vlan)8