Search in sources :

Example 36 with VdsNetworkInterface

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

the class HostNetworkTopologyPersisterImpl method findNetworksOnInterfaces.

private Collection<Network> findNetworksOnInterfaces(Collection<VdsNetworkInterface> ifaces, Map<String, Network> clusterNetworksByName) {
    final Collection<Network> networks = new ArrayList<>();
    for (VdsNetworkInterface iface : ifaces) {
        final String interfaceNetworkName = iface.getNetworkName();
        if (clusterNetworksByName.containsKey(interfaceNetworkName)) {
            final Network network = clusterNetworksByName.get(interfaceNetworkName);
            networks.add(network);
        }
    }
    return networks;
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 37 with VdsNetworkInterface

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

the class HostNetworkTopologyPersisterImpl method logChangedDisplayNetwork.

private void logChangedDisplayNetwork(VDS host, Collection<Network> engineHostNetworks, Collection<VdsNetworkInterface> engineInterfaces) {
    if (isVmRunningOnHost(host.getId())) {
        final Network engineDisplayNetwork = findDisplayNetwork(host.getClusterId(), engineHostNetworks);
        if (engineDisplayNetwork == null) {
            return;
        }
        final IsNetworkOnInterfacePredicate isNetworkOnInterfacePredicate = new IsNetworkOnInterfacePredicate(engineDisplayNetwork.getName());
        final VdsNetworkInterface vdsmDisplayInterface = host.getInterfaces().stream().filter(isNetworkOnInterfacePredicate).findFirst().orElse(null);
        final VdsNetworkInterface engineDisplayInterface = engineInterfaces.stream().filter(isNetworkOnInterfacePredicate).findFirst().orElse(null);
        final DisplayInterfaceEqualityPredicate displayIneterfaceEqualityPredicate = new DisplayInterfaceEqualityPredicate(engineDisplayInterface);
        if (// the display interface is't on host anymore
        vdsmDisplayInterface == null || !displayIneterfaceEqualityPredicate.test(vdsmDisplayInterface)) {
            final AuditLogable loggable = createAuditLogForHost(host);
            auditLogDirector.log(loggable, AuditLogType.NETWORK_UPDATE_DISPLAY_FOR_HOST_WITH_ACTIVE_VM);
        }
    }
}
Also used : AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) Network(org.ovirt.engine.core.common.businessentities.network.Network) DisplayInterfaceEqualityPredicate(org.ovirt.engine.core.vdsbroker.vdsbroker.predicates.DisplayInterfaceEqualityPredicate) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) IsNetworkOnInterfacePredicate(org.ovirt.engine.core.vdsbroker.vdsbroker.predicates.IsNetworkOnInterfacePredicate)

Example 38 with VdsNetworkInterface

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

the class HostNetworkTopologyPersisterImpl method getVmNetworksImplementedAsBridgeless.

private String getVmNetworksImplementedAsBridgeless(VDS host, List<Network> clusterNetworks) {
    Map<String, VdsNetworkInterface> interfacesByNetworkName = NetworkUtils.hostInterfacesByNetworkName(host.getInterfaces());
    List<String> networkNames = new ArrayList<>();
    for (Network net : clusterNetworks) {
        if (net.isVmNetwork() && interfacesByNetworkName.containsKey(net.getName()) && !interfacesByNetworkName.get(net.getName()).isBridged()) {
            networkNames.add(net.getName());
        }
    }
    return StringUtils.join(networkNames, ",");
}
Also used : Network(org.ovirt.engine.core.common.businessentities.network.Network) ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 39 with VdsNetworkInterface

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

the class HostNetworkAttachmentsPersister method updateReportedNetworkAttachmentsNotMentionedInRequest.

/**
 * Adds new network attachments for reported networks from the host which weren't associated to a user attachment.
 * Updates existing network attachments which network get reported on different nic.
 * <br/>
 * The network attachment's attributes will be inherited from the network interface on which it is configured.
 * @param networkAttachments already existing or newly created network attachments
 */
private void updateReportedNetworkAttachmentsNotMentionedInRequest(List<NetworkAttachment> networkAttachments) {
    for (VdsNetworkInterface nic : nicsByName.values()) {
        String networkName = nic.getNetworkName();
        if (networkName != null && clusterNetworks.containsKey(networkName)) {
            NetworkAttachment networkAttachmentRelatedToNetwork = getNetworkAttachmentRelatedToNetwork(networkAttachments, clusterNetworks.get(networkName));
            boolean networkAttachmentRelatedToNetworkExist = networkAttachmentRelatedToNetwork != null;
            if (networkAttachmentRelatedToNetworkExist) {
                VdsNetworkInterface baseInterfaceNicOrThis = getBaseInterfaceNicOrThis(nic);
                boolean networkMovedToDifferentNic = !baseInterfaceNicOrThis.getId().equals(networkAttachmentRelatedToNetwork.getNicId());
                if (networkMovedToDifferentNic) {
                    networkAttachmentRelatedToNetwork.setNicId(baseInterfaceNicOrThis.getId());
                    networkAttachmentRelatedToNetwork.setNicName(baseInterfaceNicOrThis.getName());
                    networkAttachmentDao.update(networkAttachmentRelatedToNetwork);
                }
            } else {
                if (!nic.isPartOfBond()) {
                    createNetworkAttachmentForReportedNetworksNotHavingOne(nic, networkName);
                }
            }
        }
    }
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 40 with VdsNetworkInterface

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

the class HostNetworkAttachmentsPersister method persistOrUpdateUserNetworkAttachments.

/**
 * User provided network attachments, which relates to network configured on host, are inserted or updated
 * into database and used to update passed in <code>networkAttachments</code> collection.
 */
private void persistOrUpdateUserNetworkAttachments(List<NetworkAttachment> networkAttachments) {
    Map<Guid, NetworkAttachment> validDbAttachmentsById = Entities.businessEntitiesById(networkAttachments);
    for (NetworkAttachment networkAttachment : userNetworkAttachments) {
        if (networkConfiguredOnHost(networkAttachment.getNetworkId())) {
            VdsNetworkInterface reportedNicToWhichIsNetworkAttached = reportedNicsByNetworkId.get(networkAttachment.getNetworkId());
            Guid reportedNicId = baseInterfaceOfNic(reportedNicToWhichIsNetworkAttached).getId();
            /*this is needed for attaching network to newly created bond, where network attachment
                does not have nicId set and that nic id is known only after vdsm call.
                * */
            if (networkAttachment.getNicId() == null) {
                networkAttachment.setNicId(reportedNicId);
            } else {
                if (!networkAttachment.getNicId().equals(reportedNicId)) {
                    throw new IllegalStateException(INCONSISTENCY_NETWORK_IS_REPORTED_ON_DIFFERENT_NIC_THAN_WAS_SPECIFIED);
                }
            }
            boolean alreadyExistingAttachment = validDbAttachmentsById.containsKey(networkAttachment.getId());
            if (alreadyExistingAttachment) {
                networkAttachmentDao.update(networkAttachment);
                networkAttachments.remove(validDbAttachmentsById.get(networkAttachment.getId()));
                networkAttachments.add(networkAttachment);
            } else {
                networkAttachment.setId(Guid.newGuid());
                networkAttachmentDao.save(networkAttachment);
                networkAttachments.add(networkAttachment);
            }
        }
    }
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

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