[PATCH rhel7-branch] Set ONBOOT=yes for the device used for installation (#1002544).

Radek Vykydal rvykydal at redhat.com
Mon Oct 7 11:27:36 UTC 2013


We set ONBOOT=no by default for all devices not used in initramfs
which are autoactivated in anaconda.

This will go away when we turn autoactivation of these devices off. For now,
I use similar code as in fedora.py class only with different policy.

Following the autoactivation patch it will be possible to remove
setNetworkOnbootDefault for rhel, for fedora I'll probably move the code from
fedora.py to network.py to use fedora.py only to detect installation class.

---
 pyanaconda/installclasses/rhel.py | 38 ++++++++++++++++++++++++++++++++++++++
 pyanaconda/network.py             | 17 +++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/pyanaconda/installclasses/rhel.py b/pyanaconda/installclasses/rhel.py
index cfc25b3..02dab71 100644
--- a/pyanaconda/installclasses/rhel.py
+++ b/pyanaconda/installclasses/rhel.py
@@ -20,6 +20,8 @@
 from pyanaconda.installclass import BaseInstallClass
 from pyanaconda.constants import *
 from pyanaconda.product import *
+from pyanaconda import network
+from pyanaconda import nm
 import types
 
 class InstallClass(BaseInstallClass):
@@ -46,5 +48,41 @@ class InstallClass(BaseInstallClass):
         BaseInstallClass.configure(self, anaconda)
         BaseInstallClass.setDefaultPartitioning(self, anaconda.storage)
 
+    def setNetworkOnbootDefault(self, ksdata):
+        # for installations using network
+        if ksdata.method.method not in ("url", "nfs"):
+            return
+
+        # if there is no device to be autoactivated after reboot (we set all
+        # devices not used in initramfs to ONBOOT=no by default)
+        for devName in nm.nm_devices():
+            if nm.nm_device_type_is_wifi(devName):
+                continue
+            try:
+                onboot = nm.nm_device_setting_value(devName, "connection", "autoconnect")
+            except nm.DeviceSettingsNotFoundError:
+                continue
+            if not onboot == False:
+                return
+
+        # set ONBOOT=yes for the device used during installation
+        # (ie for majority of cases the one having the default route)
+        devName = network.default_route_device()
+        if not devName:
+            return
+        if nm.nm_device_type_is_wifi(devName):
+            return
+        ifcfg_path = network.find_ifcfg_file_of_device(devName, root_path=ROOT_PATH)
+        if not ifcfg_path:
+            return
+        ifcfg = network.IfcfgFile(ifcfg_path)
+        ifcfg.read()
+        ifcfg.set(('ONBOOT', 'yes'))
+        ifcfg.write()
+        for nd in ksdata.network.network:
+            if nd.device == devName:
+                nd.onboot = True
+                break
+
     def __init__(self):
         BaseInstallClass.__init__(self)
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 103cb76..eafdcfa 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -675,6 +675,23 @@ def ifaceForHostIP(host):
 
     return routeInfo[routeInfo.index("dev") + 1]
 
+def default_route_device():
+    routes = iutil.execWithCapture("ip", [ "route", "show"])
+    if not routes:
+        log.error("Could not get default route device")
+        return None
+
+    for line in routes.split("\n"):
+        if line.startswith("default"):
+            parts = line.split()
+            if parts[3] == "dev":
+                return parts[4]
+            else:
+                log.error("Could not parse default route device")
+                return None
+
+    return None
+
 def copyFileToPath(file, destPath='', overwrite=False):
     if not os.path.isfile(file):
         return False
-- 
1.7.11.7



More information about the anaconda-patches mailing list