[PATCH 4/4] networking: use ksdata.network.hostname, consolidate writing sysconfig/network
Radek Vykydal
rvykydal at redhat.com
Thu Jul 26 08:37:49 UTC 2012
The aim is to use ksdata.network.hostname which is new property (there
is a related kickstart patch) obtaining the hostname from network commands
(ksdata.network.network list of NetworkData objects).
notes:
- getHostname (actual hostname of system) is still used in dracutSetupArgs,
we need to get ksdata passed somehow from bootloader.py:set_boot_args()
- Hostname of installer environment is still set in kickstart. We used to
do it because of mdadm member naming (640743) but this is not needed
anymore - mdadm actually doesn't use it. If it starts to again, or
does it in some special conditions, we can pass ksdata.network.hostname
(as we do for default vg names) using --homehost option.
We might need to set the hostname for some installed package though,
so I am keeping it.
- We should think about where to set hostname in GUI. This should happen
before writing storage (vg, mdmember names) or we can drop default
naming based on hostname.
---
pyanaconda/install.py | 2 +-
pyanaconda/network.py | 71 +++++++++++-----------------------
pyanaconda/storage/__init__.py | 14 ++-----
pyanaconda/ui/gui/spokes/network.py | 9 ++++-
4 files changed, 36 insertions(+), 60 deletions(-)
diff --git a/pyanaconda/install.py b/pyanaconda/install.py
index 45a659a..ac37cbd 100644
--- a/pyanaconda/install.py
+++ b/pyanaconda/install.py
@@ -79,7 +79,7 @@ def doInstall(storage, payload, ksdata, instClass):
ksdata.services.execute(storage, ksdata, instClass)
ksdata.keyboard.execute(storage, ksdata, instClass)
- writeNetworkConf(storage, instClass)
+ writeNetworkConf(storage, ksdata, instClass)
# Creating users and groups requires some pre-configuration.
u = Users()
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index cbfbef8..ac9bd00 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-*
+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)
+ copyFileToPath(dhclientfile, destPath)
- # /etc/resolv.conf
- _copyFileToPath("/etc/resolv.conf", destPath,
- overwrite=flags.livecdInstall)
def get_ksdevice_name(ksspec=""):
@@ -782,24 +762,17 @@ 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=")
- hostname = getHostname()
- if hostname:
- f.write(hostname + "\n")
- else:
- f.write("localhost.localdomain\n")
+ f.write("HOSTNAME=%s\n" % ksdata.network.hostname)
gateway = ipv6_defaultgw = None
for iface in reversed(getDevices()):
@@ -821,8 +794,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)
@@ -887,10 +859,13 @@ def usedByRootOnISCSI(iface, storage):
return False
-def writeNetworkConf(storage, instClass):
- write_sysconfig_network()
+def writeNetworkConf(storage, ksdata, instClass):
+ 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()
diff --git a/pyanaconda/storage/__init__.py b/pyanaconda/storage/__init__.py
index ae63bbf..64e25e8 100644
--- a/pyanaconda/storage/__init__.py
+++ b/pyanaconda/storage/__init__.py
@@ -1117,11 +1117,8 @@ class Storage(object):
name = kwargs.pop("name")
else:
hostname = ""
- if self.data:
- for nd in self.data.network.dataList():
- if nd.hostname:
- hostname = nd.hostname
- break
+ if self.data and self.data.network.hostname is not None:
+ hostname = self.data.network.hostname
name = self.suggestContainerName(hostname=hostname, prefix="vg")
@@ -1188,11 +1185,8 @@ class Storage(object):
# set up the volume label, using hostname if necessary
if not name:
hostname = ""
- if self.data:
- for nd in self.data.network.dataList():
- if nd.hostname:
- hostname = nd.hostname
- break
+ if self.data and self.data.network.hostname is not None:
+ hostname = self.data.network.hostname
name = self.suggestContainerName(prefix="btrfs",
hostname=hostname)
diff --git a/pyanaconda/ui/gui/spokes/network.py b/pyanaconda/ui/gui/spokes/network.py
index b11fb4c..b19c223 100644
--- a/pyanaconda/ui/gui/spokes/network.py
+++ b/pyanaconda/ui/gui/spokes/network.py
@@ -39,7 +39,8 @@ from pyanaconda.ui.gui.spokes import NormalSpoke, StandaloneSpoke
from pyanaconda.ui.gui.categories.software import SoftwareCategory
from pyanaconda.ui.gui.hubs.summary import SummaryHub
-from pyanaconda.network import NetworkDevice, netscriptsDir, kickstartNetworkData, getActiveNetDevs
+from pyanaconda.network import NetworkDevice, netscriptsDir, kickstartNetworkData, getActiveNetDevs, getHostname
+from pyanaconda.kickstart import NetworkData
from gi.repository import GLib, GObject, Pango, Gio, NetworkManager, NMClient
import dbus
@@ -969,6 +970,12 @@ class NetworkStandaloneSpoke(StandaloneSpoke):
def __init__(self, *args, **kwargs):
StandaloneSpoke.__init__(self, *args, **kwargs)
+
+ if self.data.network.hostname is None:
+ hostname = getHostname()
+ nd = NetworkData(hostname=hostname)
+ self.data.network.network.append(nd)
+
self.network_control_box = NetworkControlBox(self.builder)
parent = self.builder.get_object("AnacondaStandaloneWindow-action_area5")
parent.add(self.network_control_box.vbox)
--
1.7.4
More information about the anaconda-patches
mailing list