-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Comments below. On Fri, 30 Apr 2010, Radek Vykydal wrote:
Former Network.write was used to write config both to anaconda environment and to installed system. It became quite messy and unreadable doing both things as writing to installed system was just copying the file from anaconda root to system root for all files except ifcfg-DEVICE. Using two separate methods makes clear what we are doing. Also there is a question if we need to copy the network config to system twice as we are doing - first in preinstall step, and then in writeconfig step. The latter is not necessary I think and seem to be actually a noop. --- __init__.py | 2 +- network.py | 193 +++++++++++++++++++++++++++++---------------------------- yuminstall.py | 2 +- 3 files changed, 99 insertions(+), 98 deletions(-) diff --git a/__init__.py b/__init__.py index b53877c..21e7640 100644 --- a/__init__.py +++ b/__init__.py @@ -300,7 +300,7 @@ class Anaconda(object): self.instLanguage.write(self.rootPath) self.timezone.write(self.rootPath) - self.network.write(instPath=self.rootPath, anaconda=self) + self.network.copyConfigToPath(instPath=self.rootPath) self.desktop.write(self.rootPath) self.users.write(self.rootPath) self.security.write(self.rootPath) diff --git a/network.py b/network.py index 9e46f00..97eb992 100644 --- a/network.py +++ b/network.py @@ -317,12 +317,17 @@ class NetworkDevice(IfcfgFile): def writeIfcfgFile(self, dir=None): IfcfgFile.write(self, dir) + @property + def keyfilePath(self): + return os.path.join(self.dir, "keys-%s" % self.iface) + def writeWepkeyFile(self, dir=None, overwrite=True): if not self.wepkey: return False if not dir: - dir = os.path.dirname(self.path) - keyfile = os.path.join(dir, "keys-%s" % self.iface) + keyfile = self.keyfilePath + else: + keyfile = os.path.join(dir, os.path.basename(self.keyfilePath)) if not overwrite and os.path.isfile(keyfile): return False @@ -576,29 +581,56 @@ class Network: return False - def write(self, instPath='', anaconda=None): + def _copyFileToPath(self, file, instPath='', overwrite=False): + if not os.path.isfile(file): + return False + destfile = os.path.join(instPath, file.lstrip('/')) + if (os.path.isfile(destfile) and not overwrite): + return False + if not os.path.isdir(os.path.dirname(destfile)): + iutil.mkdirChain(os.path.dirname(destfile)) + shutil.copy(file, destfile) + return True - devices = self.netdevices.values() + def copyConfigToPath(self, instPath=''): - if len(devices) == 0: + if len(self.netdevices) == 0: return - sysconfig = instPath + sysconfigDir - netscripts = instPath + netscriptsDir - destnetwork = instPath + networkConfFile + # /etc/sysconfig/network-scripts/ifcfg-DEVICE + # /etc/sysconfig/network-scripts/keys-DEVICE + # /etc/dhclient-DEVICE.conf + # TODORV: do we really don't want overwrite on live cd? + for devName, device in self.netdevices.items(): + self._copyFileToPath(device.path, instPath) + self._copyFileToPath(device.keyfilePath, instPath) + dhclientfile = os.path.join("/etc/dhclient-%s.conf" % devName)
This needs to be "/etc/dhcp/dhclient-%s.conf"
+ self._copyFileToPath(dhclientfile, instPath) + + # /etc/sysconfig/network + self._copyFileToPath(networkConfFile, instPath, + overwrite=flags.livecdInstall) - if not os.path.isdir(netscripts): - iutil.mkdirChain(netscripts) + # /etc/resolv.conf + self._copyFileToPath("/etc/resolv.conf", instPath, + overwrite=flags.livecdInstall) + + # /etc/udev/rules.d/70-persistent-net.rules + self._copyFileToPath("/etc/udev/rules.d/70-persistent-net.rules", + instPath, overwrite=flags.livecdInstall) + + def write(self, anaconda=None): + + devices = self.netdevices.values() + + if len(devices) == 0: + return # /etc/sysconfig/network-scripts/ifcfg-* # /etc/sysconfig/network-scripts/keys-* for dev in devices: device = dev.get('DEVICE') - cfgfile = "%s/ifcfg-%s" % (netscripts, device,) - if (instPath) and (os.path.isfile(cfgfile)): - continue - bootproto = dev.get('BOOTPROTO').lower() # write out the hostname as DHCP_HOSTNAME if given (#81613) if (bootproto == 'dhcp' and self.hostname and @@ -623,28 +655,11 @@ class Network: dev.set(('NM_CONTROLLED', 'no')) break - dev.writeIfcfgFile(netscripts) + dev.writeIfcfgFile(netscriptsDir) dev.log_file("===== write\n") - # This is not needed for anaconda environment, because writing - # out keys is handled by stage1, kickstart, or nm-c-e. - # For installed system (instPath == /mnt/sysimage), the files - # should just be copied, not written again as the info we have - # in Network object will not reflect what nm-c-e - # could have changed (it has wider set of options like wpa, etc...) - # and it isn't worth to implement all this possibilities - # in Network object to be able to keep it updated. if dev.wepkey: - dev.writeWepkeyFile(dir=netscripts, overwrite=False) - - # /etc/dhclient-DEVICE.conf - dhclientconf = '/etc/dhclient-' + device + '.conf' - if os.path.isfile(dhclientconf): - destdhclientconf = '%s%s' % (instPath, dhclientconf,) - try: - shutil.copy(dhclientconf, destdhclientconf) - except: - log.warning("unable to copy %s to target system" % (dhclientconf,)) + dev.writeWepkeyFile(dir=netscriptsDir, overwrite=False) # TODORV: note that we use the last dev from the loop above @@ -653,27 +668,26 @@ class Network: # care of this case. # /etc/sysconfig/network - if (not instPath) or (not os.path.isfile(destnetwork)) or flags.livecdInstall: - newnetwork = "%s.new" % (destnetwork,) + newnetwork = "%s.new" % (networkConfFile) - f = open(newnetwork, "w") - f.write("NETWORKING=yes\n") - f.write("HOSTNAME=") + f = open(newnetwork, "w") + f.write("NETWORKING=yes\n") + f.write("HOSTNAME=") - # use instclass hostname if set(kickstart) to override - if self.hostname: - f.write(self.hostname + "\n") - else: - f.write("localhost.localdomain\n") + # use instclass hostname if set(kickstart) to override + if self.hostname: + f.write(self.hostname + "\n") + else: + f.write("localhost.localdomain\n") - if dev.get('GATEWAY'): - f.write("GATEWAY=%s\n" % (dev.get('GATEWAY'),)) + if dev.get('GATEWAY'): + f.write("GATEWAY=%s\n" % (dev.get('GATEWAY'),)) - if dev.get('IPV6_DEFAULTGW'): - f.write("IPV6_DEFAULTGW=%s\n" % (dev.get('IPV6_DEFAULTGW'),)) + if dev.get('IPV6_DEFAULTGW'): + f.write("IPV6_DEFAULTGW=%s\n" % (dev.get('IPV6_DEFAULTGW'),)) - f.close() - shutil.move(newnetwork, destnetwork) + f.close() + shutil.move(newnetwork, networkConfFile) # If the hostname was not looked up, but typed in by the user, # domain might not be computed, so do it now. @@ -700,66 +714,53 @@ class Network: self.domains = [domainname] # /etc/resolv.conf - if (not instPath) or (not os.path.isfile(instPath + '/etc/resolv.conf')) or flags.livecdInstall: - if os.path.isfile('/etc/resolv.conf') and instPath != '': - destresolv = "%s/etc/resolv.conf" % (instPath,) - shutil.copy('/etc/resolv.conf', destresolv) - elif (self.domains != ['localdomain'] and self.domains) or \ - self.hasNameServers(dev.info): - resolv = "%s/etc/resolv.conf" % (instPath,) + if (self.domains != ['localdomain'] and self.domains) or \ + self.hasNameServers(dev.info): + resolv = "/etc/resolv.conf" - f = open(resolv, "w") + f = open(resolv, "w") - if self.domains != ['localdomain'] and self.domains: - f.write("search %s\n" % (string.joinfields(self.domains, ' '),)) + if self.domains != ['localdomain'] and self.domains: + f.write("search %s\n" % (string.joinfields(self.domains, ' '),)) - for key in dev.info.keys(): - if key.upper().startswith('DNS'): - f.write("nameserver %s\n" % (dev.get(key),)) + for key in dev.info.keys(): + if key.upper().startswith('DNS'): + f.write("nameserver %s\n" % (dev.get(key),)) - f.close() + f.close() # /etc/udev/rules.d/70-persistent-net.rules rules = "/etc/udev/rules.d/70-persistent-net.rules" - destRules = instPath + rules - if (not instPath) or (not os.path.isfile(destRules)) or \ - flags.livecdInstall: - if not os.path.isdir("%s/etc/udev/rules.d" %(instPath,)): - iutil.mkdirChain("%s/etc/udev/rules.d" %(instPath,)) - - if os.path.isfile(rules) and rules != destRules: - shutil.copy(rules, destRules) - else: - f = open(destRules, "w") - f.write(""" + f = open(rules, "w") + f.write(""" # This file was automatically generated by the /lib/udev/write_net_rules # program run by the persistent-net-generator.rules rules file. # # You can modify it, as long as you keep each rule on a single line. """) - for dev in self.netdevices.values(): - addr = dev.get("HWADDR") - if not addr: - continue - devname = dev.get("DEVICE") - basename = devname - while basename != "" and basename[-1] in string.digits: - basename = basename[:-1] - - # rules are case senstive for address. Lame. - addr = addr.lower() - - s = "" - if len(dev.description) > 0: - s = "# %s (rule written by anaconda)\n" % (dev.description,) - else: - s = "# %s (rule written by anaconda)\n" % (devname,) - s = s + 'SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS=="?*", ATTR{address}=="%s", ATTR{type}=="1", KERNEL=="%s*", NAME="%s"\n' % (addr, basename, devname,) - - f.write(s) - - f.close() + for dev in self.netdevices.values(): + addr = dev.get("HWADDR") + if not addr: + continue + devname = dev.get("DEVICE") + basename = devname + while basename != "" and basename[-1] in string.digits: + basename = basename[:-1] + + # rules are case senstive for address. Lame. + addr = addr.lower() + + s = "" + if len(dev.description) > 0: + s = "# %s (rule written by anaconda)\n" % (dev.description,) + else: + s = "# %s (rule written by anaconda)\n" % (devname,) + s = s + 'SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS=="?*", ATTR{address}=="%s", ATTR{type}=="1", KERNEL=="%s*", NAME="%s"\n' % (addr, basename, devname,) + + f.write(s) + + f.close() # write out current configuration state and wait for NetworkManager # to bring the device up, watch NM state and return to the caller diff --git a/yuminstall.py b/yuminstall.py index 604da7b..17e8df4 100644 --- a/yuminstall.py +++ b/yuminstall.py @@ -1588,7 +1588,7 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon if os.access("/etc/modprobe.d/anaconda.conf", os.R_OK): shutil.copyfile("/etc/modprobe.d/anaconda.conf", anaconda.rootPath + "/etc/modprobe.d/anaconda.conf") - anaconda.network.write(instPath=anaconda.rootPath, anaconda=anaconda) + anaconda.network.copyConfigToPath(instPath=anaconda.rootPath) anaconda.storage.write(anaconda.rootPath) if not anaconda.isHeadless: anaconda.keyboard.write(anaconda.rootPath)
- -- David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAkvi2m0ACgkQ5hsjjIy1VknrPACgpTOfs5Op32vlSZpoNDg2/A97 F7MAoLmhie/ZPSXQcENHTBBl6Dft91L8 =AM7+ -----END PGP SIGNATURE----- _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list