Search in sources :

Example 26 with NicLabel

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

the class HostSetupNetworksValidatorTest method testNotRemovingLabeledNetworksLabelMovedToAnotherNicValid.

@Test
public void testNotRemovingLabeledNetworksLabelMovedToAnotherNicValid() {
    VdsNetworkInterface nicWithLabel = createNic("nicWithLabel");
    final String labelName = "lbl1";
    nicWithLabel.setLabels(Collections.singleton(labelName));
    Network network = createNetworkWithNameAndLabel("net", labelName);
    NetworkAttachment removedAttachment = createNetworkAttachment(network, nicWithLabel);
    NicLabel nicLabel = new NicLabel(Guid.newGuid(), nicWithLabel.getName() + "not", labelName);
    assertTestNotRemovingLabeledNetworksValid(nicWithLabel, removedAttachment, new ParametersBuilder().addLabels(nicLabel).build(), network);
}
Also used : FindActiveVmsUsingNetwork(org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NicLabel(org.ovirt.engine.core.common.businessentities.network.NicLabel) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 27 with NicLabel

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

the class HostSetupNetworksValidator method getLabelsToConfigureOnNic.

private Set<String> getLabelsToConfigureOnNic(String nicName) {
    VdsNetworkInterface existingNic = existingInterfacesMap.get(nicName);
    Set<String> labelsToConfigure = new HashSet<>();
    if (existingNic != null) {
        boolean nicWasRemoved = removedBondVdsNetworkInterfaceMap.containsKey(existingNic.getName());
        if (nicWasRemoved) {
            return null;
        }
        Set<String> oldLabels = existingNic.getLabels();
        if (oldLabels != null) {
            for (String label : oldLabels) {
                NicLabel nicLabel = nicLabelByLabel.get(label);
                boolean labelRemovedFromNic = params.getRemovedLabels().contains(label) || (nicLabel != null && !Objects.equals(nicLabel.getNicName(), existingNic.getName()));
                if (!labelRemovedFromNic) {
                    labelsToConfigure.add(label);
                }
            }
        }
        for (NicLabel nicLabel : params.getLabels()) {
            if (existingNic.getName().equals(nicLabel.getNicName())) {
                labelsToConfigure.add(nicLabel.getLabel());
            }
        }
    }
    return labelsToConfigure;
}
Also used : VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NicLabel(org.ovirt.engine.core.common.businessentities.network.NicLabel) HashSet(java.util.HashSet)

Example 28 with NicLabel

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

the class BackendHostResource method toParameters.

private HostSetupNetworksParameters toParameters(Action action) {
    HostSetupNetworksParameters parameters = new HostSetupNetworksParameters(guid);
    Map<Guid, NetworkAttachment> attachmentsById = getBackendNetworkAttachments();
    if (action.isSetModifiedNetworkAttachments()) {
        for (org.ovirt.engine.api.model.NetworkAttachment model : action.getModifiedNetworkAttachments().getNetworkAttachments()) {
            NetworkAttachment attachment = mapNetworkAttachment(attachmentsById, model);
            parameters.getNetworkAttachments().add(attachment);
        }
    }
    if (action.isSetSynchronizedNetworkAttachments()) {
        Map<Guid, NetworkAttachment> networkAttachmentFromParams = Entities.businessEntitiesById(parameters.getNetworkAttachments());
        for (org.ovirt.engine.api.model.NetworkAttachment model : action.getSynchronizedNetworkAttachments().getNetworkAttachments()) {
            if (model.isSetId()) {
                Guid networkAttachmentId = asGuid(model.getId());
                if (networkAttachmentFromParams.containsKey(networkAttachmentId)) {
                    networkAttachmentFromParams.get(networkAttachmentId).setOverrideConfiguration(true);
                } else if (attachmentsById.containsKey(networkAttachmentId)) {
                    NetworkAttachment networkAttachment = attachmentsById.get(networkAttachmentId);
                    networkAttachment.setOverrideConfiguration(true);
                    parameters.getNetworkAttachments().add(networkAttachment);
                } else {
                    return handleError(new EntityNotFoundException("NetworkAttachment.id: " + model.getId()), true);
                }
            }
        }
    }
    if (action.isSetModifiedLabels()) {
        for (NetworkLabel label : action.getModifiedLabels().getNetworkLabels()) {
            NicLabel nicLabel = new NicLabel();
            nicLabel.setLabel(label.getId());
            if (label.isSetHostNic()) {
                nicLabel.setNicId(label.getHostNic().isSetId() ? asGuid(label.getHostNic().getId()) : null);
                nicLabel.setNicName(label.getHostNic().getName());
            }
            parameters.getLabels().add(nicLabel);
        }
    }
    if (action.isSetRemovedLabels()) {
        for (NetworkLabel label : action.getRemovedLabels().getNetworkLabels()) {
            parameters.getRemovedLabels().add(label.getId());
        }
    }
    if (action.isSetRemovedNetworkAttachments()) {
        for (org.ovirt.engine.api.model.NetworkAttachment model : action.getRemovedNetworkAttachments().getNetworkAttachments()) {
            NetworkAttachment attachment = mapNetworkAttachment(attachmentsById, model);
            parameters.getRemovedNetworkAttachments().add(attachment.getId());
        }
    }
    BusinessEntityMap<Bond> bonds = getBackendHostBonds();
    if (action.isSetModifiedBonds()) {
        BusinessEntityMap<VdsNetworkInterface> nicsFromBackend = getBackendNics();
        for (HostNic bond : action.getModifiedBonds().getHostNics()) {
            completeSlaveNames(nicsFromBackend, bond);
            parameters.getCreateOrUpdateBonds().add(mapBonds(bonds, bond));
        }
    }
    if (action.isSetRemovedBonds()) {
        for (HostNic bond : action.getRemovedBonds().getHostNics()) {
            parameters.getRemovedBonds().add(mapBonds(bonds, bond).getId());
        }
    }
    if (action.isSetCheckConnectivity()) {
        parameters.setRollbackOnFailure(action.isCheckConnectivity());
    }
    if (action.isSetConnectivityTimeout()) {
        parameters.setConectivityTimeout(action.getConnectivityTimeout());
    }
    return parameters;
}
Also used : HostSetupNetworksParameters(org.ovirt.engine.core.common.action.HostSetupNetworksParameters) Guid(org.ovirt.engine.core.compat.Guid) NetworkLabel(org.ovirt.engine.api.model.NetworkLabel) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) HostNic(org.ovirt.engine.api.model.HostNic) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NicLabel(org.ovirt.engine.core.common.businessentities.network.NicLabel) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Aggregations

NicLabel (org.ovirt.engine.core.common.businessentities.network.NicLabel)28 Test (org.junit.Test)16 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)16 HostSetupNetworksParameters (org.ovirt.engine.core.common.action.HostSetupNetworksParameters)7 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)6 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)5 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)5 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)4 Network (org.ovirt.engine.core.common.businessentities.network.Network)4 ArrayList (java.util.ArrayList)3 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)3 HashSet (java.util.HashSet)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)2 Guid (org.ovirt.engine.core.compat.Guid)2 HashMap (java.util.HashMap)1 List (java.util.List)1 HostNic (org.ovirt.engine.api.model.HostNic)1 NetworkLabel (org.ovirt.engine.api.model.NetworkLabel)1 Nic (org.ovirt.engine.core.common.businessentities.network.Nic)1