Search in sources :

Example 21 with NetworkAttachment

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

the class EffectiveHostNetworkQosTest method testGetQosWhenNetworkAttachmentDoesNotHaveOverriddenQos.

@Test
public void testGetQosWhenNetworkAttachmentDoesNotHaveOverriddenQos() throws Exception {
    HostNetworkQos hostNetworkQos = createHostNetworkQos();
    Network network = createNetworkWithQos(hostNetworkQos);
    NetworkAttachment networkAttachment = createNetworkAttachmentWithoutOverriddenQos();
    when(hostNetworkQosDao.get(network.getQosId())).thenReturn(hostNetworkQos);
    assertThat(effectiveHostNetworkQos.getQos(networkAttachment, network), is(hostNetworkQos));
    verify(hostNetworkQosDao).get(eq(network.getQosId()));
    verifyNoMoreInteractions(hostNetworkQosDao);
}
Also used : AnonymousHostNetworkQos(org.ovirt.engine.core.common.businessentities.network.AnonymousHostNetworkQos) HostNetworkQos(org.ovirt.engine.core.common.businessentities.network.HostNetworkQos) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 22 with NetworkAttachment

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

the class EffectiveHostNetworkQosTest method createNetworkAttachentWithOverriddenQos.

private NetworkAttachment createNetworkAttachentWithOverriddenQos() {
    NetworkAttachment networkAttachment = new NetworkAttachment();
    HostNetworkQos hostNetworkQos = createHostNetworkQos();
    networkAttachment.setHostNetworkQos(AnonymousHostNetworkQos.fromHostNetworkQos(hostNetworkQos));
    return networkAttachment;
}
Also used : AnonymousHostNetworkQos(org.ovirt.engine.core.common.businessentities.network.AnonymousHostNetworkQos) HostNetworkQos(org.ovirt.engine.core.common.businessentities.network.HostNetworkQos) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 23 with NetworkAttachment

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

the class LogicalNetworkModelParametersHelper method createAttachmentWhenAttachingTo.

private NetworkAttachment createAttachmentWhenAttachingTo(VdsNetworkInterface targetNic) {
    NetworkAttachment networkAttachment = new NetworkAttachment(targetNic, networkModel.getNetwork(), NetworkCommonUtils.createDefaultIpConfiguration());
    NetworkParameters netParams = networkModel.getSetupModel().getNetworkToLastDetachParams().get(networkModel.getName());
    if (netParams != null) {
        applyOnAttachmentParamsFrom(netParams, networkAttachment);
    } else {
        VdsNetworkInterface nicToTakeParamsFrom = null;
        if (networkModel.hasVlan()) {
            nicToTakeParamsFrom = getPotentialVlanDevice(targetNic);
        } else {
            nicToTakeParamsFrom = targetNic;
        }
        boolean newlyCreatedBond = nicToTakeParamsFrom != null && nicToTakeParamsFrom.getId() == null;
        if (nicToTakeParamsFrom != null && !newlyCreatedBond) {
            InterfacePropertiesAccessor.FromNic interfacePropertiesAccessor = new InterfacePropertiesAccessor.FromNic(nicToTakeParamsFrom, null);
            applyOnAttachmentParamsFrom(interfacePropertiesAccessor, networkAttachment);
        }
        fixBootProtocolOfMgmtNetworkIfNeeded(networkAttachment);
    }
    return networkAttachment;
}
Also used : InterfacePropertiesAccessor(org.ovirt.engine.ui.uicommonweb.models.hosts.InterfacePropertiesAccessor) NetworkParameters(org.ovirt.engine.ui.uicommonweb.models.hosts.NetworkParameters) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 24 with NetworkAttachment

use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment 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 25 with NetworkAttachment

use of org.ovirt.engine.core.common.businessentities.network.NetworkAttachment 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

NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)167 Test (org.junit.Test)79 Network (org.ovirt.engine.core.common.businessentities.network.Network)62 Guid (org.ovirt.engine.core.compat.Guid)37 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)36 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)35 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)20 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)18 HashMap (java.util.HashMap)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)14 ArrayList (java.util.ArrayList)10 IpConfiguration (org.ovirt.engine.core.common.businessentities.network.IpConfiguration)10 ProviderNetwork (org.ovirt.engine.core.common.businessentities.network.ProviderNetwork)9 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)8 PersistentHostSetupNetworksParameters (org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)7 HostNetworkQos (org.ovirt.engine.core.common.businessentities.network.HostNetworkQos)7 AnonymousHostNetworkQos (org.ovirt.engine.core.common.businessentities.network.AnonymousHostNetworkQos)6 HostSetupNetworksParameters (org.ovirt.engine.core.common.action.HostSetupNetworksParameters)5 BusinessEntityMap (org.ovirt.engine.core.common.businessentities.BusinessEntityMap)5