Search in sources :

Example 6 with PersistentHostSetupNetworksParameters

use of org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters 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 7 with PersistentHostSetupNetworksParameters

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

the class AddNetworksByLabelParametersBuilder method buildParameters.

/**
 * Adds a list of labeled networks to a host
 */
public PersistentHostSetupNetworksParameters buildParameters(Guid hostId, List<Network> labeledNetworks, Map<String, VdsNetworkInterface> nicsByLabel) {
    PersistentHostSetupNetworksParameters parameters = createHostSetupNetworksParameters(hostId);
    Set<Network> networksToAdd = getNetworksToConfigure(getNics(hostId), labeledNetworks);
    for (Network network : networksToAdd) {
        VdsNetworkInterface labeledNic = nicsByLabel.get(network.getLabel());
        VdsNetworkInterface nicToConfigure = getNicToConfigure(getNics(hostId), labeledNic.getId());
        if (nicToConfigure == null) {
            throw new EngineException(EngineError.LABELED_NETWORK_INTERFACE_NOT_FOUND);
        }
        // configure the network on the nic
        addAttachmentToParameters(nicToConfigure, network, parameters);
    }
    parameters.setNetworkNames(networksToAdd.stream().map(Network::getName).collect(Collectors.joining(", ")));
    return parameters;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) Network(org.ovirt.engine.core.common.businessentities.network.Network) EngineException(org.ovirt.engine.core.common.errors.EngineException) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 8 with PersistentHostSetupNetworksParameters

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

the class SyncAllHostNetworksCommand method generateSyncAllHostNetworksParameters.

private PersistentHostSetupNetworksParameters generateSyncAllHostNetworksParameters() {
    PersistentHostSetupNetworksParameters parameters = new PersistentHostSetupNetworksParameters(getVdsId());
    QueryReturnValue returnValue = runInternalQuery(QueryType.GetNetworkAttachmentsByHostId, new IdQueryParameters(getVdsId()));
    List<NetworkAttachment> networkAttachments = returnValue.getReturnValue();
    List<NetworkAttachment> unSyncNetworkAttachments = networkAttachments.stream().filter(new NetworkNotInSyncPredicate()).collect(Collectors.toList());
    for (NetworkAttachment networkAttachment : unSyncNetworkAttachments) {
        networkAttachment.setOverrideConfiguration(true);
    }
    parameters.setNetworkAttachments(unSyncNetworkAttachments);
    parameters.setSequence(parameters.getSequence() + 1);
    parameters.setTotal(parameters.getTotal() + 1);
    return parameters;
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) NetworkNotInSyncPredicate(org.ovirt.engine.core.bll.network.predicate.NetworkNotInSyncPredicate) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 9 with PersistentHostSetupNetworksParameters

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

the class HostSetupNetworksParametersBuilder method updateParametersSequencing.

/**
 * Update the given list of parameters to have sequencing according to their order, and have the total count. The
 * updated parameters also will be set to log the command.
 *
 * @param parameters
 *            A list of parameters to update.
 */
public static void updateParametersSequencing(List<ActionParametersBase> parameters) {
    for (int i = 0; i < parameters.size(); i++) {
        PersistentHostSetupNetworksParameters setupNetworkParameters = (PersistentHostSetupNetworksParameters) parameters.get(i);
        setupNetworkParameters.setSequence(i + 1);
        setupNetworkParameters.setTotal(parameters.size());
        setupNetworkParameters.setShouldBeLogged(true);
    }
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)

Example 10 with PersistentHostSetupNetworksParameters

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

the class HostSetupNetworksParametersBuilder method createHostSetupNetworksParameters.

protected PersistentHostSetupNetworksParameters createHostSetupNetworksParameters(Guid hostId) {
    PersistentHostSetupNetworksParameters parameters = new PersistentHostSetupNetworksParameters(hostId);
    parameters.setRollbackOnFailure(true);
    parameters.setShouldBeLogged(false);
    return parameters;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)

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