Search in sources :

Example 76 with Network

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

the class NetworkIdNetworkNameCompleter method completeNetworkAttachment.

private void completeNetworkAttachment(NetworkAttachment networkAttachment, BusinessEntityMap<Network> clusterNetworks, Guid dataCenterId) {
    Guid networkId = networkAttachment.getNetworkId();
    String networkName = networkAttachment.getNetworkName();
    boolean networkNameSpecified = networkName != null;
    boolean networkIdSpecified = networkId != null;
    if (!networkIdSpecified && !networkNameSpecified || networkIdSpecified && networkNameSpecified) {
        return;
    }
    if (networkNameSpecified) {
        Network network = getNetworkByName(networkName, clusterNetworks, dataCenterId);
        boolean networkByNameExists = network != null;
        if (networkByNameExists) {
            networkAttachment.setNetworkId(network.getId());
        }
    }
    if (networkIdSpecified) {
        Network network = getNetworkById(networkId, clusterNetworks);
        boolean networkByIdExists = network != null;
        if (networkByIdExists) {
            networkAttachment.setNetworkName(network.getName());
        }
    }
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) Guid(org.ovirt.engine.core.compat.Guid)

Example 77 with Network

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

the class NetworkMtuValidator method networksOnNicMatchMtu.

private boolean networksOnNicMatchMtu(List<Network> networksOnNic) {
    final Network nonVlanNetwork = networksOnNic.stream().filter(network -> !NetworkUtils.isVlan(network)).findFirst().orElse(null);
    if (nonVlanNetwork == null) {
        return true;
    }
    int nonVlanNetworkActualMtu = getMtuActualValue(nonVlanNetwork);
    return networksOnNic.stream().map(network -> getMtuActualValue(network)).noneMatch(networkMtu -> networkMtu != nonVlanNetworkActualMtu);
}
Also used : List(java.util.List) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Collection(java.util.Collection) Map(java.util.Map) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) HashMap(java.util.HashMap) Network(org.ovirt.engine.core.common.businessentities.network.Network) BusinessEntityMap(org.ovirt.engine.core.common.businessentities.BusinessEntityMap) NetworkUtils(org.ovirt.engine.core.utils.NetworkUtils) ArrayList(java.util.ArrayList) Network(org.ovirt.engine.core.common.businessentities.network.Network)

Example 78 with Network

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

the class NetworkMtuValidator method getNetworksOnNics.

Map<String, List<Network>> getNetworksOnNics(Collection<NetworkAttachment> attachmentsToConfigure) {
    Map<String, List<Network>> nicsToNetworks = new HashMap<>();
    for (NetworkAttachment attachment : attachmentsToConfigure) {
        String nicName = attachment.getNicName();
        if (!nicsToNetworks.containsKey(nicName)) {
            nicsToNetworks.put(nicName, new ArrayList<>());
        }
        Network networkToConfigure = networkBusinessEntityMap.get(attachment.getNetworkId());
        nicsToNetworks.get(nicName).add(networkToConfigure);
    }
    return nicsToNetworks;
}
Also used : HashMap(java.util.HashMap) Network(org.ovirt.engine.core.common.businessentities.network.Network) List(java.util.List) ArrayList(java.util.ArrayList) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 79 with Network

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

the class NicLabelsCompleter method completeNetworkAttachmentsByLabels.

private void completeNetworkAttachmentsByLabels() {
    for (NicLabel nicLabel : params.getLabels()) {
        List<Network> labelNetworks = labelToNetworks.get(nicLabel.getLabel());
        if (labelNetworks == null) {
            continue;
        }
        for (Network network : labelNetworks) {
            NetworkAttachment newOrModifiedNetworkAttachment = attachmentsByNetworkId.get(network.getId());
            NetworkAttachment existingNetworkAttachment = existingNetworkAttachmentsByNetworkId.get(network.getId());
            boolean existingAttachmentRemoved = existingNetworkAttachment == null ? false : params.getRemovedNetworkAttachments().contains(existingNetworkAttachment.getId());
            boolean noNewOrModifiedNetworkAttachment = newOrModifiedNetworkAttachment == null;
            NetworkAttachment attachmentToConfigure = noNewOrModifiedNetworkAttachment && !existingAttachmentRemoved ? existingNetworkAttachment : newOrModifiedNetworkAttachment;
            if (attachmentToConfigure == null) {
                params.getNetworkAttachments().add(createNetworkAttachment(nicLabel.getNicId(), nicLabel.getNicName(), network.getId(), network.getName()));
            } else if (!Objects.equals(attachmentToConfigure.getNicName(), nicLabel.getNicName()) && noNewOrModifiedNetworkAttachment) {
                NetworkAttachment updatedNetworkAttachment = new NetworkAttachment(existingNetworkAttachment);
                updatedNetworkAttachment.setNicId(nicLabel.getNicId());
                updatedNetworkAttachment.setNicName(nicLabel.getNicName());
                params.getNetworkAttachments().add(updatedNetworkAttachment);
            }
        }
    }
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) NicLabel(org.ovirt.engine.core.common.businessentities.network.NicLabel) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 80 with Network

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

the class ImportExternalNetworkCommand method getNetwork.

protected Network getNetwork() {
    if (network == null) {
        NetworkProviderProxy proxy = providerProxyFactory.create(getProvider());
        String networkId = getParameters().getNetworkExternalId();
        network = proxy.getAll().stream().filter(network -> networkId.equals(network.getProvidedBy().getExternalId())).findFirst().orElse(null);
    }
    return network;
}
Also used : NonTransactiveCommandAttribute(org.ovirt.engine.core.bll.NonTransactiveCommandAttribute) LockProperties(org.ovirt.engine.core.common.action.LockProperties) Guid(org.ovirt.engine.core.compat.Guid) ProviderDao(org.ovirt.engine.core.dao.provider.ProviderDao) Provider(org.ovirt.engine.core.common.businessentities.Provider) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) Inject(javax.inject.Inject) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) ImportExternalNetworkParameters(org.ovirt.engine.core.common.action.ImportExternalNetworkParameters) Map(java.util.Map) NetworkProviderProxy(org.ovirt.engine.core.bll.provider.network.NetworkProviderProxy) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkLocking(org.ovirt.engine.core.bll.NetworkLocking) Pair(org.ovirt.engine.core.common.utils.Pair) ProviderProxyFactory(org.ovirt.engine.core.bll.provider.ProviderProxyFactory) NetworkValidator(org.ovirt.engine.core.bll.validator.NetworkValidator) NetworkProviderValidator(org.ovirt.engine.core.bll.provider.NetworkProviderValidator) InternalImportExternalNetworkParameters(org.ovirt.engine.core.common.action.InternalImportExternalNetworkParameters) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) CommandBase(org.ovirt.engine.core.bll.CommandBase) List(java.util.List) PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) Collections(java.util.Collections) NetworkProviderProxy(org.ovirt.engine.core.bll.provider.network.NetworkProviderProxy)

Aggregations

Network (org.ovirt.engine.core.common.businessentities.network.Network)292 Test (org.junit.Test)105 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)63 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)47 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)46 ArrayList (java.util.ArrayList)44 Guid (org.ovirt.engine.core.compat.Guid)44 ProviderNetwork (org.ovirt.engine.core.common.businessentities.network.ProviderNetwork)39 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)23 List (java.util.List)21 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)21 HashMap (java.util.HashMap)19 NetworkCluster (org.ovirt.engine.core.common.businessentities.network.NetworkCluster)19 Map (java.util.Map)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 VnicProfile (org.ovirt.engine.core.common.businessentities.network.VnicProfile)13 HashSet (java.util.HashSet)9 Set (java.util.Set)9 BusinessEntityMap (org.ovirt.engine.core.common.businessentities.BusinessEntityMap)9 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)9