def update_hostname_data_test(self): from pyanaconda.kickstart import AnacondaKSHandler handler = AnacondaKSHandler() ksdata = self.ksdata_mock # network --hostname oldhostname # pylint: disable=no-member nd = handler.NetworkData(hostname="oldhostname", bootProto="") ksdata.network.network = [nd] network.update_hostname_data(ksdata, "newhostname") # network --hostname newhostname self.assertEqual(ksdata.network.network[0].hostname, "newhostname") # no network in ks ksdata.network.network = [] network.update_hostname_data(ksdata, "newhostname") # network --hostname newhostname self.assertEqual(ksdata.network.network[0].hostname, "newhostname") # network --bootproto dhcp --onboot no --device em1 --hostname oldhostname # pylint: disable=no-member nd = handler.NetworkData(bootProto="dhcp", onboot="no", device="em1", hostname="oldhostname") ksdata.network.network = [nd] network.update_hostname_data(ksdata, "newhostname") # network --bootproto dhcp --onboot no --device em1 --hostname newhostname self.assertEqual(ksdata.network.network[0].hostname, "newhostname") self.assertEqual(len(ksdata.network.network), 1) # network --bootproto dhcp --onboot no --device em1 # pylint: disable=no-member nd = handler.NetworkData(bootProto="dhcp", onboot="no", device="em1") ksdata.network.network = [nd] network.update_hostname_data(ksdata, "newhostname") # network --bootproto dhcp --onboot no --device em1 # network --hostname newhostname self.assertEqual(ksdata.network.network[0].hostname, "") self.assertEqual(ksdata.network.network[1].hostname, "newhostname") # network --bootproto dhcp --onboot no --device em1 # network --hostname oldhostname # pylint: disable=no-member nd1 = handler.NetworkData(bootProto="dhcp", onboot="no", device="em1") # pylint: disable=no-member nd2 = handler.NetworkData(hostname="oldhostname", bootProto="") ksdata.network.network = [nd1, nd2] network.update_hostname_data(ksdata, "newhostname") # network --bootproto dhcp --onboot no --device em1 # network --hostname newhostname self.assertEquals(ksdata.network.network[0].hostname, "") self.assertEquals(ksdata.network.network[1].hostname, "newhostname")
def dumpMissingDefaultIfcfgs(): """ Dump missing default ifcfg file for wired devices. Returns list of devices for which ifcfg file was dumped. """ rv = [] for devname in nm.nm_devices(): if not nm.nm_device_type_is_ethernet(devname): continue try: con_uuid = nm.nm_device_setting_value(devname, "connection", "uuid") except nm.SettingsNotFoundError: if find_ifcfg_file_of_device(devname): continue from pyanaconda.kickstart import AnacondaKSHandler handler = AnacondaKSHandler() network_data = handler.NetworkData(onboot=False, ipv6="auto") add_connection_for_ksdata(network_data, devname) rv.append(devname) return rv
def hostname_ksdata(hostname): from pyanaconda.kickstart import AnacondaKSHandler handler = AnacondaKSHandler() # pylint: disable-msg=E1101 return handler.NetworkData(hostname=hostname, bootProto="")
def ifcfg_to_ksdata(ifcfg, devname): from pyanaconda.kickstart import AnacondaKSHandler handler = AnacondaKSHandler() kwargs = {} # no network command for bond slaves if ifcfg.get("MASTER"): return None # no network command for team slaves if ifcfg.get("TEAM_MASTER"): return None # ipv4 and ipv6 if ifcfg.get("ONBOOT") and ifcfg.get("ONBOOT") == "no": kwargs["onboot"] = False if ifcfg.get('MTU') and ifcfg.get('MTU') != "0": kwargs["mtu"] = ifcfg.get('MTU') # ipv4 if not ifcfg.get('BOOTPROTO'): kwargs["noipv4"] = True else: if iutil.lowerASCII(ifcfg.get('BOOTPROTO')) == 'dhcp': kwargs["bootProto"] = "dhcp" if ifcfg.get('DHCPCLASS'): kwargs["dhcpclass"] = ifcfg.get('DHCPCLASS') elif ifcfg.get('IPADDR'): kwargs["bootProto"] = "static" kwargs["ip"] = ifcfg.get('IPADDR') netmask = ifcfg.get('NETMASK') prefix = ifcfg.get('PREFIX') if not netmask and prefix: netmask = prefix2netmask(int(prefix)) if netmask: kwargs["netmask"] = netmask # note that --gateway is common for ipv4 and ipv6 if ifcfg.get('GATEWAY'): kwargs["gateway"] = ifcfg.get('GATEWAY') elif ifcfg.get('IPADDR0'): kwargs["bootProto"] = "static" kwargs["ip"] = ifcfg.get('IPADDR0') prefix = ifcfg.get('PREFIX0') if prefix: netmask = prefix2netmask(int(prefix)) kwargs["netmask"] = netmask # note that --gateway is common for ipv4 and ipv6 if ifcfg.get('GATEWAY0'): kwargs["gateway"] = ifcfg.get('GATEWAY0') # ipv6 if (not ifcfg.get('IPV6INIT') or ifcfg.get('IPV6INIT') == "no"): kwargs["noipv6"] = True else: if ifcfg.get('IPV6_AUTOCONF') in ("yes", ""): kwargs["ipv6"] = "auto" else: if ifcfg.get('IPV6ADDR'): kwargs["ipv6"] = ifcfg.get('IPV6ADDR') if ifcfg.get('IPV6_DEFAULTGW') \ and ifcfg.get('IPV6_DEFAULTGW') != "::": kwargs["ipv6gateway"] = ifcfg.get('IPV6_DEFAULTGW') if ifcfg.get('DHCPV6C') == "yes": kwargs["ipv6"] = "dhcp" # ipv4 and ipv6 dnsline = '' for key in ifcfg.info.keys(): if iutil.upperASCII(key).startswith('DNS'): if dnsline == '': dnsline = ifcfg.get(key) else: dnsline += "," + ifcfg.get(key) if dnsline: kwargs["nameserver"] = dnsline if ifcfg.get("ETHTOOL_OPTS"): kwargs["ethtool"] = ifcfg.get("ETHTOOL_OPTS") if ifcfg.get("ESSID"): kwargs["essid"] = ifcfg.get("ESSID") # hostname if ifcfg.get("DHCP_HOSTNAME"): kwargs["hostname"] = ifcfg.get("DHCP_HOSTNAME") # bonding # FIXME: dracut has only BOND_OPTS if ifcfg.get("BONDING_MASTER") == "yes" or ifcfg.get("TYPE") == "Bond": slaves = get_bond_slaves_from_ifcfgs([devname, ifcfg.get("UUID")]) if slaves: kwargs["bondslaves"] = ",".join(slaves) bondopts = ifcfg.get("BONDING_OPTS") if bondopts: sep = "," if sep in bondopts: sep = ";" kwargs["bondopts"] = sep.join(bondopts.split()) # vlan if ifcfg.get("VLAN") == "yes" or ifcfg.get("TYPE") == "Vlan": kwargs["device"] = ifcfg.get("PHYSDEV") kwargs["vlanid"] = ifcfg.get("VLAN_ID") # pylint: disable-msg=E1101 nd = handler.NetworkData(**kwargs) # teaming if ifcfg.get("TYPE") == "Team" or ifcfg.get("DEVICETYPE") == "Team": slaves = get_team_slaves([devname, ifcfg.get("UUID")]) for dev, cfg in slaves: nd.teamslaves.append((dev, cfg)) teamconfig = nm.nm_device_setting_value(devname, "team", "config") if teamconfig: nd.teamconfig = teamconfig return nd
def hostname_ksdata(hostname): from pyanaconda.kickstart import AnacondaKSHandler handler = AnacondaKSHandler() kwargs = {} return handler.NetworkData(hostname=hostname, bootProto="")