Search in sources :

Example 6 with Bond

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

the class BackendHostResource method mapBonds.

public CreateOrUpdateBond mapBonds(BusinessEntityMap<Bond> bonds, HostNic model) {
    Mapper<HostNic, Bond> hostNicMapper = getMapper(HostNic.class, Bond.class);
    Bond bond;
    if (model.isSetId()) {
        Guid nicId = asGuid(model.getId());
        bond = hostNicMapper.map(model, bonds.get(nicId));
    } else {
        Bond template = model.isSetName() ? bonds.get(model.getName()) : null;
        bond = hostNicMapper.map(model, template);
    }
    return CreateOrUpdateBond.fromBond(bond);
}
Also used : HostNic(org.ovirt.engine.api.model.HostNic) Guid(org.ovirt.engine.core.compat.Guid) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Example 7 with Bond

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

the class HostNicMapper method map.

@Mapping(from = HostNic.class, to = VdsNetworkInterface.class)
public static VdsNetworkInterface map(HostNic model, VdsNetworkInterface template) {
    VdsNetworkInterface entity;
    if (template != null) {
        entity = template;
    } else if (model.isSetBonding()) {
        entity = new Bond();
    } else if (model.isSetVlan()) {
        entity = new Vlan();
    } else {
        entity = new Nic();
    }
    if (model.isSetId()) {
        entity.setId(GuidUtils.asGuid(model.getId()));
    }
    if (model.isSetNetwork() && model.getNetwork().isSetName()) {
        entity.setNetworkName(model.getNetwork().getName());
    }
    if (model.isSetName()) {
        entity.setName(model.getName());
    }
    if (model.isSetBaseInterface()) {
        entity.setBaseInterface(model.getBaseInterface());
    }
    mapIpv4FromModel(model, entity);
    mapIpv6FromModel(model, entity);
    if (model.isSetMac() && model.getMac().isSetAddress()) {
        entity.setMacAddress(model.getMac().getAddress());
    }
    if (model.isSetBonding()) {
        entity.setBonded(true);
        if (model.getBonding().isSetOptions()) {
            List<Option> bondingOptions = model.getBonding().getOptions().getOptions();
            String optionsString = bondingOptions.stream().filter(Option::isSetName).map(x -> x.getName() + "=" + x.getValue()).collect(joining(" "));
            entity.setBondOptions(optionsString);
        }
    }
    if (model.isSetQos()) {
        entity.setQos((HostNetworkQos) QosMapper.map(model.getQos(), null));
    }
    return entity;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) InterfaceStatus(org.ovirt.engine.core.common.businessentities.network.InterfaceStatus) HostNic(org.ovirt.engine.api.model.HostNic) GuidUtils(org.ovirt.engine.api.restapi.utils.GuidUtils) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Ipv6BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv6BootProtocol) Option(org.ovirt.engine.api.model.Option) Network(org.ovirt.engine.api.model.Network) Mac(org.ovirt.engine.api.model.Mac) BootProtocol(org.ovirt.engine.api.model.BootProtocol) Bonding(org.ovirt.engine.api.model.Bonding) IpVersion(org.ovirt.engine.api.model.IpVersion) HostNetworkQos(org.ovirt.engine.core.common.businessentities.network.HostNetworkQos) Vlan(org.ovirt.engine.core.common.businessentities.network.Vlan) Nic(org.ovirt.engine.core.common.businessentities.network.Nic) Ipv4BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol) Collectors.joining(java.util.stream.Collectors.joining) NicStatus(org.ovirt.engine.api.model.NicStatus) UpdateHostNicVfsConfigParameters(org.ovirt.engine.core.common.action.UpdateHostNicVfsConfigParameters) List(java.util.List) HostNicVirtualFunctionsConfiguration(org.ovirt.engine.api.model.HostNicVirtualFunctionsConfiguration) Bond(org.ovirt.engine.core.common.businessentities.network.Bond) Ip(org.ovirt.engine.api.model.Ip) Options(org.ovirt.engine.api.model.Options) HostNicVfsConfig(org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) HostNic(org.ovirt.engine.api.model.HostNic) Nic(org.ovirt.engine.core.common.businessentities.network.Nic) Option(org.ovirt.engine.api.model.Option) Vlan(org.ovirt.engine.core.common.businessentities.network.Vlan) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Example 8 with Bond

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

the class NetworkCommonUtils method fillBondSlaves.

public static void fillBondSlaves(Collection<? extends VdsNetworkInterface> nics) {
    Map<String, List<String>> bondToSlaves = getBondNameToBondSlaveNamesMap(nics);
    for (VdsNetworkInterface nic : nics) {
        if (nic instanceof Bond) {
            Bond bond = (Bond) nic;
            bond.setSlaves(bondToSlaves.containsKey(bond.getName()) ? bondToSlaves.get(bond.getName()) : new ArrayList<String>());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) List(java.util.List) ArrayList(java.util.ArrayList) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Example 9 with Bond

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

the class NicLabelValidator method labelBeingAttachedToValidBond.

ValidationResult labelBeingAttachedToValidBond(NicLabel nicLabel) {
    String interfaceName = nicLabel.getNicName();
    VdsNetworkInterface nic = existingInterfacesMap.get(interfaceName);
    if (nic instanceof Bond) {
        CreateOrUpdateBond createOrUpdateBond = createOrUpdateBondBusinessEntityMap.containsKey(interfaceName) ? createOrUpdateBondBusinessEntityMap.get(interfaceName) : CreateOrUpdateBond.fromBond((Bond) nic);
        if (createOrUpdateBond.getSlaves().size() < 2) {
            return new ValidationResult(EngineMessage.IMPROPER_BOND_IS_LABELED, ReplacementUtils.createSetVariableString(HostInterfaceValidator.VAR_BOND_NAME, createOrUpdateBond.getName()));
        }
    }
    return ValidationResult.VALID;
}
Also used : CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 10 with Bond

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

the class NicLabelValidatorTest method assertLabelBeingAttachedToNonVlanNonSlaveInterfaceFailed.

private void assertLabelBeingAttachedToNonVlanNonSlaveInterfaceFailed(HostSetupNetworksParameters params, VdsNetworkInterface attachLabelToNic) {
    List<VdsNetworkInterface> nics = new ArrayList<>();
    nics.add(attachLabelToNic);
    if (attachLabelToNic.getBondName() != null) {
        Bond bond = new Bond(attachLabelToNic.getBondName());
        bond.setId(Guid.newGuid());
        nics.add(bond);
    }
    NicLabel nicLabel = new NicLabel(attachLabelToNic.getId(), attachLabelToNic.getName(), "lbl1");
    assertThat(createNicLabelValidator(params, nics).labelBeingAttachedToNonVlanNonSlaveInterface(nicLabel), failsWith(EngineMessage.LABEL_ATTACH_TO_IMPROPER_INTERFACE, ReplacementUtils.createSetVariableString("LABEL_ATTACH_TO_IMPROPER_INTERFACE_ENTITY", attachLabelToNic.getName())));
}
Also used : ArrayList(java.util.ArrayList) 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

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