/** * Checks whether an interface is part of a bond. * * @return whether the interface is part of a bond. */ public boolean isPartOfBond() { return getBondName() != null; }
public static Map<String, List<VdsNetworkInterface>> getBondNameToBondSlavesMap(Collection<? extends VdsNetworkInterface> nics) { Map<String, List<VdsNetworkInterface>> bondToSlaves = new HashMap<>(); for (VdsNetworkInterface nic : nics) { if (nic.isPartOfBond()) { String bondName = nic.getBondName(); if (!bondToSlaves.containsKey(bondName)) { bondToSlaves.put(bondName, new ArrayList<VdsNetworkInterface>()); } bondToSlaves.get(bondName).add(nic); } } return bondToSlaves; }
public boolean isPartOfBond(String bondName) { return isPartOfBond() && getBondName().equals(bondName); }
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);
/** * Checks if a given nic is labeled properly: either an interface or a bond (not a slave nor vlan). * * @param iface * the nic to check * @return <code>true</code> iff the nic is properly labeled or if no labels provided for it, else * <code>false</code> */ private boolean validateLabel(VdsNetworkInterface iface) { return iface.getLabels() == null || iface.getLabels().isEmpty() ? true : isEmpty(iface.getBondName()) && iface.getVlanId() == null; } }
protected HostNic map(VdsNetworkInterface iface, HostNic template, List<VdsNetworkInterface> ifaces) { HostNic nic = super.map(iface, template); if (iface.getBonded() != null && iface.getBonded()) { nic = addSlaveLinks(nic, getCollection(ifaces)); nic = addActiveSlaveLink(nic, iface, getCollection(ifaces)); } else if (iface.getBondName() != null) { nic = addMasterLink(nic, iface.getBondName(), getCollection(ifaces)); } return nic; }
/** * validate the following: * <ul> * <li>an interface must have an address when the boot protocol is static * </ul> */ @Override public boolean isValid(VdsNetworkInterface iface, ConstraintValidatorContext context) { Ipv4BootProtocol bootProtocol = iface.getIpv4BootProtocol(); String address = iface.getIpv4Address(); if (bootProtocol != null && bootProtocol == STATIC_IP) { if (isNullOrEmpty(address)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("NETWORK_ADDR_MANDATORY_IN_STATIC_IP") .addNode("address").addConstraintViolation(); return false; } } if (!isEmpty(iface.getBondName()) && !validateSlave(iface)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("SLAVE_INTERFACE_IS_MISCONFIGURED").addConstraintViolation(); return false; } if (!validateLabel(iface)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("IMPROPER_INTERFACE_IS_LABELED").addConstraintViolation(); } return true; }
.addValue("addr", nic.getIpv4Address()) .addValue("ipv6_address", nic.getIpv6Address()) .addValue("bond_name", nic.getBondName()) .addValue("bond_type", nic.getBondType()) .addValue("gateway", nic.getIpv4Gateway())