def objectivize(cls, name, configurator, options, nics, mtu, _netinfo, on_removal_just_detach_from_network=False): if nics: # New bonding or edit bonding. slaves = cls._objectivizeSlaves(name, configurator, _nicSort(nics), mtu, _netinfo) if name in _netinfo.bondings: if _netinfo.ifaceUsers(name): mtu = max(mtu, mtus.getMtu(name)) if not options: options = _netinfo.bondings[name]['cfg'].get( 'BONDING_OPTS') elif name in _netinfo.bondings: # Implicit bonding. if _netinfo.ifaceUsers(name): mtu = max(mtu, mtus.getMtu(name)) slaves = [Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo) for nic in _netinfo.getNicsForBonding(name)] options = _netinfo.bondings[name]['cfg'].get('BONDING_OPTS') else: raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Missing required nics on a bonding %s ' 'that is unknown to Vdsm ' % name) detach = on_removal_just_detach_from_network # argument is too long return cls(name, configurator, slaves=slaves, options=options, mtu=mtu, on_removal_just_detach_from_network=detach)
def configure(self, **opts): # in a limited condition, we should not touch the nic config if (self.vlan and nics.operstate(self.name) == nics.OPERSTATE_UP and ifaceUsed(self.name) and self.mtu <= mtus.getMtu(self.name)): return self.configurator.configureNic(self, **opts)
def __init__(self, name, configurator, ipv4=None, ipv6=None, blockingdhcp=False, mtu=None, _netinfo=None): if _netinfo is None: _netinfo = CachingNetInfo() if name not in _netinfo.nics: raise ConfigNetworkError(ne.ERR_BAD_NIC, 'unknown nic: %s' % name) if _netinfo.ifaceUsers(name): mtu = max(mtu, mtus.getMtu(name)) super(Nic, self).__init__(name, configurator, ipv4, ipv6, blockingdhcp, mtu)
def objectivize(cls, name, configurator, options, nics, mtu, _netinfo, destroyOnMasterRemoval=None): if nics: # New bonding or edit bonding. slaves = cls._objectivizeSlaves(name, configurator, _nicSort(nics), mtu, _netinfo) if name in _netinfo.bondings: if _netinfo.ifaceUsers(name): mtu = max(mtu, mtus.getMtu(name)) if not options: options = _netinfo.bondings[name]['cfg'].get( 'BONDING_OPTS') elif name in _netinfo.bondings: # Implicit bonding. if _netinfo.ifaceUsers(name): mtu = max(mtu, mtus.getMtu(name)) slaves = [ Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo) for nic in _netinfo.getNicsForBonding(name) ] options = _netinfo.bondings[name]['cfg'].get('BONDING_OPTS') else: raise ConfigNetworkError( ne.ERR_BAD_PARAMS, 'Missing required nics on a bonding %s ' 'that is unknown to Vdsm ' % name) return cls(name, configurator, slaves=slaves, options=options, mtu=mtu, destroyOnMasterRemoval=destroyOnMasterRemoval)
def configure(self, **opts): # When the bond is up and we are not changing the configuration that # is already applied in any way, we can skip the configuring. if (self.vlan and self.name in bonding.bondings() and (not self.configurator.unifiedPersistence or self.name in self.configurator.runningConfig.bonds) and nics.operstate(self.name) == nics.OPERSTATE_UP and ifaceUsed(self.name) and self.mtu <= mtus.getMtu(self.name) and self.areOptionsApplied() and frozenset(slave.name for slave in self.slaves) == frozenset( bonding.slaves(self.name))): return self.configurator.configureBond(self, **opts)
def configure(self, **opts): # When the bond is up and we are not changing the configuration that # is already applied in any way, we can skip the configuring. if (self.vlan and self.name in bonding.bondings() and (not self.configurator.unifiedPersistence or self.name in self.configurator.runningConfig.bonds) and nics.operstate(self.name) == nics.OPERSTATE_UP and ifaceUsed(self.name) and self.mtu <= mtus.getMtu(self.name) and self.areOptionsApplied() and frozenset(slave.name for slave in self.slaves) == frozenset(bonding.slaves(self.name))): return self.configurator.configureBond(self, **opts)
def _get_net_info(attrs, interface, dhcpv4ifaces, dhcpv6ifaces, routes): mtu = mtus.getMtu(interface) addr, netmask, ipv4addrs, ipv6addrs = addresses.getIpInfo(interface) dhcpv4 = dhcp.dhcp_used(interface, dhcpv4ifaces, attrs) dhcpv6 = dhcp.dhcp_used(interface, dhcpv6ifaces, attrs, family=6) gateway = netinfo_routes.get_gateway(routes, interface) ipv6gateway = netinfo_routes.get_gateway(routes, interface, family=6) return { 'mtu': str(mtu), 'addr': addr, 'gateway': gateway, 'netmask': netmask, 'dhcpv4': dhcpv4, 'ipv4addrs': ipv4addrs, 'ipv6addrs': ipv6addrs, 'ipv6gateway': ipv6gateway, 'dhcpv6': dhcpv6, 'cfg': {'BOOTPROTO': 'dhcp' if dhcpv4 else 'none'}}
def _setNewMtu(self, iface, ifaceVlans): """ Update an interface's MTU when one of its users is removed. :param iface: interface object (bond or nic device) :type iface: NetDevice instance :param ifaceVlans: vlan devices using the interface 'iface' :type ifaceVlans: iterable :return mtu value that was applied """ ifaceMtu = mtus.getMtu(iface.name) maxMtu = mtus.getMaxMtu(ifaceVlans, None) if maxMtu and maxMtu < ifaceMtu: if isinstance(iface, Bond): self.configApplier.setBondingMtu(iface.name, maxMtu) else: self.configApplier.setIfaceMtu(iface.name, maxMtu) return maxMtu
def _get_net_info(interface, routes): mtu = mtus.getMtu(interface) ipaddrs = addresses.getIpAddrs() addr, netmask, ipv4addrs, ipv6addrs = addresses.getIpInfo(interface, ipaddrs) dhcpv4, dhcpv6 = dhcp.dhcp_status(interface, ipaddrs) gateway = netinfo_routes.get_gateway(routes, interface) ipv6gateway = netinfo_routes.get_gateway(routes, interface, family=6) return { 'mtu': str(mtu), 'addr': addr, 'gateway': gateway, 'netmask': netmask, 'dhcpv4': dhcpv4, 'ipv4addrs': ipv4addrs, 'ipv6addrs': ipv6addrs, 'ipv6autoconf': addresses.is_ipv6_local_auto(interface), 'ipv6gateway': ipv6gateway, 'dhcpv6': dhcpv6, 'cfg': {'BOOTPROTO': 'dhcp' if dhcpv4 else 'none'}}
def _get_net_info(attrs, interface, dhcpv4ifaces, dhcpv6ifaces, routes): mtu = mtus.getMtu(interface) addr, netmask, ipv4addrs, ipv6addrs = addresses.getIpInfo(interface) dhcpv4 = dhcp.dhcp_used(interface, dhcpv4ifaces, attrs) dhcpv6 = dhcp.dhcp_used(interface, dhcpv6ifaces, attrs, family=6) gateway = netinfo_routes.get_gateway(routes, interface) ipv6gateway = netinfo_routes.get_gateway(routes, interface, family=6) return { 'mtu': str(mtu), 'addr': addr, 'gateway': gateway, 'netmask': netmask, 'dhcpv4': dhcpv4, 'ipv4addrs': ipv4addrs, 'ipv6addrs': ipv6addrs, 'ipv6gateway': ipv6gateway, 'dhcpv6': dhcpv6, 'cfg': { 'BOOTPROTO': 'dhcp' if dhcpv4 else 'none' } }
def _update_mtu_for_an_existing_bridge(dev_name, configurator, mtu): if mtu != mtus.getMtu(dev_name): configurator.configApplier.setIfaceMtu(dev_name, mtu) _update_bridge_ports_mtu(dev_name, mtu)