public static Collection<VdsNetworkInterface> getBondsWithSlavesInformation(Collection<? extends VdsNetworkInterface> nics) { List<VdsNetworkInterface> bonds = new ArrayList<>(); fillBondSlaves(nics); for (VdsNetworkInterface nic : nics) { if (nic instanceof Bond) { bonds.add(nic); } } return bonds; }
/** * Check if the proposed interface represents a VLAN of the given interface name or is equal to it.<br> * If either of the parameters is null, <code>false</code> is returned. * * @param proposedIface * The interface to check if it's a VLAN of the other interface or it is the other interface. * @param iface * The interface to check for. * * @return <code>true</code> if the proposed interface is a VLAN on the interface or if it is the other interface, * <code>false</code> otherwise. */ public static boolean interfaceBasedOn(VdsNetworkInterface proposedIface, String iface) { return iface != null && proposedIface != null && iface.equals(NetworkCommonUtils.stripVlan(proposedIface)); }
public static IpConfiguration createDefaultIpConfiguration() { IpConfiguration ipConfiguration = new IpConfiguration(); IPv4Address iPv4Address = createDefaultIpv4Address(); ipConfiguration.getIPv4Addresses().add(iPv4Address); IpV6Address ipv6Address = createDefaultIpv6Address(); ipConfiguration.getIpV6Addresses().add(ipv6Address); return ipConfiguration; }
public static Map<String, List<String>> getBondNameToBondSlaveNamesMap(Collection<? extends VdsNetworkInterface> nics) { Map<String, List<String>> result = new HashMap<>(); Map<String, List<VdsNetworkInterface>> map = getBondNameToBondSlavesMap(nics); for (Map.Entry<String, List<VdsNetworkInterface>> entry : map.entrySet()) { result.put(entry.getKey(), getNicNames(entry.getValue())); } return result; }
public static boolean interfaceHasVlan(VdsNetworkInterface iface, List<VdsNetworkInterface> allIfaces) { return allIfaces.stream().anyMatch(i -> NetworkCommonUtils.isVlan(i) && interfaceBasedOn(i, iface.getName())); }
public static IpConfiguration createIpConfigurationFromVdsNetworkInterface(VdsNetworkInterface nic) { if (nic == null) { return NetworkCommonUtils.createDefaultIpConfiguration(); } final List<IPv4Address> iPv4Addresses = Stream.of(nic).map(new NicToIpv4AddressFunction()).collect(toList()); final List<IpV6Address> ipV6Addresses = Stream.of(nic).map(new NicToIpv6AddressFunction()).collect(toList()); IpConfiguration ipConfiguration = new IpConfiguration(); ipConfiguration.setIPv4Addresses(iPv4Addresses); ipConfiguration.setIpV6Addresses(ipV6Addresses); return ipConfiguration; }
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>()); } } }
/** * Returns the underlying interface name of a given nic * * @return Base interface name if the nic is a vlan device. * Otherwise, the name of the nic */ public static String stripVlan(VdsNetworkInterface nic) { return isVlan(nic) ? nic.getBaseInterface() : nic.getName(); }
private NetworkAttachment createNetworkAttachment(Guid id, VdsNetworkInterface baseNic, Network network) { NetworkAttachment networkAttachment = new NetworkAttachment(baseNic, network, NetworkCommonUtils.createDefaultIpConfiguration()); networkAttachment.setId(id); return networkAttachment; }
private boolean isPhysicalNic(VdsNetworkInterface nic, Set<String> bondNames, Set<String> slaveNames) { boolean isBond = bondNames.contains(nic.getName()); boolean isRemovedBond = hostSetupNetworksParametersData.getRemovedBonds().contains(nic.getId()); boolean isSlave = slaveNames.contains(nic.getName()); boolean isVlanDevice = NetworkCommonUtils.isVlan(nic); return !(isBond || isRemovedBond || isSlave || isVlanDevice); }
private NetworkAttachment createAttachmentWhenAttachingTo(VdsNetworkInterface targetNic) { NetworkAttachment networkAttachment = new NetworkAttachment(targetNic, networkModel.getNetwork(), NetworkCommonUtils.createDefaultIpConfiguration()); NetworkParameters netParams = networkModel.getSetupModel().getNetworkToLastDetachParams().get(networkModel.getName()); if (netParams != null) { applyOnAttachmentParamsFrom(netParams, networkAttachment); } else { VdsNetworkInterface nicToTakeParamsFrom = null; if (networkModel.hasVlan()) { nicToTakeParamsFrom = getPotentialVlanDevice(targetNic); } else { nicToTakeParamsFrom = targetNic; } boolean newlyCreatedBond = nicToTakeParamsFrom != null && nicToTakeParamsFrom.getId() == null; if (nicToTakeParamsFrom != null && !newlyCreatedBond) { InterfacePropertiesAccessor.FromNic interfacePropertiesAccessor = new InterfacePropertiesAccessor.FromNic(nicToTakeParamsFrom, null); applyOnAttachmentParamsFrom(interfacePropertiesAccessor, networkAttachment); } fixBootProtocolOfMgmtNetworkIfNeeded(networkAttachment); } return networkAttachment; }
private void initCreateOrUpdateBondParameters() { NetworkCommonUtils.fillBondSlaves(allExistingNics); for (VdsNetworkInterface nic : allExistingNics) { if (nic.isBond()) { getHostSetupNetworksParametersData().getBonds() .add(CreateOrUpdateBond.fromBond((Bond) nic)); } } hostSetupNetworksParametersData.setOriginalBondsByName(Entities.entitiesByName(hostSetupNetworksParametersData.getBonds())); }
public void createModelsForUnamangedNetworks(Map<String, Set<LogicalNetworkModel>> nicToNetworks) { for (VdsNetworkInterface nic : allExistingNics) { if (shouldCreateUnmanagedNetworkModel(nic)) { LogicalNetworkModel networkModel = createUnmanagedNetworkModel(nic.getNetworkName(), nic); networkModelByName.put(networkModel.getName(), networkModel); String baseNicName = NetworkCommonUtils.stripVlan(nic); if (!nicToNetworks.containsKey(baseNicName)) { nicToNetworks.put(baseNicName, new HashSet<LogicalNetworkModel>()); } nicToNetworks.get(baseNicName).add(networkModel); } } }