Search in sources :

Example 1 with CreateOrUpdateBond

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

the class HostSetupNetworksModel method getBondNameToSlaves.

private Map<String, List<VdsNetworkInterface>> getBondNameToSlaves() {
    final Map<String, VdsNetworkInterface> nicMap = Entities.entitiesByName(allExistingNics);
    Map<String, List<VdsNetworkInterface>> bondToSlaves = new HashMap<>();
    for (CreateOrUpdateBond createOrUpdateBond : hostSetupNetworksParametersData.getBonds()) {
        String bondName = createOrUpdateBond.getName();
        // $NON-NLS-1$
        assert !bondToSlaves.containsKey(bondName) : "the same bond shouldn't exist twice in the parameters";
        bondToSlaves.put(bondName, new ArrayList<VdsNetworkInterface>());
        Set<String> slavesNames = createOrUpdateBond.getSlaves();
        for (String slaveName : slavesNames) {
            bondToSlaves.get(bondName).add(nicMap.get(slaveName));
        }
    }
    return bondToSlaves;
}
Also used : HashMap(java.util.HashMap) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with CreateOrUpdateBond

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

the class HostSetupNetworksModel method onOperation.

public void onOperation(NetworkOperation operation, final NetworkCommand networkCommand) {
    Model popupWindow;
    UICommand cancelCommand = new UICommand("Cancel", new // $NON-NLS-1$
    BaseCommandTarget() {

        @Override
        public void executeCommand(UICommand command) {
            sourceListModel.setConfirmWindow(null);
        }
    });
    cancelCommand.setTitle(ConstantsManager.getInstance().getConstants().cancel());
    cancelCommand.setIsCancel(true);
    if (operation.isNullOperation()) {
        return;
    } else if (operation == NetworkOperation.BOND_WITH || operation == NetworkOperation.JOIN_BONDS) {
        final SetupNetworksBondModel bondPopup;
        boolean doesBondHaveVmNetworkAttached = doesBondHaveVmNetworkAttached((NetworkInterfaceModel) networkCommand.getOp1(), (NetworkInterfaceModel) networkCommand.getOp2());
        if (operation == NetworkOperation.BOND_WITH) {
            bondPopup = new SetupNetworksAddBondModel(getFreeBonds(), nextBondName, doesBondHaveVmNetworkAttached);
        } else {
            bondPopup = new SetupNetworksJoinBondsModel(getFreeBonds(), (BondNetworkInterfaceModel) networkCommand.getOp1(), (BondNetworkInterfaceModel) networkCommand.getOp2(), doesBondHaveVmNetworkAttached);
        }
        bondPopup.getCommands().add(new UICommand("OK", new // $NON-NLS-1$
        BaseCommandTarget() {

            @Override
            public void executeCommand(UICommand command) {
                if (!bondPopup.validate()) {
                    return;
                }
                sourceListModel.setConfirmWindow(null);
                CreateOrUpdateBond bond = new CreateOrUpdateBond();
                bond.setName(bondPopup.getBond().getSelectedItem());
                setBondOptions(bond, bondPopup);
                NetworkInterfaceModel nic1 = (NetworkInterfaceModel) networkCommand.getOp1();
                NetworkInterfaceModel nic2 = (NetworkInterfaceModel) networkCommand.getOp2();
                // Store networks
                List<LogicalNetworkModel> networks = new ArrayList<>();
                networks.addAll(nic1.getItems());
                networks.addAll(nic2.getItems());
                // Store labels
                List<NetworkLabelModel> labels = new ArrayList<>();
                labels.addAll(nic1.getLabels());
                labels.addAll(nic2.getLabels());
                networkCommand.execute(bond);
                /*
                     * We are calling the <code>redraw()</code> to create the BondModel which is needed by the following
                     * operations (attaching the networks and the labels to the bond).
                     *
                     * For more details @see #redraw. After executing the <code>networkCommand</code> which creates the
                     * bond, the bondModel still not exist (only the <code>hostSetupNetworksParametersData.bonds</code>
                     * are updated). <code>redraw()</code> has to be called to create it.
                     */
                redraw();
                // Attach the previous networks
                attachNetworks(bond.getName(), networks);
                // Attach previous labels
                attachLabels(bond.getName(), labels);
                redraw();
            }
        }));
        popupWindow = bondPopup;
    } else if (networkCommand.getOp1() == getNewNetworkLabelModel()) {
        final SetupNetworksLabelModel labelPopup = new SetupNetworksLabelModel(dcLabels);
        labelPopup.getCommands().add(new UICommand("OK", new // $NON-NLS-1$
        BaseCommandTarget() {

            @Override
            public void executeCommand(UICommand uiCommand) {
                if (!labelPopup.validate()) {
                    return;
                }
                sourceListModel.setConfirmWindow(null);
                String label = labelPopup.getLabel().getEntity();
                dcLabels.add(label);
                NetworkOperation.LABEL.getCommand(new NetworkLabelModel(label, HostSetupNetworksModel.this), networkCommand.getOp2(), hostSetupNetworksParametersData).execute();
                redraw();
            }
        }));
        popupWindow = labelPopup;
    } else {
        // just execute the command
        networkCommand.execute();
        redraw();
        return;
    }
    // add cancel
    popupWindow.getCommands().add(cancelCommand);
    // set window
    sourceListModel.setConfirmWindow(popupWindow);
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) BaseCommandTarget(org.ovirt.engine.ui.uicommonweb.BaseCommandTarget) NetworkInterfaceModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkInterfaceModel) BondNetworkInterfaceModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.BondNetworkInterfaceModel) NewNetworkLabelModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkLabelModel.NewNetworkLabelModel) NetworkLabelModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkLabelModel) DataFromHostSetupNetworksModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.DataFromHostSetupNetworksModel) NetworkInterfaceModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkInterfaceModel) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) KeyValueModel(org.ovirt.engine.ui.uicommonweb.models.vms.key_value.KeyValueModel) LogicalNetworkModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.LogicalNetworkModel) NewNetworkLabelModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkLabelModel.NewNetworkLabelModel) FromNetworkAttachmentModel(org.ovirt.engine.ui.uicommonweb.models.hosts.InterfacePropertiesAccessor.FromNetworkAttachmentModel) Model(org.ovirt.engine.ui.uicommonweb.models.Model) BondNetworkInterfaceModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.BondNetworkInterfaceModel) NetworkItemModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkItemModel) NetworkLabelModel(org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkLabelModel) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with CreateOrUpdateBond

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

the class ExecuteNetworkCommandInNetworkOperationTest method testReBondingTwoNicsWithReattachingNetworkAttachmentOnNewlyCreatedBond.

/*
     * At the beginning there was bond. It was broken into two nics, but they get back together in the end.
     */
@Test
public void testReBondingTwoNicsWithReattachingNetworkAttachmentOnNewlyCreatedBond() throws Exception {
    addBondToParamsAndModel(existingBond, bondNetworkInterfaceModelA, Collections.emptyList());
    initOrginalBondNameToIdMap(CreateOrUpdateBond.fromBond(existingBond));
    NetworkOperation.BREAK_BOND.getTarget().executeNetworkCommand(bondNetworkInterfaceModelA, null, dataFromHostSetupNetworksModel);
    NetworkOperation.BOND_WITH.getTarget().executeNetworkCommand(networkInterfaceModelOfNicA, networkInterfaceModelOfNicB, dataFromHostSetupNetworksModel, createBond(null, existingBondName, Collections.emptyList()));
    // related network attachment will be updated, not removed and created new one.
    assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(0));
    assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0));
    assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(1));
    CreateOrUpdateBond newOrModifiedBond = dataFromHostSetupNetworksModel.getBonds().iterator().next();
    assertBond(newOrModifiedBond, existingBondId, Arrays.asList(nicA, nicB));
    assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(0));
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Test(org.junit.Test)

Example 4 with CreateOrUpdateBond

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

the class ExecuteNetworkCommandInNetworkOperationTest method testAddingNewNicWithNetworkAttachmentToExistingBondWithoutAnyAttachment.

/*
     * At the beginning there was bond without any network attachment. Then another nic showed up joining the family
     * bringing his own network attachment along.
     */
@Test
public void testAddingNewNicWithNetworkAttachmentToExistingBondWithoutAnyAttachment() throws Exception {
    addBondToParamsAndModel(existingBond, bondNetworkInterfaceModelA, Collections.emptyList());
    NetworkAttachment networkAttachment = createAttachmentOnNetworkModelAndUpdateParams(networkInterfaceModelOfNicC, logicalNetworkModelOfNetworkC);
    when(networkInterfaceModelOfNicC.getItems()).thenReturn(Collections.singletonList(logicalNetworkModelOfNetworkC));
    initNetworkIdToExistingAttachmentIdMap(networkAttachment);
    NetworkOperation.ADD_TO_BOND.getTarget().executeNetworkCommand(networkInterfaceModelOfNicC, bondNetworkInterfaceModelA, dataFromHostSetupNetworksModel);
    // related network attachment will be updated, not removed and created new one.
    assertThat(dataFromHostSetupNetworksModel.getNetworkAttachments().size(), is(1));
    assertNetworkAttachment(dataFromHostSetupNetworksModel.getNetworkAttachments().iterator().next(), networkAttachment.getId(), networkC.getId(), existingBondId);
    assertThat(dataFromHostSetupNetworksModel.getRemovedNetworkAttachments().size(), is(0));
    assertThat(dataFromHostSetupNetworksModel.getBonds().size(), is(1));
    CreateOrUpdateBond newOrModifiedBond = dataFromHostSetupNetworksModel.getBonds().iterator().next();
    assertBond(newOrModifiedBond, existingBondId, Arrays.asList(nicA, nicB, nicC));
    assertThat(dataFromHostSetupNetworksModel.getRemovedBonds().size(), is(0));
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) Test(org.junit.Test)

Example 5 with CreateOrUpdateBond

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

the class ExecuteNetworkCommandInNetworkOperationTest method addBondToParamsAndModel.

private void addBondToParamsAndModel(Bond bond, BondNetworkInterfaceModel bondModel, List<LogicalNetworkModel> networks) {
    CreateOrUpdateBond createOrUpdateBond = CreateOrUpdateBond.fromBond(bond);
    dataFromHostSetupNetworksModel.getBonds().add(createOrUpdateBond);
    when(bondModel.getOriginalIface()).thenReturn(bond);
    when(bondModel.getCreateOrUpdateBond()).thenReturn(createOrUpdateBond);
    when(bondModel.getItems()).thenReturn(networks);
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond)

Aggregations

CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)38 Test (org.junit.Test)18 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)14 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)10 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)8 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)8 Guid (org.ovirt.engine.core.compat.Guid)6 HostSetupNetworksParameters (org.ovirt.engine.core.common.action.HostSetupNetworksParameters)5 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)4 BondNetworkInterfaceModel (org.ovirt.engine.ui.uicommonweb.models.hosts.network.BondNetworkInterfaceModel)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Network (org.ovirt.engine.core.common.businessentities.network.Network)3 LogicalNetworkModel (org.ovirt.engine.ui.uicommonweb.models.hosts.network.LogicalNetworkModel)3 NetworkInterfaceModel (org.ovirt.engine.ui.uicommonweb.models.hosts.network.NetworkInterfaceModel)3 List (java.util.List)2 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)2 NicLabel (org.ovirt.engine.core.common.businessentities.network.NicLabel)2 BaseCommandTarget (org.ovirt.engine.ui.uicommonweb.BaseCommandTarget)2 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)2