On Thu, 2014-05-22 at 13:19 +0200, Radek Vykydal wrote:
Trying to consolidate a bit, keeping policy in installclasses
and routines in network module. Also be more specific when handling
exception.
---
pyanaconda/installclasses/fedora.py | 36 ++++++++---------------------------
pyanaconda/installclasses/rhel.py | 38 ++++++++-----------------------------
pyanaconda/network.py | 29 ++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 58 deletions(-)
diff --git a/pyanaconda/installclasses/fedora.py b/pyanaconda/installclasses/fedora.py
index db20ed5..1fe192b 100644
--- a/pyanaconda/installclasses/fedora.py
+++ b/pyanaconda/installclasses/fedora.py
@@ -20,7 +20,6 @@
from pyanaconda.installclass import BaseInstallClass
from pyanaconda.product import productName
from pyanaconda import network
-from pyanaconda import iutil
from pyanaconda import nm
from pyanaconda.i18n import N_
@@ -43,37 +42,18 @@ class InstallClass(BaseInstallClass):
BaseInstallClass.setDefaultPartitioning(self, anaconda.storage)
def setNetworkOnbootDefault(self, ksdata):
- # if something's already enabled, we can just leave the config alone
- for devName in nm.nm_devices():
- if nm.nm_device_type_is_wifi(devName):
+ if network.has_some_wired_autoconnect_device():
+ return
+ # choose first wired device having link
+ for dev in nm.nm_devices():
+ if nm.nm_device_type_is_wifi(dev):
continue
try:
- onboot = nm.nm_device_setting_value(devName, "connection",
"autoconnect")
- except nm.SettingsNotFoundError:
- continue
- if not onboot == False:
- return
-
- # the default otherwise: bring up the first wired netdev with link
- for devName in nm.nm_devices():
- if nm.nm_device_type_is_wifi(devName):
- continue
- try:
- link_up = nm.nm_device_carrier(devName)
- except ValueError:
+ link_up = nm.nm_device_carrier(dev)
+ except (nm.UnknownDeviceError, nm.PropertyNotFoundError):
continue
if link_up:
- ifcfg_path = network.find_ifcfg_file_of_device(devName,
root_path=iutil.getSysroot())
- if not ifcfg_path:
- continue
- 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
+ network.update_onboot_value(dev, "yes", ksdata)
break
def __init__(self):
diff --git a/pyanaconda/installclasses/rhel.py b/pyanaconda/installclasses/rhel.py
index 39c959b..ed8511e 100644
--- a/pyanaconda/installclasses/rhel.py
+++ b/pyanaconda/installclasses/rhel.py
@@ -21,7 +21,6 @@ from pyanaconda.i18n import N_
from pyanaconda.installclass import BaseInstallClass
from pyanaconda.product import productName
from pyanaconda import network
-from pyanaconda import iutil
from pyanaconda import nm
class InstallClass(BaseInstallClass):
@@ -49,40 +48,19 @@ class InstallClass(BaseInstallClass):
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.SettingsNotFoundError:
- 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:
+ if network.has_some_wired_autoconnect_device():
return
- if nm.nm_device_type_is_wifi(devName):
+ # choose the device used during installation
+ # (ie for majority of cases the one having the default route)
+ dev = network.default_route_device()
+ if not dev:
return
- ifcfg_path = network.find_ifcfg_file_of_device(devName,
root_path=iutil.getSysroot())
- if not ifcfg_path:
+ # ignore wireless (its ifcfgs would need to be handled differently)
+ if nm.nm_device_type_is_wifi(dev):
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
+ network.update_onboot_value(dev, "yes", ksdata)
def __init__(self):
BaseInstallClass.__init__(self)
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index fd8d092..2e473e8 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -1331,3 +1331,32 @@ def status_message():
def default_ks_vlan_interface_name(parent, vlanid):
return "%s.%s" % (parent, vlanid)
+
+def has_some_wired_autoconnect_device():
+ """Is there a wired network device with
autoconnect?"""
+ for dev in nm.nm_devices():
+ if nm.nm_device_type_is_wifi(dev):
+ continue
+ try:
+ onboot = nm.nm_device_setting_value(dev, "connection",
"autoconnect")
+ except nm.SettingsNotFoundError:
+ continue
+ if not onboot == False:
+ return True
+ return False
+
+def update_onboot_value(devname, value, ksdata):
+ """Update onboot value in ifcfg files and ksdata"""
+ log.debug("network: setting ONBOOT value of %s to %s", devname, value)
+ ifcfg_path = find_ifcfg_file_of_device(devname, root_path=iutil.getSysroot())
+ if not ifcfg_path:
+ log.debug("network: can't find ifcfg file of %s", devname)
+ return
+ ifcfg = 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
This looks good to me.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic