Search in sources :

Example 11 with PersistentHostSetupNetworksParameters

use of org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters in project ovirt-engine by oVirt.

the class ManageNetworksParametersBuilderImpl method combine.

private PersistentHostSetupNetworksParameters combine(PersistentHostSetupNetworksParameters addSetupNetworksParameters, PersistentHostSetupNetworksParameters removeSetupNetworksParameters) {
    Guid hostId = addSetupNetworksParameters.getVdsId();
    final PersistentHostSetupNetworksParameters resultParam = createHostSetupNetworksParameters(hostId);
    extendParameters(resultParam, addSetupNetworksParameters);
    extendParameters(resultParam, removeSetupNetworksParameters);
    return resultParam;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) Guid(org.ovirt.engine.core.compat.Guid)

Example 12 with PersistentHostSetupNetworksParameters

use of org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters in project ovirt-engine by oVirt.

the class AddNetworkParametersBuilder method buildParameters.

public ArrayList<ActionParametersBase> buildParameters(Network network, List<VdsNetworkInterface> nics) {
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    for (VdsNetworkInterface nic : nics) {
        PersistentHostSetupNetworksParameters setupNetworkParams = createHostSetupNetworksParameters(nic.getVdsId());
        setupNetworkParams.setNetworkNames(network.getName());
        VdsNetworkInterface nicToConfigure = getNicToConfigure(getNics(nic.getVdsId()), nic.getId());
        if (nicToConfigure == null) {
            throw new EngineException(EngineError.LABELED_NETWORK_INTERFACE_NOT_FOUND);
        }
        NetworkAttachment networkAttachment = new NetworkAttachment(nicToConfigure, network, NetworkUtils.createIpConfigurationFromVdsNetworkInterface(getVlanDevice(nicToConfigure, network.getVlanId())));
        setupNetworkParams.getNetworkAttachments().add(networkAttachment);
        addBootProtocolForRoleNetworkAttachment(nicToConfigure, network, networkAttachment);
        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 13 with PersistentHostSetupNetworksParameters

use of org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters in project ovirt-engine by oVirt.

the class RemoveNetworksByLabelParametersBuilder method buildParameters.

/**
 * Removes a given list of labeled networks from a host
 */
public PersistentHostSetupNetworksParameters buildParameters(Guid hostId, List<Network> networksToRemove) {
    PersistentHostSetupNetworksParameters parameters = createHostSetupNetworksParameters(hostId);
    Map<String, VdsNetworkInterface> nicByNetwork = NetworkUtils.hostInterfacesByNetworkName(getNics(hostId));
    Map<String, VdsNetworkInterface> nicByName = Entities.entitiesByName(getNics(hostId));
    for (Network networkToRemove : networksToRemove) {
        VdsNetworkInterface nicWithNetwork = nicByNetwork.get(networkToRemove.getName());
        if (nicWithNetwork != null) {
            VdsNetworkInterface baseNicWithNetwork = nicByName.get(NetworkCommonUtils.stripVlan(nicWithNetwork));
            if (NetworkUtils.isLabeled(networkToRemove) && NetworkUtils.isLabeled(baseNicWithNetwork) && baseNicWithNetwork.getLabels().contains(networkToRemove.getLabel())) {
                NetworkAttachment networkAttachment = getNetworkIdToAttachmentMap(hostId).get(networkToRemove.getId());
                if (networkAttachment == null) {
                    parameters.getRemovedUnmanagedNetworks().add(networkToRemove.getName());
                } else {
                    parameters.getRemovedNetworkAttachments().add(networkAttachment.getId());
                }
            }
        }
    }
    return parameters;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) Network(org.ovirt.engine.core.common.businessentities.network.Network) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 14 with PersistentHostSetupNetworksParameters

use of org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters in project ovirt-engine by oVirt.

the class ChangeVDSClusterCommand method configureNetworks.

private void configureNetworks() {
    final PersistentHostSetupNetworksParameters params;
    try {
        params = changeClusterParametersBuilder.buildParameters(getVdsId(), getSourceCluster().getId(), getTargetCluster().getId());
    } catch (EngineException e) {
        auditLogDirector.log(this, AuditLogType.CONFIGURE_NETWORK_BY_LABELS_WHEN_CHANGING_CLUSTER_FAILED);
        return;
    }
    ThreadPoolUtil.execute(() -> runInternalAction(ActionType.PersistentHostSetupNetworks, params, cloneContextAndDetachFromParent()));
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 15 with PersistentHostSetupNetworksParameters

use of org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters in project ovirt-engine by oVirt.

the class NetworkClustersToSetupNetworksParametersTransformerImpl method createSetupNetworksParameters.

private List<PersistentHostSetupNetworksParameters> createSetupNetworksParameters(Map<Guid, List<Network>> attachNetworksByHost, Map<Guid, Map<String, VdsNetworkInterface>> labelsToNicsByHost, Map<Guid, List<Network>> detachNetworksByHost, Map<Guid, List<Network>> updates) {
    final List<PersistentHostSetupNetworksParameters> parameters = new ArrayList<>(attachNetworksByHost.size());
    final ManageNetworksParametersBuilder builder = manageNetworksParametersBuilderFactory.create(commandContext, interfaceDao, vdsStaticDao, networkClusterDao, networkAttachmentDao);
    Set<Guid> hostIds = Stream.of(attachNetworksByHost, detachNetworksByHost, updates).flatMap(e -> e.keySet().stream()).collect(Collectors.toSet());
    for (Guid hostId : hostIds) {
        final Map<String, VdsNetworkInterface> nicsByLabel = labelsToNicsByHost.get(hostId);
        parameters.add(builder.buildParameters(hostId, nullToEmptyList(attachNetworksByHost.get(hostId)), nullToEmptyList(detachNetworksByHost.get(hostId)), nicsByLabel == null ? Collections.emptyMap() : nicsByLabel, nullToEmptyList(updates.get(hostId))));
    }
    return parameters;
}
Also used : ManageNetworksParametersBuilderFactory(org.ovirt.engine.core.bll.network.ManageNetworksParametersBuilderFactory) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) NetworkImplementationDetailsUtils(org.ovirt.engine.core.vdsbroker.NetworkImplementationDetailsUtils) Function(java.util.function.Function) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NetworkAttachmentDao(org.ovirt.engine.core.dao.network.NetworkAttachmentDao) ArrayList(java.util.ArrayList) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) Map(java.util.Map) Network(org.ovirt.engine.core.common.businessentities.network.Network) ManageNetworksParametersBuilder(org.ovirt.engine.core.bll.network.ManageNetworksParametersBuilder) PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) CollectionUtils.nullToEmptyList(org.ovirt.engine.core.utils.CollectionUtils.nullToEmptyList) Collection(java.util.Collection) Set(java.util.Set) NetworkDao(org.ovirt.engine.core.dao.network.NetworkDao) Collectors(java.util.stream.Collectors) VdsStaticDao(org.ovirt.engine.core.dao.VdsStaticDao) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) InterfaceDao(org.ovirt.engine.core.dao.network.InterfaceDao) Collections(java.util.Collections) NetworkClusterDao(org.ovirt.engine.core.dao.network.NetworkClusterDao) PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) ManageNetworksParametersBuilder(org.ovirt.engine.core.bll.network.ManageNetworksParametersBuilder) ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

PersistentHostSetupNetworksParameters (org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)15 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)7 Network (org.ovirt.engine.core.common.businessentities.network.Network)6 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)5 ArrayList (java.util.ArrayList)4 EngineException (org.ovirt.engine.core.common.errors.EngineException)4 Guid (org.ovirt.engine.core.compat.Guid)4 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Test (org.junit.Test)1 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)1