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);
}
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;
}
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>());
}
}
}
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;
}
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())));
}
Aggregations