Search in sources :

Example 11 with CreateOrUpdateBond

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

the class HostSetupNetworksCommand method isBonding.

private boolean isBonding(NetworkAttachment attachment, BusinessEntityMap<VdsNetworkInterface> nics) {
    for (CreateOrUpdateBond bond : getParameters().getCreateOrUpdateBonds()) {
        if (bond.getName() != null && bond.getName().equals(attachment.getNicName())) {
            return true;
        }
    }
    VdsNetworkInterface attachedNic = nics.get(attachment.getNicId(), attachment.getNicName());
    Validate.notNull(attachedNic, "NicId/NicName must refer to a resolvable interface");
    return Boolean.TRUE.equals(attachedNic.getBonded());
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 12 with CreateOrUpdateBond

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

the class HostSetupNetworksValidator method validNewOrModifiedBonds.

ValidationResult validNewOrModifiedBonds() {
    for (CreateOrUpdateBond modifiedOrNewBond : params.getCreateOrUpdateBonds()) {
        String bondName = modifiedOrNewBond.getName();
        Guid bondId = modifiedOrNewBond.getId();
        /*
             * bondId is provided, but bondName not. This means that user attempted update, but bond of such ID does not
             * exit, thus completors did not complete name.
             */
        if (bondId != null && bondName == null) {
            return new ValidationResult(EngineMessage.HOST_NETWORK_INTERFACE_HAVING_ID_DOES_NOT_EXIST, ReplacementUtils.createSetVariableString(VAR_NIC_ID, bondId));
        }
        /*
             * user did not provide neither bondId nor bondName. That means he probably attempted new bond creation
             * but forgot to provide bondName.
             */
        if (bondId == null && bondName == null) {
            return new ValidationResult(EngineMessage.BOND_DOES_NOT_HAVE_NEITHER_ID_NOR_NAME_SPECIFIED);
        }
        /*
             * if (bondId == null && bondName != null) …
             * User provided only bondName, and completors failed to find existing bonds id for that name.
             * We cannot tell, what user wanted to do(create/update). We have to assume, it's new record creation, which
             * is valid scenario.
             */
        ValidationResult validateCoherentNicIdentification = validateCoherentNicIdentification(modifiedOrNewBond);
        if (!validateCoherentNicIdentification.isValid()) {
            return validateCoherentNicIdentification;
        }
        boolean validBondName = bondName.matches(BusinessEntitiesDefinitions.BOND_NAME_PATTERN);
        if (!validBondName) {
            EngineMessage engineMessage = EngineMessage.NETWORK_BOND_NAME_BAD_FORMAT;
            return new ValidationResult(engineMessage, ReplacementUtils.getVariableAssignmentString(engineMessage, bondName));
        }
        // either it's newly create bond, thus non existing, or given name must reference existing bond.
        ValidationResult interfaceIsBondOrNull = createHostInterfaceValidator(existingInterfacesMap.get(bondName)).interfaceIsBondOrNull();
        if (!interfaceIsBondOrNull.isValid()) {
            return interfaceIsBondOrNull;
        }
        // count of bond slaves must be at least two.
        if (modifiedOrNewBond.getSlaves().size() < 2) {
            return new ValidationResult(EngineMessage.NETWORK_BONDS_INVALID_SLAVE_COUNT, ReplacementUtils.getVariableAssignmentString(EngineMessage.NETWORK_BONDS_INVALID_SLAVE_COUNT, bondName));
        }
        ValidationResult validateModifiedBondSlaves = validateModifiedBondSlaves(modifiedOrNewBond);
        if (!validateModifiedBondSlaves.isValid()) {
            return validateModifiedBondSlaves;
        }
    }
    return ValidationResult.VALID;
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Guid(org.ovirt.engine.core.compat.Guid) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage)

Example 13 with CreateOrUpdateBond

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

the class HostSetupNetworksCommand method removeUnchangedBonds.

private void removeUnchangedBonds(List<VdsNetworkInterface> existingNics) {
    Map<Guid, VdsNetworkInterface> nicsById = Entities.businessEntitiesById(existingNics);
    List<CreateOrUpdateBond> createOrUpdateBonds = getParameters().getCreateOrUpdateBonds();
    for (Iterator<CreateOrUpdateBond> iterator = createOrUpdateBonds.iterator(); iterator.hasNext(); ) {
        CreateOrUpdateBond bondFromRequest = iterator.next();
        Guid idOfBondFromRequest = bondFromRequest.getId();
        boolean bondFromRequestIsNewBond = idOfBondFromRequest == null;
        if (!bondFromRequestIsNewBond) {
            if (bondFromRequest.equalToBond((Bond) nicsById.get(idOfBondFromRequest))) {
                iterator.remove();
            }
        }
    }
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid)

Example 14 with CreateOrUpdateBond

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

the class NicLabelValidatorTest method labelBeingAttachedToValidBondNewBondValid.

@Test
public void labelBeingAttachedToValidBondNewBondValid() {
    CreateOrUpdateBond createOrUpdateBond = new CreateOrUpdateBond();
    createOrUpdateBond.setName("bond");
    createOrUpdateBond.setSlaves(new HashSet<>(Arrays.asList("slave1", "slave2")));
    HostSetupNetworksParameters params = createHostSetupNetworksParams();
    params.getCreateOrUpdateBonds().add(createOrUpdateBond);
    NicLabel nicLabel = new NicLabel(createOrUpdateBond.getId(), createOrUpdateBond.getName(), "lbl1");
    assertThat(createNicLabelValidator(params, new ArrayList<>()).labelBeingAttachedToValidBond(nicLabel), isValid());
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) NicLabel(org.ovirt.engine.core.common.businessentities.network.NicLabel) HostSetupNetworksParameters(org.ovirt.engine.core.common.action.HostSetupNetworksParameters) Test(org.junit.Test)

Example 15 with CreateOrUpdateBond

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

the class NicLabelValidatorTest method labelBeingAttachedToNonVlanNonSlaveInterfaceAttachToRemovedSlave.

@Test
public void labelBeingAttachedToNonVlanNonSlaveInterfaceAttachToRemovedSlave() {
    HostSetupNetworksParameters params = createHostSetupNetworksParams();
    VdsNetworkInterface slave = createNic();
    Bond bondWithSlave = new Bond("bond");
    bondWithSlave.setSlaves(Collections.singletonList(slave.getName()));
    CreateOrUpdateBond updatedBond = new CreateOrUpdateBond();
    updatedBond.setName(bondWithSlave.getName());
    updatedBond.setSlaves(new HashSet<>());
    params.setCreateOrUpdateBonds(Collections.singletonList(updatedBond));
    NicLabel nicLabel = new NicLabel();
    nicLabel.setNicName(slave.getName());
    NicLabelValidator nicLabelValidator = createNicLabelValidator(params, Arrays.asList(bondWithSlave, slave));
    assertThat(nicLabelValidator.labelBeingAttachedToNonVlanNonSlaveInterface(nicLabel), isValid());
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NicLabel(org.ovirt.engine.core.common.businessentities.network.NicLabel) HostSetupNetworksParameters(org.ovirt.engine.core.common.action.HostSetupNetworksParameters) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond) Test(org.junit.Test)

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