Search in sources :

Example 1 with Bond

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

the class VdsBrokerObjectsBuilder method addHostBondDevices.

private static void addHostBondDevices(VDS vds, Map<String, Object> struct) {
    Map<String, Map<String, Object>> bonds = (Map<String, Map<String, Object>>) struct.get(VdsProperties.NETWORK_BONDINGS);
    if (bonds != null) {
        for (Entry<String, Map<String, Object>> entry : bonds.entrySet()) {
            Bond bond = new Bond();
            updateCommonInterfaceData(bond, vds, entry);
            bond.setBonded(true);
            Map<String, Object> bondProperties = entry.getValue();
            if (bondProperties != null) {
                bond.setMacAddress((String) bondProperties.get("hwaddr"));
                if (bondProperties.get("slaves") != null) {
                    addBondDeviceToHost(vds, bond, (Object[]) bondProperties.get("slaves"));
                }
                bond.setBondOptions(parseBondOptions((Map<String, Object>) bondProperties.get("opts")));
                bond.setAdPartnerMac((String) bondProperties.get("ad_partner_mac"));
                bond.setActiveSlave((String) bondProperties.get("active_slave"));
            }
        }
    }
}
Also used : Bond(org.ovirt.engine.core.common.businessentities.network.Bond) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Bond

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

the class HostInterfaceListModel method updateItems.

private void updateItems(Iterable<VdsNetworkInterface> source) {
    ArrayList<HostInterfaceLineModel> items = new ArrayList<>();
    setOriginalItems((ArrayList<VdsNetworkInterface>) source);
    List<Bond> nonEmptyBonds = new ArrayList<>();
    List<Nic> independentNics = new ArrayList<>();
    Map<String, List<Nic>> bondToNics = new HashMap<>();
    Map<String, List<Vlan>> nicToVlans = new HashMap<>();
    sortNics();
    classifyNics(nonEmptyBonds, independentNics, bondToNics, nicToVlans);
    // create all bond models
    for (Bond bond : nonEmptyBonds) {
        HostInterfaceLineModel model = lineModelFromBond(bond);
        items.add(model);
        // add contained interface models - should exist, but check just in case
        if (bondToNics.containsKey(bond.getName())) {
            for (Nic nic : bondToNics.get(bond.getName())) {
                model.getInterfaces().add(hostInterfaceFromNic(nic));
            }
        }
        // add any corresponding VLAN bridge models
        model.getVLans().addAll(gatherVlans(bond, nicToVlans));
    }
    // create all independent NIC models
    for (Nic nic : independentNics) {
        HostInterfaceLineModel model = lineModelFromInterface(nic);
        model.getInterfaces().add(hostInterfaceFromNic(nic));
        items.add(model);
        // add any corresponding VLAN bridge models
        model.getVLans().addAll(gatherVlans(nic, nicToVlans));
    }
    setItems(items);
    updateActionAvailability();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Nic(org.ovirt.engine.core.common.businessentities.network.Nic) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ArrayList(java.util.ArrayList) List(java.util.List) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Example 3 with Bond

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

the class HostInterfaceListModel method classifyNics.

private void classifyNics(List<Bond> nonEmptyBonds, List<Nic> independentNics, Map<String, List<Nic>> bondToNics, Map<String, List<Vlan>> nicToVlans) {
    for (VdsNetworkInterface nic : getOriginalItems()) {
        if (nic instanceof Bond) {
            nonEmptyBonds.add((Bond) nic);
        } else if (nic instanceof Nic) {
            if (nic.getBondName() == null) {
                independentNics.add((Nic) nic);
            } else {
                if (bondToNics.containsKey(nic.getBondName())) {
                    bondToNics.get(nic.getBondName()).add((Nic) nic);
                } else {
                    List<Nic> nicList = new ArrayList<>();
                    nicList.add((Nic) nic);
                    bondToNics.put(nic.getBondName(), nicList);
                }
            }
        } else if (nic instanceof Vlan) {
            String nameWithoutVlan = nic.getBaseInterface();
            if (nicToVlans.containsKey(nameWithoutVlan)) {
                nicToVlans.get(nameWithoutVlan).add((Vlan) nic);
            } else {
                List<Vlan> vlanList = new ArrayList<>();
                vlanList.add((Vlan) nic);
                nicToVlans.put(nameWithoutVlan, vlanList);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Nic(org.ovirt.engine.core.common.businessentities.network.Nic) ArrayList(java.util.ArrayList) List(java.util.List) Vlan(org.ovirt.engine.core.common.businessentities.network.Vlan) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Example 4 with Bond

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

the class ExecuteNetworkCommandInNetworkOperationTest method joinBondsTest.

/*
     * At the beginning there were two bonds (one with NetworkAttachment), which, after being introduced to each other,
     * formed a firm bond adopting NetworkAttachment as their own.
     */
private void joinBondsTest(boolean resusingName) {
    addBondToParamsAndModel(existingBond, bondNetworkInterfaceModelA, Collections.emptyList());
    NetworkAttachment networkAttachment = createAttachmentOnNetworkModelAndUpdateParams(bondNetworkInterfaceModelA, logicalNetworkModelOfNetworkA);
    // $NON-NLS-1$
    Bond bondB = createBond(Guid.newGuid(), "bondB", Arrays.asList(nicC, nicD)).toBond();
    addBondToParamsAndModel(bondB, bondNetworkInterfaceModelB, Collections.singletonList(logicalNetworkModelOfNetworkA));
    initOrginalBondNameToIdMap(bondNetworkInterfaceModelA.getCreateOrUpdateBond(), bondNetworkInterfaceModelB.getCreateOrUpdateBond());
    when(bondNetworkInterfaceModelA.getItems()).thenReturn(Collections.singletonList(logicalNetworkModelOfNetworkA));
    when(bondNetworkInterfaceModelA.getSlaves()).thenReturn(Arrays.asList(networkInterfaceModelOfNicA, networkInterfaceModelOfNicB));
    when(bondNetworkInterfaceModelB.getItems()).thenReturn(Collections.emptyList());
    when(bondNetworkInterfaceModelB.getSlaves()).thenReturn(Arrays.asList(networkInterfaceModelOfNicC, networkInterfaceModelOfNicD));
    if (resusingName) {
        newlyCreatedBond.setName(existingBondName);
    }
    NetworkOperation.JOIN_BONDS.getTarget().executeNetworkCommand(bondNetworkInterfaceModelA, bondNetworkInterfaceModelB, dataFromHostSetupNetworksModel, newlyCreatedBond);
    // NetworkOperation.JOIN_BONDS only detaches the attachments, the attachments are being re-attached only in
    // HostSetupNetworksModel (after clicking ok in the new bond dialog)
    assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(0));
    assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(1));
    Guid removeNetworkAttachmentId = dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().iterator().next();
    // $NON-NLS-1$
    assertThat("id mismatch", removeNetworkAttachmentId, is(networkAttachment.getId()));
    assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(1));
    CreateOrUpdateBond newOrModifiedBond = dataFromHostSetupNetworksModel.getBonds().iterator().next();
    assertBond(newOrModifiedBond, resusingName ? existingBondId : null, Arrays.asList(nicA, nicB, nicC, nicD));
    assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(resusingName ? 1 : 2));
    // $NON-NLS-1$
    assertThat("id mismatch", dataFromHostSetupNetworksModel.getRemovedBonds().contains(existingBondId), is(!resusingName));
    // $NON-NLS-1$
    assertThat("id mismatch", dataFromHostSetupNetworksModel.getRemovedBonds().contains(bondB.getId()), is(true));
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Guid(org.ovirt.engine.core.compat.Guid) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 5 with Bond

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

the class HostNetworkInterfaceBondedListViewItem method createBondInterfaceStatusPanel.

protected IsWidget createBondInterfaceStatusPanel(boolean isUp, VDS host) {
    Bond bond = (Bond) getEntity().getInterface();
    if (!isAdPartnerMacValid(bond, host)) {
        WidgetTooltip tooltip = new WidgetTooltip(new IconStatusPanel(PatternflyConstants.PFICON_WARNING_TRIANGLE_O, PatternflyConstants.PFICON));
        tooltip.setHtml(templates.italicWordWrapMaxWidth(constants.bondInMode4HasNoPartnerMac()));
        return tooltip;
    } else {
        return super.createInterfaceStatusPanel(isUp);
    }
}
Also used : IconStatusPanel(org.ovirt.engine.ui.common.widget.uicommon.vm.IconStatusPanel) Bond(org.ovirt.engine.core.common.businessentities.network.Bond) WidgetTooltip(org.ovirt.engine.ui.common.widget.tooltip.WidgetTooltip)

Aggregations

Bond (org.ovirt.engine.core.common.businessentities.network.Bond)34 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)24 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)19 Test (org.junit.Test)11 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)8 ArrayList (java.util.ArrayList)7 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)5 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)5 NicLabel (org.ovirt.engine.core.common.businessentities.network.NicLabel)5 List (java.util.List)4 HostNic (org.ovirt.engine.api.model.HostNic)4 HostSetupNetworksParameters (org.ovirt.engine.core.common.action.HostSetupNetworksParameters)4 Network (org.ovirt.engine.core.common.businessentities.network.Network)4 HashMap (java.util.HashMap)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Nic (org.ovirt.engine.core.common.businessentities.network.Nic)3 Guid (org.ovirt.engine.core.compat.Guid)3 Bonding (org.ovirt.engine.api.model.Bonding)2 Vlan (org.ovirt.engine.core.common.businessentities.network.Vlan)2 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)2