Search in sources :

Example 76 with NetworkAttachment

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

the class NetworkAttachmentDaoImplTest method testSave.

/**
 * Ensures that the save is working correctly
 */
@Test
public void testSave() {
    dao.save(networkAttachment);
    NetworkAttachment result = dao.get(networkAttachment.getId());
    assertNotNull(result);
    assertNetworkAttachmentEquals(networkAttachment, result);
}
Also used : NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 77 with NetworkAttachment

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

the class NetworkAttachmentDaoImplTest method testRemove.

/**
 * Ensures that the remove is working correctly
 */
@Test
public void testRemove() {
    dao.save(networkAttachment);
    NetworkAttachment result = dao.get(networkAttachment.getId());
    assertNotNull(result);
    dao.remove(networkAttachment.getId());
    assertNull(dao.get(networkAttachment.getId()));
    assertNull(dnsResolverConfigurationDao.get(networkAttachment.getDnsResolverConfiguration().getId()));
}
Also used : NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 78 with NetworkAttachment

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

the class ManageNetworksParametersBuilderImpl method buildParameters.

@Override
public PersistentHostSetupNetworksParameters buildParameters(Guid vdsId, List<Network> labeledNetworksToBeAdded, List<Network> labeledNetworksToBeRemoved, Map<String, VdsNetworkInterface> nicsByLabel, List<Network> updatedNetworks) {
    final PersistentHostSetupNetworksParameters addSetupNetworksParameters = addNetworksByLabelParametersBuilder.buildParameters(vdsId, labeledNetworksToBeAdded, nicsByLabel);
    final PersistentHostSetupNetworksParameters removeSetupNetworksParameters = removeNetworksByLabelParametersBuilder.buildParameters(vdsId, labeledNetworksToBeRemoved);
    PersistentHostSetupNetworksParameters updatedNetworksParams = createHostSetupNetworksParameters(vdsId);
    Map<Guid, NetworkAttachment> networkIdToAttachmentMap = getNetworkIdToAttachmentMap(vdsId);
    List<NetworkAttachment> updatedNetworkAttachments = updatedNetworks.stream().map(Network::getId).map(networkIdToAttachmentMap::get).collect(Collectors.toList());
    updatedNetworkAttachments.forEach(networkAttachment -> networkAttachment.setOverrideConfiguration(true));
    updatedNetworksParams.getNetworkAttachments().addAll(updatedNetworkAttachments);
    final PersistentHostSetupNetworksParameters combinedParams = combine(combine(addSetupNetworksParameters, removeSetupNetworksParameters), updatedNetworksParams);
    combinedParams.setNetworkNames(commaSeparateNetworkNames(Arrays.asList(labeledNetworksToBeAdded.stream(), labeledNetworksToBeRemoved.stream(), updatedNetworks.stream())));
    return combinedParams;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) Network(org.ovirt.engine.core.common.businessentities.network.Network) Guid(org.ovirt.engine.core.compat.Guid) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 79 with NetworkAttachment

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

the class RemoveNetworkParametersBuilder method buildParameters.

public ArrayList<ActionParametersBase> buildParameters(Network network, List<VdsNetworkInterface> labeledNics) {
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    if (managementNetworkUtil.isManagementNetwork(network.getId())) {
        return parameters;
    }
    for (VdsNetworkInterface nic : labeledNics) {
        PersistentHostSetupNetworksParameters setupNetworkParams = createHostSetupNetworksParameters(nic.getVdsId());
        setupNetworkParams.setNetworkNames(network.getName());
        Map<String, VdsNetworkInterface> nicByNetworkName = NetworkUtils.hostInterfacesByNetworkName(getNics(nic.getVdsId()));
        VdsNetworkInterface nicToConfigure = getNicToConfigure(getNics(nic.getVdsId()), nic.getId());
        if (nicToConfigure == null) {
            throw new EngineException(EngineError.LABELED_NETWORK_INTERFACE_NOT_FOUND);
        }
        NetworkAttachment networkAttachment = getNetworkIdToAttachmentMap(nic.getVdsId()).get(network.getId());
        if (networkAttachment != null) {
            if (networkAttachment.getNicId().equals(nicToConfigure.getId())) {
                setupNetworkParams.getRemovedNetworkAttachments().add(networkAttachment.getId());
            }
        } else {
            VdsNetworkInterface nicWithNetwork = nicByNetworkName.get(network.getName());
            if (nicWithNetwork != null && NetworkCommonUtils.stripVlan(nicWithNetwork).equals(nic.getName())) {
                setupNetworkParams.getRemovedUnmanagedNetworks().add(network.getName());
            }
        }
        parameters.add(setupNetworkParams);
    }
    return parameters;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 80 with NetworkAttachment

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

the class HostSetupNetworksModel method initNetworkIdToExistingAttachmentMap.

private void initNetworkIdToExistingAttachmentMap() {
    Map<Guid, Guid> networkIdToExistingAttachmentId = new HashMap<>();
    for (NetworkAttachment attachment : hostSetupNetworksParametersData.getNetworkAttachments()) {
        networkIdToExistingAttachmentId.put(attachment.getNetworkId(), attachment.getId());
    }
    hostSetupNetworksParametersData.setNetworkIdToExistingAttachmentId(networkIdToExistingAttachmentId);
}
Also used : HashMap(java.util.HashMap) 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