def _write_network(self, settings): # TODO(harlowja) fix this... since this is the ubuntu format entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) # Make the intermediate format as the rhel format... nameservers = [] searchservers = [] dev_names = entries.keys() for (dev, info) in entries.iteritems(): net_fn = self.network_script_tpl % (dev) net_cfg = { 'DEVICE': dev, 'NETMASK': info.get('netmask'), 'IPADDR': info.get('address'), 'BOOTPROTO': info.get('bootproto'), 'GATEWAY': info.get('gateway'), 'BROADCAST': info.get('broadcast'), 'MACADDR': info.get('hwaddress'), 'ONBOOT': _make_sysconfig_bool(info.get('auto')), } rhel_util.update_sysconfig_file(net_fn, net_cfg) if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if 'dns-search' in info: searchservers.extend(info['dns-search']) if nameservers or searchservers: rhel_util.update_resolve_conf_file(self.resolve_conf_fn, nameservers, searchservers) if dev_names: net_cfg = { 'NETWORKING': _make_sysconfig_bool(True), } rhel_util.update_sysconfig_file(self.network_conf_fn, net_cfg) return dev_names
def _write_network(self, settings): entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) dev_names = entries.keys() # Format for netctl for (dev, info) in entries.items(): nameservers = [] net_fn = self.network_conf_dir + dev net_cfg = { 'Connection': 'ethernet', 'Interface': dev, 'IP': info.get('bootproto'), 'Address': "('%s/%s')" % (info.get('address'), info.get('netmask')), 'Gateway': info.get('gateway'), 'DNS': str(tuple(info.get('dns-nameservers'))).replace(',', '') } util.write_file(net_fn, convert_netctl(net_cfg)) if info.get('auto'): self._enable_interface(dev) if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if nameservers: util.write_file(self.resolve_conf_fn, convert_resolv_conf(nameservers)) return dev_names
def _write_network(self, settings): entries = net_util.translate_network(settings) nameservers = [] searchdomains = [] dev_names = entries.keys() for (device, info) in entries.items(): # Skip the loopback interface. if device.startswith('lo'): continue dev = self.getnetifname(device) LOG.info('Configuring interface %s', dev) if info.get('bootproto') == 'static': LOG.debug('Configuring dev %s with %s / %s', dev, info.get('address'), info.get('netmask')) # Configure an ipv4 address. ifconfig = (info.get('address') + ' netmask ' + info.get('netmask')) # Configure the gateway. self.updatercconf('defaultrouter', info.get('gateway')) if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if 'dns-search' in info: searchdomains.extend(info['dns-search']) else: ifconfig = 'DHCP' self.updatercconf('ifconfig_' + dev, ifconfig) # Try to read the /etc/resolv.conf or just start from scratch if that # fails. try: resolvconf = ResolvConf(util.load_file(self.resolv_conf_fn)) resolvconf.parse() except IOError: util.logexc(LOG, "Failed to parse %s, use new empty file", self.resolv_conf_fn) resolvconf = ResolvConf('') resolvconf.parse() # Add some nameservers for server in nameservers: try: resolvconf.add_nameserver(server) except ValueError: util.logexc(LOG, "Failed to add nameserver %s", server) # And add any searchdomains. for domain in searchdomains: try: resolvconf.add_search_domain(domain) except ValueError: util.logexc(LOG, "Failed to add search domain %s", domain) util.write_file(self.resolv_conf_fn, str(resolvconf), 0o644) return dev_names
def _write_network(self, settings): entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) return _render_network( entries, resolv_conf=self.resolve_conf_fn, conf_dir=self.network_conf_dir, enable_func=self._enable_interface)
def _write_network(self, settings): entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) return _render_network(entries, resolv_conf=self.resolve_conf_fn, conf_dir=self.network_conf_dir, enable_func=self._enable_interface)
def _write_network(self, settings): # TODO(harlowja) fix this... since this is the ubuntu format entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) # Match Debian/Ubunto distro functionality of clean slating # the network interface configuration. # Remove all existing ifcfg-eth* files. This cleans up files that # are left around if you capture an image from a VM with 5 NICs # and deploy it with 1 NIC. rhel_util.remove_ifcfg_files(self.network_script_dir) rhel_util.remove_resolve_conf_file(self.resolve_conf_fn) # Make the intermediate format as the rhel format... nameservers = [] searchservers = [] dev_names = entries.keys() for (dev, info) in entries.iteritems(): net_fn = self.network_script_tpl % (dev) net_cfg = { 'DEVICE': dev, 'NETMASK': info.get('netmask'), 'IPADDR': info.get('address'), 'BOOTPROTO': info.get('bootproto'), 'BROADCAST': info.get('broadcast'), 'MACADDR': info.get('hwaddress'), 'ONBOOT': _make_sysconfig_bool(info.get('auto')), } if 'mtu' in info: net_cfg['MTU'] = info.get('mtu') # Remove the existing cfg file so the network configuration # is a replacement versus an update to match debian distro # functionality. if dev != 'lo': net_cfg['USERCONTROL'] = 'no' net_cfg['NM_CONTROLLED'] = 'no' rhel_util.update_sysconfig_file(net_fn, net_cfg) if dev == 'eth0': default_gateway = info.get('gateway') or '' if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if 'dns-search' in info: searchservers.extend(info['dns-search']) if nameservers or searchservers: rhel_util.update_resolve_conf_file(self.resolve_conf_fn, nameservers, searchservers) if dev_names: net_cfg = { 'NETWORKING': _make_sysconfig_bool(True), 'GATEWAY': default_gateway, } rhel_util.update_sysconfig_file(self.network_conf_fn, net_cfg, allow_empty=True) return dev_names
def _write_network(self, settings): entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) dev_names = entries.keys() nameservers = [] for (dev, info) in entries.items(): if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if dev == 'lo': continue net_fn = self.network_conf_fn + '.' + dev dns_nameservers = info.get('dns-nameservers') if isinstance(dns_nameservers, (list, tuple)): dns_nameservers = str(tuple(dns_nameservers)).replace(',', '') # eth0, {'auto': True, 'ipv6': {}, 'bootproto': 'dhcp'} # lo, {'dns-nameservers': ['10.0.1.3'], 'ipv6': {}, 'auto': True} results = '' if info.get('bootproto') == 'dhcp': results += 'config_{name}="dhcp"'.format(name=dev) else: results += ( 'config_{name}="{ip_address} netmask {netmask}"\n' 'mac_{name}="{hwaddr}"\n' ).format(name=dev, ip_address=info.get('address'), netmask=info.get('netmask'), hwaddr=info.get('hwaddress')) results += 'routes_{name}="default via {gateway}"\n'.format( name=dev, gateway=info.get('gateway') ) if info.get('dns-nameservers'): results += 'dns_servers_{name}="{dnsservers}"\n'.format( name=dev, dnsservers=dns_nameservers) util.write_file(net_fn, results) self._create_network_symlink(dev) if info.get('auto'): cmd = ['rc-update', 'add', 'net.{name}'.format(name=dev), 'default'] try: (_out, err) = util.subp(cmd) if len(err): LOG.warning("Running %s resulted in stderr output: %s", cmd, err) except util.ProcessExecutionError: util.logexc(LOG, "Running interface command %s failed", cmd) if nameservers: util.write_file(self.resolve_conf_fn, convert_resolv_conf(nameservers)) return dev_names
def _write_network(self, settings): entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) dev_names = entries.keys() nameservers = [] for (dev, info) in entries.items(): if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if dev == 'lo': continue net_fn = self.network_conf_fn + '.' + dev dns_nameservers = info.get('dns-nameservers') if isinstance(dns_nameservers, (list, tuple)): dns_nameservers = str(tuple(dns_nameservers)).replace(',', '') # eth0, {'auto': True, 'ipv6': {}, 'bootproto': 'dhcp'} # lo, {'dns-nameservers': ['10.0.1.3'], 'ipv6': {}, 'auto': True} results = '' if info.get('bootproto') == 'dhcp': results += 'config_{name}="dhcp"'.format(name=dev) else: results += ('config_{name}="{ip_address} netmask {netmask}"\n' 'mac_{name}="{hwaddr}"\n').format( name=dev, ip_address=info.get('address'), netmask=info.get('netmask'), hwaddr=info.get('hwaddress')) results += 'routes_{name}="default via {gateway}"\n'.format( name=dev, gateway=info.get('gateway')) if info.get('dns-nameservers'): results += 'dns_servers_{name}="{dnsservers}"\n'.format( name=dev, dnsservers=dns_nameservers) util.write_file(net_fn, results) self._create_network_symlink(dev) if info.get('auto'): cmd = [ 'rc-update', 'add', 'net.{name}'.format(name=dev), 'default' ] try: (_out, err) = util.subp(cmd) if len(err): LOG.warning("Running %s resulted in stderr output: %s", cmd, err) except util.ProcessExecutionError: util.logexc(LOG, "Running interface command %s failed", cmd) if nameservers: util.write_file(self.resolve_conf_fn, convert_resolv_conf(nameservers)) return dev_names
def _write_network(self, settings): # Convert debian settings to ifcfg format entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) # Make the intermediate format as the suse format... nameservers = [] searchservers = [] dev_names = entries.keys() for (dev, info) in entries.items(): net_fn = self.network_script_tpl % (dev) route_fn = self.route_conf_tpl % (dev) mode = None if info.get('auto', None): mode = 'auto' else: mode = 'manual' bootproto = info.get('bootproto', None) gateway = info.get('gateway', None) net_cfg = { 'BOOTPROTO': bootproto, 'BROADCAST': info.get('broadcast'), 'GATEWAY': gateway, 'IPADDR': info.get('address'), 'LLADDR': info.get('hwaddress'), 'NETMASK': info.get('netmask'), 'STARTMODE': mode, 'USERCONTROL': 'no' } if dev != 'lo': net_cfg['ETHTOOL_OPTIONS'] = '' else: net_cfg['FIREWALL'] = 'no' rhutil.update_sysconfig_file(net_fn, net_cfg, True) if gateway and bootproto == 'static': default_route = 'default %s' % gateway util.write_file(route_fn, default_route, 0o644) if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if 'dns-search' in info: searchservers.extend(info['dns-search']) if nameservers or searchservers: rhutil.update_resolve_conf_file(self.resolve_conf_fn, nameservers, searchservers) return dev_names
def _write_network(self, settings): # Convert debian settings to ifcfg format entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) # Make the intermediate format as the suse format... nameservers = [] searchservers = [] dev_names = entries.keys() for (dev, info) in entries.iteritems(): net_fn = self.network_script_tpl % (dev) mode = info.get('auto') if mode and mode.lower() == 'true': mode = 'auto' else: mode = 'manual' net_cfg = { 'BOOTPROTO': info.get('bootproto'), 'BROADCAST': info.get('broadcast'), 'GATEWAY': info.get('gateway'), 'IPADDR': info.get('address'), 'LLADDR': info.get('hwaddress'), 'NETMASK': info.get('netmask'), 'STARTMODE': mode, 'USERCONTROL': 'no' } if dev != 'lo': net_cfg['ETHERDEVICE'] = dev net_cfg['ETHTOOL_OPTIONS'] = '' else: net_cfg['FIREWALL'] = 'no' rhel_util.update_sysconfig_file(net_fn, net_cfg, True) if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if 'dns-search' in info: searchservers.extend(info['dns-search']) if nameservers or searchservers: rhel_util.update_resolve_conf_file(self.resolve_conf_fn, nameservers, searchservers) return dev_names
def _write_network(self, settings): # Convert debian settings to ifcfg format entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) # Make the intermediate format as the suse format... nameservers = [] searchservers = [] dev_names = entries.keys() for (dev, info) in entries.items(): net_fn = self.network_script_tpl % (dev) mode = info.get("auto") if mode and mode.lower() == "true": mode = "auto" else: mode = "manual" net_cfg = { "BOOTPROTO": info.get("bootproto"), "BROADCAST": info.get("broadcast"), "GATEWAY": info.get("gateway"), "IPADDR": info.get("address"), "LLADDR": info.get("hwaddress"), "NETMASK": info.get("netmask"), "STARTMODE": mode, "USERCONTROL": "no", } if dev != "lo": net_cfg["ETHERDEVICE"] = dev net_cfg["ETHTOOL_OPTIONS"] = "" else: net_cfg["FIREWALL"] = "no" rhel_util.update_sysconfig_file(net_fn, net_cfg, True) if "dns-nameservers" in info: nameservers.extend(info["dns-nameservers"]) if "dns-search" in info: searchservers.extend(info["dns-search"]) if nameservers or searchservers: rhel_util.update_resolve_conf_file(self.resolve_conf_fn, nameservers, searchservers) return dev_names
def _write_network(self, settings): entries = net_util.translate_network(settings) aix_util.remove_resolve_conf_file(self.resolve_conf_fn) print("Translated ubuntu style network settings %s into %s" % (settings, entries)) # Make the intermediate format as the rhel format... nameservers = [] searchservers = [] dev_names = entries.keys() create_dhcp_file = True run_dhcpcd = False run_autoconf6 = False ipv6_interface = None # First, make sure the services starts out uncommented in /etc/rc.tcpip aix_util.disable_dhcpcd() aix_util.disable_ndpd_host() aix_util.disable_autoconf6() for (dev, info) in entries.iteritems(): run_cmd = 0 chdev_cmd = ['/usr/sbin/chdev'] log_chdev_cmd = ['/usr/sbin/chdev'] if dev not in 'lo': aix_dev = aix_util.translate_devname(dev) if info.get('bootproto') == 'dhcp': aix_util.config_dhcp(aix_dev, info, create_dhcp_file) create_dhcp_file = False run_dhcpcd = True else: chdev_cmd.extend(['-l', aix_dev]) log_chdev_cmd.extend(['-l', aix_dev]) if info['ipv6'] == True: chdev_opts = { "address" : '-anetaddr6=', "netmask" : '-aprefixlen=', } run_cmd = 1 run_autoconf6 = True if ipv6_interface is None: ipv6_interface = aix_dev else: ipv6_interface = "any" if info['ipv4'] == True: chdev_opts = { "address" : '-anetaddr=', "netmask" : '-anetmask=', } run_cmd = 1 for (key, val) in info.iteritems(): if key in chdev_opts and val and isinstance(val, basestring): chdev_cmd.append(chdev_opts[key] + val) log_chdev_cmd.append(chdev_opts[key] + val) if run_cmd: try: util.subp(chdev_cmd, logstring=log_chdev_cmd) time.sleep(2) except Exception as e: raise e if 'mtu' in info: util.subp(["/usr/sbin/chdev", "-l", aix_dev, "-amtu=" + info['mtu']], capture=False, rcs=[0, 1]) time.sleep(2) if aix_dev == "en0": if info['ipv6'] == True: aix_util.add_route("ipv6", info.get('gateway')) if info['ipv4'] == True: aix_util.add_route("ipv4", info.get('gateway')) if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if 'dns-search' in info: searchservers.extend(info['dns-search']) if run_dhcpcd: aix_util.enable_dhcpcd() if run_autoconf6: aix_util.enable_ndpd_host() aix_util.enable_autoconf6(ipv6_interface) if nameservers or searchservers: aix_util.update_resolve_conf_file(self.resolve_conf_fn, nameservers, searchservers) return dev_names
def _write_network(self, settings): entries = net_util.translate_network(settings) aix_util.remove_resolve_conf_file(self.resolve_conf_fn) print("Translated ubuntu style network settings %s into %s" % (settings, entries)) # Make the intermediate format as the rhel format... nameservers = [] searchservers = [] dev_names = entries.keys() create_dhcp_file = True run_dhcpcd = False run_autoconf6 = False ipv6_interface = None # First, make sure the services starts out uncommented in /etc/rc.tcpip aix_util.disable_dhcpcd() aix_util.disable_ndpd_host() aix_util.disable_autoconf6() for (dev, info) in entries.iteritems(): run_cmd = 0 chdev_cmd = ['/usr/sbin/chdev'] log_chdev_cmd = ['/usr/sbin/chdev'] if dev not in 'lo': aix_dev = aix_util.translate_devname(dev) if info.get('bootproto') == 'dhcp': aix_util.config_dhcp(aix_dev, info, create_dhcp_file) create_dhcp_file = False run_dhcp = True else: chdev_cmd.extend(['-l', aix_dev]) log_chdev_cmd.extend(['-l', aix_dev]) if info['ipv6'] == True: chdev_opts = { "address": '-anetaddr6=', "netmask": '-aprefixlen=', } run_cmd = 1 run_autoconf6 = True if ipv6_interface is None: ipv6_interface = aix_dev else: ipv6_interface = "any" if info['ipv4'] == True: chdev_opts = { "address": '-anetaddr=', "netmask": '-anetmask=', } run_cmd = 1 for (key, val) in info.iteritems(): if key in chdev_opts and val and isinstance( val, basestring): chdev_cmd.append(chdev_opts[key] + val) log_chdev_cmd.append(chdev_opts[key] + val) chdev_cmd.append("-astate=down") log_chdev_cmd.append("-astate=down") if run_cmd: try: util.subp(chdev_cmd, logstring=log_chdev_cmd) except Exception as e: raise e if info['ipv6'] == True: aix_util.add_route("ipv6", info.get('gateway')) if info['ipv4'] == True: aix_util.add_route("ipv4", info.get('gateway')) if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if 'dns-search' in info: searchservers.extend(info['dns-search']) if run_dhcp: aix_util.enable_dhcpcd() if run_autoconf6: aix_util.enable_ndpd_host() aix_util.enable_autoconf6(ipv6_interface) if nameservers or searchservers: aix_util.update_resolve_conf_file(self.resolve_conf_fn, nameservers, searchservers) return dev_names
def _write_network(self, settings): entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) route_entries = [] route_entries = translate_routes(settings) dev_names = entries.keys() dev_index = 10 nameservers = [] searchdomains = [] # Format for systemd for (dev, info) in entries.items(): if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if 'dns-search' in info: searchdomains.extend(info['dns-search']) if dev == 'lo': continue net_fn = network_file_name(self.network_conf_dir, dev) if not net_fn: net_fn = self.network_conf_dir + \ str(dev_index) + '-' + dev + '.network' else: net_fn = self.network_conf_dir + net_fn dhcp_enabled = 'no' if info.get('bootproto') == 'dhcp': if settings.find('inet dhcp') >= 0 and settings.find('inet6 dhcp') >= 0: dhcp_enabled = 'yes' else: dhcp_enabled = 'ipv6' if info.get( 'inet6') == True else 'ipv4' net_cfg = { 'Name': dev, 'DHCP': dhcp_enabled, } if info.get('hwaddress'): net_cfg['MACAddress'] = info.get('hwaddress') if info.get('address'): net_cfg['Address'] = "%s" % (info.get('address')) if info.get('netmask'): net_cfg['Address'] += "/%s" % ( mask_to_net_prefix(info.get('netmask'))) if info.get('gateway'): net_cfg['Gateway'] = info.get('gateway') if info.get('dns-nameservers'): net_cfg['DNS'] = str( tuple(info.get('dns-nameservers'))).replace(',', '') if info.get('dns-search'): net_cfg['Domains'] = str( tuple(info.get('dns-search'))).replace(',', '') route_entry = [] if dev in route_entries: route_entry = route_entries[dev] route_index = 0 found = True while found: route_name = 'routes.' + str(route_index) if route_name in route_entries[dev]: val = str(tuple(route_entries[dev][route_name])).replace( ',', '') if val: net_cfg[route_name] = val else: found = False route_index += 1 if info.get('auto'): self._write_interface_file(net_fn, net_cfg, route_entry) resolve_data = [] new_resolve_data = [] with open(self.resolve_conf_fn, "r") as rf: resolve_data = rf.readlines() LOG.debug("Old Resolve Data\n") LOG.debug("%s", resolve_data) for item in resolve_data: if (nameservers and ('DNS=' in item)) or (searchdomains and ('Domains=' in item)): continue else: new_resolve_data.append(item) new_resolve_data = new_resolve_data + \ convert_resolv_conf(nameservers, searchdomains) LOG.debug("New resolve data\n") LOG.debug("%s", new_resolve_data) if nameservers or searchdomains: util.write_file(self.resolve_conf_fn, ''.join(new_resolve_data)) return dev_names
def _write_network(self, settings): # Convert debian settings to ifcfg format entries = net_util.translate_network(settings) LOG.debug("Translated ubuntu style network settings %s into %s", settings, entries) # Match Debian/Ubunto distro functionality of clean slating # the network interface configuration. # Remove all existing ifcfg-eth* files. This cleans up files that # are left around if you capture an image from a VM with 5 NICs # and deploy it with 1 NIC. rhel_util.remove_ifcfg_files(self.network_script_dir) rhel_util.remove_resolve_conf_file(self.resolve_conf_fn) util.del_file(self.routes_fn) # Make the intermediate format as the suse format... nameservers = [] searchservers = [] dev_names = entries.keys() mac_addrs = [] for (dev, info) in entries.iteritems(): mac_addrs.append(info.get('hwaddress')) net_fn = self.network_script_tpl % (dev) mode = info.get('auto') if mode: mode = 'auto' else: mode = 'manual' net_cfg = {} net_cfg['BOOTPROTO'] = info.get('bootproto') net_cfg['BROADCAST'] = info.get('broadcast') net_cfg['LLADDR'] = info.get('hwaddress') net_cfg['STARTMODE'] = mode if info['ipv6']: prefix = info.get('netmask') ipv6addr = info.get('address') net_cfg['IPADDR_0'] = ipv6addr net_cfg['PREFIXLEN_0'] = prefix net_cfg['LABEL_0'] = '0' if info['ipv4']: net_cfg['NETMASK'] = info.get('netmask') net_cfg['IPADDR'] = info.get('address') if dev != 'lo': # net_cfg['ETHERDEVICE'] = dev net_cfg['ETHTOOL_OPTIONS'] = '' net_cfg['USERCONTROL'] = 'no' net_cfg['NM_CONTROLLED'] = 'no' net_cfg['BRIDGE'] = 'yes' else: net_cfg['FIREWALL'] = 'no' if dev == 'eth0' and info.get('gateway'): self._write_default_route(self.routes_fn, info.get('gateway')) if 'mtu' in info: net_cfg['MTU'] = info.get('mtu') # Remove the existing cfg file so the network configuration # is a replacement versus an update to match debian distro # functionality. if dev != 'lo': util.del_file(net_fn) rhel_util.update_sysconfig_file(net_fn, net_cfg, True) if 'dns-nameservers' in info: nameservers.extend(info['dns-nameservers']) if 'dns-search' in info: searchservers.extend(info['dns-search']) if nameservers or searchservers: rhel_util.update_resolve_conf_file(self.resolve_conf_fn, nameservers, searchservers) return dev_names, mac_addrs
def _write_network(self, settings): entries = net_util.translate_network(settings) LOG.debug( "Translated ubuntu style network settings %s into %s", settings, entries, ) dev_names = entries.keys() nameservers = [] for (dev, info) in entries.items(): if "dns-nameservers" in info: nameservers.extend(info["dns-nameservers"]) if dev == "lo": continue net_fn = self.network_conf_fn + "." + dev dns_nameservers = info.get("dns-nameservers") if isinstance(dns_nameservers, (list, tuple)): dns_nameservers = str(tuple(dns_nameservers)).replace(",", "") # eth0, {'auto': True, 'ipv6': {}, 'bootproto': 'dhcp'} # lo, {'dns-nameservers': ['10.0.1.3'], 'ipv6': {}, 'auto': True} results = "" if info.get("bootproto") == "dhcp": results += 'config_{name}="dhcp"'.format(name=dev) else: results += ('config_{name}="{ip_address} netmask {netmask}"\n' 'mac_{name}="{hwaddr}"\n').format( name=dev, ip_address=info.get("address"), netmask=info.get("netmask"), hwaddr=info.get("hwaddress"), ) results += 'routes_{name}="default via {gateway}"\n'.format( name=dev, gateway=info.get("gateway")) if info.get("dns-nameservers"): results += 'dns_servers_{name}="{dnsservers}"\n'.format( name=dev, dnsservers=dns_nameservers) util.write_file(net_fn, results) self._create_network_symlink(dev) if info.get("auto"): cmd = [ "rc-update", "add", "net.{name}".format(name=dev), "default", ] try: (_out, err) = subp.subp(cmd) if len(err): LOG.warning( "Running %s resulted in stderr output: %s", cmd, err, ) except subp.ProcessExecutionError: util.logexc(LOG, "Running interface command %s failed", cmd) if nameservers: util.write_file(self.resolve_conf_fn, convert_resolv_conf(nameservers)) return dev_names