[PATCH master 5/7] networking: consolidate writing/copying of configuration files
Radek Vykydal
rvykydal at redhat.com
Fri Aug 24 09:36:15 UTC 2012
---
pyanaconda/network.py | 64 +++++++++++++++++--------------------------------
1 files changed, 22 insertions(+), 42 deletions(-)
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index de432af..1118357 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -698,7 +698,7 @@ def setHostname(hn):
iutil.execWithRedirect("hostname", ["-v", hn ],
stdout="/dev/tty5", stderr="/dev/tty5")
-def _copyFileToPath(file, destPath='', overwrite=False):
+def copyFileToPath(file, destPath='', overwrite=False):
if not os.path.isfile(file):
return False
destfile = os.path.join(destPath, file.lstrip('/'))
@@ -709,42 +709,22 @@ def _copyFileToPath(file, destPath='', overwrite=False):
shutil.copy(file, destfile)
return True
-def _copyIfcfgFiles(destPath):
+# /etc/sysconfig/network-scripts/ifcfg-*
+# /etc/sysconfig/network-scripts/keys-*
+# TODO: routing info from /etc/sysconfig/network-scripts?
+def copyIfcfgFiles(destPath):
files = os.listdir(netscriptsDir)
for cfgFile in files:
if cfgFile.startswith(("ifcfg-","keys-")):
srcfile = os.path.join(netscriptsDir, cfgFile)
- _copyFileToPath(srcfile, destPath)
+ copyFileToPath(srcfile, destPath)
-# TODO: routing info from /etc/sysconfig/network-scripts?
-def copyConfigToPath(destPath):
- if flags.imageInstall:
- # for image installs we only want to write out
- # /etc/sysconfig/network
- destfile = os.path.normpath(destPath + networkConfFile)
- if not os.path.isdir(os.path.dirname(destfile)):
- iutil.mkdirChain(os.path.dirname(destfile))
- shutil.move("/tmp/sysconfig-network", destfile)
- return
-
- # /etc/sysconfig/network-scripts/ifcfg-*
- # /etc/sysconfig/network-scripts/keys-*
- # we can copy all of them
- _copyIfcfgFiles(destPath)
-
- # /etc/dhcp/dhclient-DEVICE.conf
- # TODORV: do we really don't want overwrite on live cd?
+# /etc/dhcp/dhclient-DEVICE.conf
+# TODORV: do we really don't want overwrite on live cd?
+def copyDhclientConfFiles(destPath):
for devName in getDevices():
dhclientfile = os.path.join("/etc/dhcp/dhclient-%s.conf" % devName)
- _copyFileToPath(dhclientfile, destPath)
-
- # /etc/sysconfig/network
- _copyFileToPath(networkConfFile, destPath,
- overwrite=flags.livecdInstall)
-
- # /etc/resolv.conf
- _copyFileToPath("/etc/resolv.conf", destPath,
- overwrite=flags.livecdInstall)
+ copyFileToPath(dhclientfile, destPath)
def get_ksdevice_name(ksspec=""):
@@ -782,16 +762,14 @@ def get_ifcfg_value(iface, key, root_path=""):
dev.loadIfcfgFile()
return dev.get(key)
-def write_sysconfig_network():
+def write_sysconfig_network(rootpath, ksdata, overwrite=False):
- if flags.imageInstall:
- # don't write files into host's /etc/sysconfig on image installs
- newnetwork = "/tmp/sysconfig-network"
- else:
- newnetwork = "%s.new" % (networkConfFile)
+ cfgfile = os.path.normpath(rootpath + networkConfFile)
+ if (os.path.isfile(cfgfile) and not overwrite):
+ return False
- f = open(newnetwork, "w")
- f.write("# Generated by anaconda")
+ f = open(cfgfile, "w")
+ f.write("# Generated by anaconda\n")
f.write("NETWORKING=yes\n")
f.write("HOSTNAME=")
@@ -821,8 +799,7 @@ def write_sysconfig_network():
f.write("IPV6_DEFAULTGW=%s\n" % ipv6_defaultgw)
f.close()
- if not flags.imageInstall:
- shutil.move(newnetwork, networkConfFile)
+ return True
def disableIPV6(rootpath):
cfgfile = os.path.normpath(rootpath + ipv6ConfFile)
@@ -893,9 +870,12 @@ def usedByRootOnISCSI(iface, storage):
return False
def writeNetworkConf(storage, ksdata, instClass):
- write_sysconfig_network()
+ write_sysconfig_network(ROOT_PATH, ksdata, overwrite=flags.livecdInstall)
disableIPV6(ROOT_PATH)
- copyConfigToPath(ROOT_PATH)
+ if not flags.imageInstall:
+ copyIfcfgFiles(ROOT_PATH)
+ copyDhclientConfFiles(ROOT_PATH)
+ copyFileToPath("/etc/resolv.conf", ROOT_PATH, overwrite=flags.livecdInstall)
# TODO the default for ONBOOT needs to be lay down
# before newui we didn't set it for kickstart installs
instClass.setNetworkOnbootDefault(ksdata)
--
1.7.4
More information about the anaconda-patches
mailing list