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].get('opts') options = Bond._dict2list(options) 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].get('opts') options = Bond._dict2list(options) 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 self.configurator.net_info.ifaceUsers(self.name) and self.mtu <= mtus.getMtu(self.name)): return self.configurator.configureNic(self, **opts)
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 _get_iface_info(iface, addresses, routes): ipv4gateway = get_gateway(routes, iface, family=4) ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo( iface, addresses, ipv4gateway) is_dhcpv4, is_dhcpv6 = dhcp_status(iface, addresses) return {'mtu': getMtu(iface), 'addr': ipv4addr, 'ipv4addrs': ipv4addrs, 'gateway': ipv4gateway, 'netmask': ipv4netmask, 'dhcpv4': is_dhcpv4, 'ipv6addrs': ipv6addrs, 'ipv6gateway': get_gateway(routes, iface, family=6), 'ipv6autoconf': is_ipv6_local_auto(iface), 'dhcpv6': is_dhcpv6}
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 _get_iface_info(iface, addresses, routes): ipv4gateway = get_gateway(routes, iface, family=4) ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo( iface, addresses, ipv4gateway) is_dhcpv4 = dhclient.is_active(iface, family=4) is_dhcpv6 = dhclient.is_active(iface, family=6) return {'mtu': getMtu(iface), 'addr': ipv4addr, 'ipv4addrs': ipv4addrs, 'gateway': ipv4gateway, 'netmask': ipv4netmask, 'ipv4defaultroute': is_default_route(ipv4gateway), 'dhcpv4': is_dhcpv4, 'ipv6addrs': ipv6addrs, 'ipv6gateway': get_gateway(routes, iface, family=6), 'ipv6autoconf': is_ipv6_local_auto(iface), 'dhcpv6': is_dhcpv6}
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_iface_info(iface, addresses, routes): ipv4gateway = get_gateway(routes, iface, family=4) ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo( iface, addresses, ipv4gateway) is_dhcpv4, is_dhcpv6 = dhcp_status(iface, addresses) return { 'mtu': getMtu(iface), 'addr': ipv4addr, 'ipv4addrs': ipv4addrs, 'gateway': ipv4gateway, 'netmask': ipv4netmask, 'dhcpv4': is_dhcpv4, 'ipv6addrs': ipv6addrs, 'ipv6gateway': get_gateway(routes, iface, family=6), 'ipv6autoconf': is_ipv6_local_auto(iface), 'dhcpv6': is_dhcpv6 }
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_iface_info(iface, addresses, routes): ipv4gateway = get_gateway(routes, iface, family=4) ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo( iface, addresses, ipv4gateway) is_dhcpv4 = dhclient.is_active(iface, family=4) is_dhcpv6 = dhclient.is_active(iface, family=6) return { 'mtu': getMtu(iface), 'addr': ipv4addr, 'ipv4addrs': ipv4addrs, 'gateway': ipv4gateway, 'netmask': ipv4netmask, 'ipv4defaultroute': is_default_route(ipv4gateway), 'dhcpv4': is_dhcpv4, 'ipv6addrs': ipv6addrs, 'ipv6gateway': get_gateway(routes, iface, family=6), 'ipv6autoconf': is_ipv6_local_auto(iface), 'dhcpv6': is_dhcpv6 }
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}
def _get_net_info(interface, routes): mtu = mtus.getMtu(interface) ipaddrs = addresses.getIpAddrs() addr, netmask, ipv4addrs, ipv6addrs = addresses.getIpInfo(interface, ipaddrs) dhcpv4 = dhclient.is_active(interface, family=4) dhcpv6 = dhclient.is_active(interface, 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, 'ipv6autoconf': addresses.is_ipv6_local_auto(interface), 'ipv6gateway': ipv6gateway, 'dhcpv6': dhcpv6, 'ipv4defaultroute': netinfo_routes.is_default_route(gateway)}
def _get_net_info(interface, routes): mtu = mtus.getMtu(interface) ipaddrs = addresses.getIpAddrs() addr, netmask, ipv4addrs, ipv6addrs = addresses.getIpInfo( interface, ipaddrs) dhcpv4 = dhclient.is_active(interface, family=4) dhcpv6 = dhclient.is_active(interface, 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, 'ipv6autoconf': addresses.is_ipv6_local_auto(interface), 'ipv6gateway': ipv6gateway, 'dhcpv6': dhcpv6 }
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)