def setIfaceConfigAndUp(self, iface): if iface.ipv4 or iface.ipv6: address.flush(iface.name) address.add(iface.name, iface.ipv4, iface.ipv6) if iface.mtu: self.setIfaceMtu(iface.name, iface.mtu) self.ifup(iface)
def _createConfFile(self, conf, name, ipv4, ipv6, mtu, nameservers, **kwargs): """ Create ifcfg-* file with proper fields per device """ cfg = 'DEVICE=%s\n' % pipes.quote(name) cfg += conf if ipv4.address: cfg += 'IPADDR=%s\n' % pipes.quote(ipv4.address) cfg += 'NETMASK=%s\n' % pipes.quote(ipv4.netmask) if ipv4.defaultRoute and ipv4.gateway: cfg += 'GATEWAY=%s\n' % pipes.quote(ipv4.gateway) # According to manual the BOOTPROTO=none should be set # for static IP cfg += 'BOOTPROTO=none\n' elif ipv4.bootproto: cfg += 'BOOTPROTO=%s\n' % pipes.quote(ipv4.bootproto) # FIXME: Move this out, it is unrelated to a conf file creation. if os.path.exists(os.path.join(NET_PATH, name)): # Ask dhclient to stop any dhclient running for the device dhclient.kill(name) address.flush(name) if mtu: cfg += 'MTU=%d\n' % mtu is_default_route = ipv4.defaultRoute and (ipv4.gateway or ipv4.bootproto == 'dhcp') cfg += 'DEFROUTE=%s\n' % _to_ifcfg_bool(is_default_route) cfg += 'NM_CONTROLLED=no\n' enable_ipv6 = ipv6.address or ipv6.ipv6autoconf or ipv6.dhcpv6 cfg += 'IPV6INIT=%s\n' % _to_ifcfg_bool(enable_ipv6) if enable_ipv6: if ipv6.address is not None: cfg += 'IPV6ADDR=%s\n' % pipes.quote(ipv6.address) if ipv6.gateway is not None: cfg += 'IPV6_DEFAULTGW=%s\n' % pipes.quote(ipv6.gateway) elif ipv6.dhcpv6: cfg += 'DHCPV6C=yes\n' cfg += 'IPV6_AUTOCONF=%s\n' % _to_ifcfg_bool(ipv6.ipv6autoconf) if nameservers: for i, nameserver in enumerate(nameservers[0:2], 1): cfg += 'DNS{}={}\n'.format(i, nameserver) ifcfg_file = NET_CONF_PREF + name hook_dict = {'ifcfg_file': ifcfg_file, 'config': cfg} hook_return = hooks.before_ifcfg_write(hook_dict) cfg = hook_return['config'] self.writeConfFile(ifcfg_file, cfg) hooks.after_ifcfg_write(hook_return)
def removeBond(self, bonding): toBeRemoved = not ifaceUsed(bonding.name) if toBeRemoved: if bonding.master is None: address.flush(bonding.name) DynamicSourceRoute.addInterfaceTracking(bonding) self._removeSourceRoute(bonding, DynamicSourceRoute) if bonding.on_removal_just_detach_from_network: self.configApplier.setIfaceMtu(bonding.name, mtus.DEFAULT_MTU) self.configApplier.ifdown(bonding) else: self._destroyBond(bonding) self.runningConfig.removeBonding(bonding.name) else: self._setNewMtu(bonding, vlans.vlan_devs_for_iface(bonding.name))
def removeNic(self, nic, remove_even_if_used=False): """ Remove a nic from the kernel. By default, do nothing if the nic is used When remove_even_if_used=True, remove the nic anyway # FIXME the caller of this method is responsible to remove # the nic from its users (such as bond) """ toBeRemoved = not ifaceUsed(nic.name) or remove_even_if_used if toBeRemoved: if nic.master is None: address.flush(nic.name) DynamicSourceRoute.addInterfaceTracking(nic) self._removeSourceRoute(nic, DynamicSourceRoute) else: self.configApplier.setIfaceMtu(nic.name, mtus.DEFAULT_MTU) self.configApplier.ifdown(nic) else: self._setNewMtu(nic, vlans.vlan_devs_for_iface(nic.name))
def _set_static_ip_config(iface, attrs): address.flush(iface) ipv4 = address.IPv4(*_ipv4_conf_params(attrs)) ipv6 = address.IPv6(*_ipv6_conf_params(attrs)) address.add(iface, ipv4, ipv6)
def _ip_flush(ifaces): # TODO: Tell NetworkManager to unmanage this iface. for iface in ifaces: dhclient.kill(iface, family=4) dhclient.kill(iface, family=6) address.flush(iface)
def _drop_nic_ip_config(iface): """Drop IP configuration of a new nic controlled by VDSM""" if os.path.exists(os.path.join('/sys/class/net', iface)): dhclient.kill(iface, family=4) dhclient.kill(iface, family=6) address.flush(iface)