[PATCH 15/15] remove Network(): list of network devices, final steps

Radek Vykydal rvykydal at redhat.com
Thu Jul 19 10:02:48 UTC 2012


This is almost the final step, the object is not used anymore,
I am keeping the rest only not to forget to handle what is left:
- I need to look at imageInstall
- creating default ifcfg files (setDefaultConfig) should go to
dracut or some network initialization step

The whole patchset removes anaconda.network object aiming to have all
data/configuration in ksdata.

The object was needed for our GUI using nm-c-e. We used to keep list of device
configuration objects (basically ifcfg dictionaries) in it so that we could
tweak them to be able to use nm-c-e for configuration/activation of devices.
Now it seems we can do without the list although we still need to do some
modifications of ifcfg files at the end of installation (setting onboot policy,
setting values for devices used for storage)

Hopefuly we'll be able to represent all the data stored in network object
in ksdata.

Following to the patchset I want to update ksdata with NetworkData objects
for all devices and use it to replace network.getDevices(). I have to think
where it should happen:
- in kickstart.py
- or somewhere in pre-gui network initialization (so that it happens also
  for non-ks cases) where we e.g. activate default device if needed.
- or in initialize of standalone spoke - seems to late, we'll need it
  already for eventual bring-up of network

-----

To sum up what the network.py serves for now:

Some of network utility functions (more of them are in isys):
- hostname sanity checking
- ip sanity checking
- hostname resolution
- status of networking
  - connected?
  - list of active devices
- logging (ifcfg files)

Network configuration:
- hostname setting (getting?)
  - note: storage (lvm, raid) is using hostname for default names
- ksdevice resolution (link, MAC address, bootif)
  - probably we'll be able to remove it, now it is only used
    for unspecified --device in kickstart network command
- write kickstart (currently from ifcfg config)
  - used by apply method
- write dracut arguments (from ifcfg config)
  - note: depends on storage
- modify configuration of target system (ifcfg files)
  - note: depends on storage
  - ONBOOT policy (differs on rhel and Fedora)
  - FCoE - ONBOOT=yes the devices
  - root on iSCSI - NM_CONTROLLED=no for root on iscsi
    (there is a NM BZ to fix this)
- write /etc/sysconfig/network configuration
  - this should be reviewed
- copy network configuration files to system
  - ifcfg-<iface> files and wireless key-<iface> files
  - dhclient-<iface>.conf files
    (dhcpclass and dhcp timeout which is not supported in noloader)
  - /etc/sysconfig/network
  - /etc/resolv.conf - genrated by NM
  - /etc/udev/rules.d/70-persistent-net.rules (review)
- disable ipv6 on target system (noipv6 boot/ks option)
---
 pyanaconda/__init__.py              |    4 ++--
 pyanaconda/installclass.py          |    2 +-
 pyanaconda/installclasses/fedora.py |   13 ++++++++-----
 pyanaconda/iw/advanced_storage.py   |    8 ++++----
 pyanaconda/iw/network_gui.py        |    6 +++---
 pyanaconda/kickstart.py             |   26 +++++++++++++++++---------
 pyanaconda/network.py               |   32 +++++++-------------------------
 pyanaconda/rescue.py                |   15 +--------------
 pyanaconda/text.py                  |    4 ++--
 pyanaconda/textw/add_drive_text.py  |    6 +++---
 pyanaconda/textw/netconfig_text.py  |   16 ++++++++++------
 pyanaconda/vnc.py                   |    3 +--
 pyanaconda/yuminstall.py            |    4 ++--
 13 files changed, 61 insertions(+), 78 deletions(-)

diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py
index 0b2e93a..18628d2 100644
--- a/pyanaconda/__init__.py
+++ b/pyanaconda/__init__.py
@@ -285,11 +285,11 @@ class Anaconda(object):
         self.instLanguage.write()
 
         self.timezone.write()
-        if not self.ksdata:
-            self.instClass.setNetworkOnbootDefault(self.network)
         network.write_sysconfig_network()
         network.disableIPV6()
         network.copyConfigToPath(ROOT_PATH)
+        if not self.ksdata:
+            self.instClass.setNetworkOnbootDefault()
         network.disableNMForStorageDevices(self.storage)
         network.autostartFCoEDevices(self.storage)
         self.desktop.write()
diff --git a/pyanaconda/installclass.py b/pyanaconda/installclass.py
index 144df91..cf6fb8d 100644
--- a/pyanaconda/installclass.py
+++ b/pyanaconda/installclass.py
@@ -217,7 +217,7 @@ class BaseInstallClass(object):
 
         return (all(result.values()), result)
 
-    def setNetworkOnbootDefault(self, network):
+    def setNetworkOnbootDefault(self):
         pass
 
     def __init__(self):
diff --git a/pyanaconda/installclasses/fedora.py b/pyanaconda/installclasses/fedora.py
index bc575ea..e2c1543 100644
--- a/pyanaconda/installclasses/fedora.py
+++ b/pyanaconda/installclasses/fedora.py
@@ -21,7 +21,7 @@ from pyanaconda.installclass import BaseInstallClass
 from pyanaconda.constants import *
 from pyanaconda.product import *
 from pyanaconda import iutil
-from pyanaconda.network import hasActiveNetDev
+from pyanaconda import network
 from pyanaconda import isys
 
 import os, types
@@ -122,17 +122,20 @@ class InstallClass(BaseInstallClass):
         # than two versions ago!
         return newVer >= oldVer and newVer - oldVer <= 2
 
-    def setNetworkOnbootDefault(self, network):
+    def setNetworkOnbootDefault(self):
         # if something's already enabled, we can just leave the config alone
-        for devName, dev in network.netdevices.items():
-            if dev.get('ONBOOT') == 'yes':
+        for devName in network.getDevices():
+            if network.get_ifcfg_value(devName, "ONBOOT", ROOT_PATH) == "yes":
                 return
 
         # the default otherwise: bring up the first wired netdev with link
-        for devName, dev in network.netdevices.items():
+        for devName in network.getDevices():
             if (not isys.isWirelessDevice(devName) and
                 isys.getLinkStatus(devName)):
+                dev = network.NetworkDevice(ROOT_PATH + network.netscriptsDir, devName)
+                dev.loadIfcfgFile()
                 dev.set(('ONBOOT', 'yes'))
+                dev.writeIfcfgFile()
                 break
 
     def __init__(self):
diff --git a/pyanaconda/iw/advanced_storage.py b/pyanaconda/iw/advanced_storage.py
index 1375d7e..c343b9f 100644
--- a/pyanaconda/iw/advanced_storage.py
+++ b/pyanaconda/iw/advanced_storage.py
@@ -31,6 +31,7 @@ from pyanaconda import network
 from pyanaconda import partIntfHelpers as pih
 import pyanaconda.storage.fcoe
 import pyanaconda.storage.iscsi
+from pyanaconda import isys
 
 import logging
 log = logging.getLogger("anaconda")
@@ -337,19 +338,18 @@ def addFcoeDrive(anaconda):
     store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
     combo.set_model(store)
 
-    netdevs = anaconda.network.netdevices
-    keys = netdevs.keys()
+    keys = network.getDevices()
     keys.sort()
     selected_interface = None
     for dev in keys:
         i = store.append(None)
-        desc = netdevs[dev].description
+        desc = isys.getNetDevDesc(dev)
         if desc:
             desc = "%s - %s" %(dev, desc)
         else:
             desc = "%s" %(dev,)
 
-        mac = netdevs[dev].get("HWADDR")
+        mac = isys.getMacAddress(dev)
         if mac:
             desc = "%s - %s" %(desc, mac)
 
diff --git a/pyanaconda/iw/network_gui.py b/pyanaconda/iw/network_gui.py
index bdf2ee8..1fac765 100644
--- a/pyanaconda/iw/network_gui.py
+++ b/pyanaconda/iw/network_gui.py
@@ -51,7 +51,7 @@ class NetworkWindow(InstallWindow):
 
         self.netconfButton = self.xml.get_widget("netconfButton")
         self.netconfButton.connect("clicked", self._netconfButton_clicked)
-        if (len(self.anaconda.network.netdevices) == 0
+        if (len(network.getDevices()) == 0
             or flags.imageInstall
             or flags.livecdInstall):
             self.netconfButton.set_sensitive(False)
@@ -129,7 +129,7 @@ def runNMCE(anaconda=None, blocking=True):
 
 def selectInstallNetDeviceDialog(network, devices = None):
 
-    devs = devices or network.netdevices.keys()
+    devs = devices or network.getDevices()
     if not devs:
         return None
     devs.sort()
@@ -168,7 +168,7 @@ def selectInstallNetDeviceDialog(network, devices = None):
         else:
             desc = "%s" %(dev,)
 
-        hwaddr = network.netdevices[dev].get("HWADDR")
+        hwaddr = isys.getMacAddress(dev)
 
         if hwaddr:
             desc = "%s - %s" %(desc, hwaddr,)
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 4a2cbb7..285f643 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -657,7 +657,7 @@ class NetworkData(commands.network.F16_NetworkData):
                 network.setHostname(self.hostname)
             return
 
-        devices = self.anaconda.network.netdevices
+        devices = network.getDevices()
 
         if not self.device:
             if "ksdevice" in flags.cmdline:
@@ -669,7 +669,7 @@ class NetworkData(commands.network.F16_NetworkData):
                 device = network.getActiveNetDevs()[0]
             else:
                 msg = "first device found"
-                device = min(devices.keys())
+                device = min(devices)
             log.info("unspecified network --device in kickstart, using %s (%s)" %
                      (device, msg))
         else:
@@ -695,16 +695,20 @@ class NetworkData(commands.network.F16_NetworkData):
         # If we were given a network device name, grab the device object.
         # If we were given a MAC address, resolve that to a device name
         # and then grab the device object.  Otherwise, errors.
-        dev = None
 
-        if devices.has_key(device):
-            dev = devices[device]
-        else:
-            for (key, val) in devices.iteritems():
-                if val.get("HWADDR").lower() == device.lower():
-                    dev = val
+        if device not in devices:
+            for d in devices:
+                if isys.getMacAddress(d).lower() == device.lower():
+                    device = d
                     break
 
+        dev = network.NetworkDevice(ROOT_PATH, device)
+        try:
+            dev.loadIfcfgFile()
+        except IOError as e:
+            log.info("Can't load ifcfg file %s" % dev.path)
+            dev = None
+
         if self.hostname != "":
             network.setHostname(self.hostname)
             if not dev:
@@ -765,6 +769,10 @@ class NetworkData(commands.network.F16_NetworkData):
         if self.nodefroute:
             dev.set (("DEFROUTE", "no"))
 
+    #TODO
+    # write ifcfg file, carefuly handle ONBOOT value,
+    # problems - might activate the device!!!
+
 class MultiPath(commands.multipath.FC6_MultiPath):
     def parse(self, args):
         raise NotImplementedError("The multipath kickstart command is not currently supported")
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index bf94b1d..2cb57b2 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -405,41 +405,23 @@ class Network:
 
     def __init__(self):
 
-        self.update()
-
-    def update(self):
-        ifcfglog.debug("Network.update() called")
-
-        self.netdevices = {}
+        ifcfglog.debug("Network object created called")
 
+        # TODO this may need to be handled in getDevices()
         if flags.imageInstall:
             return
 
+        # TODO this should go away (patch pending),
+        # default ifcfg files should be created in dracut
+
         # populate self.netdevices
         devhash = isys.getDeviceProperties(dev=None)
         for iface in devhash.keys():
-            if isys.isWirelessDevice(iface):
-                device = WirelessNetworkDevice(iface)
-            else:
+            if not isys.isWirelessDevice(iface):
                 device = NetworkDevice(netscriptsDir, iface)
-                if os.access(device.path, os.R_OK):
-                    device.loadIfcfgFile()
-                else:
+                if not os.access(device.path, os.R_OK):
                     device.setDefaultConfig()
 
-            self.netdevices[iface] = device
-
-    # write out current configuration state and wait for NetworkManager
-    # to bring the device up, watch NM state and return to the caller
-    # once we have a state
-    def bringUp(self):
-        write_sysconfig_network()
-        if waitForConnection():
-            resetResolver()
-            return True
-        else:
-            return False
-
 def getDevices():
     # TODO: filter with existence of ifcfg file?
     return isys.getDeviceProperties().keys()
diff --git a/pyanaconda/rescue.py b/pyanaconda/rescue.py
index 4a17390..828fcb3 100644
--- a/pyanaconda/rescue.py
+++ b/pyanaconda/rescue.py
@@ -93,7 +93,7 @@ class RescueInterface(InstallInterfaceBase):
 	    return OkCancelWindow(self.screen, title, text)
 
     def enableNetwork(self, anaconda):
-        if len(anaconda.network.netdevices) == 0:
+        if len(network.getDevices()) == 0:
             return False
         from textw.netconfig_text import NetworkConfiguratorText
         w = NetworkConfiguratorText(self.screen, anaconda)
@@ -172,18 +172,6 @@ def makeResolvConf(instPath):
     f.write(buf)
     f.close()
 
-#
-# Write out something useful for networking and start interfaces
-#
-def startNetworking(network, intf):
-    # do lo first
-    if os.system("/usr/sbin/ifconfig lo 127.0.0.1"):
-        log.error("Error trying to start lo in rescue.py::startNetworking()")
-
-    # start up dhcp interfaces first
-    if not network.bringUp():
-        log.error("Error bringing up network interfaces")
-
 def runShell(screen = None, msg=""):
     if screen:
         screen.suspend()
@@ -239,7 +227,6 @@ def doRescue(anaconda):
                           "will not be available in rescue mode."))
                     break
 
-                startNetworking(anaconda.network, anaconda.intf)
                 break
             else:
                 break
diff --git a/pyanaconda/text.py b/pyanaconda/text.py
index 1b201c1..020f92a 100644
--- a/pyanaconda/text.py
+++ b/pyanaconda/text.py
@@ -36,7 +36,7 @@ from localeinfo import expandLangs
 from flags import flags
 from textw.constants_text import *
 from constants import *
-from network import hasActiveNetDev
+from network import hasActiveNetDev, getDevices
 from installinterfacebase import InstallInterfaceBase
 import imp
 import textw
@@ -389,7 +389,7 @@ class InstallInterface(InstallInterfaceBase):
         return passphrase
 
     def enableNetwork(self):
-        if len(self.anaconda.network.netdevices) == 0:
+        if len(getDevices) == 0:
             return False
         from textw.netconfig_text import NetworkConfiguratorText
         w = NetworkConfiguratorText(self.screen, self.anaconda)
diff --git a/pyanaconda/textw/add_drive_text.py b/pyanaconda/textw/add_drive_text.py
index b28af4f..5c9384d 100644
--- a/pyanaconda/textw/add_drive_text.py
+++ b/pyanaconda/textw/add_drive_text.py
@@ -24,6 +24,7 @@ from snack import *
 from constants_text import *
 from pyanaconda.constants import *
 import pyanaconda.partIntfHelpers as pih 
+from pyanaconda import isys
 
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
@@ -363,8 +364,7 @@ class addDriveDialog(object):
         return INSTALL_OK
 
     def addFcoeDriveDialog(self, screen):
-        netdevs = self.anaconda.network.netdevices
-        devs = netdevs.keys()
+        devs = network.getDevices()
         devs.sort()
 
         if not devs:
@@ -381,7 +381,7 @@ class addDriveDialog(object):
 
         interfaceList = Listbox(height=len(devs), scroll=1)
         for dev in devs:
-            hwaddr = netdevs[dev].get("HWADDR")
+            hwaddr = isys.getMacAddress(dev)
             if hwaddr:
                 desc = "%s - %.50s" % (dev, hwaddr)
             else:
diff --git a/pyanaconda/textw/netconfig_text.py b/pyanaconda/textw/netconfig_text.py
index 6be52f3..852201e 100644
--- a/pyanaconda/textw/netconfig_text.py
+++ b/pyanaconda/textw/netconfig_text.py
@@ -45,7 +45,7 @@ class NetworkConfiguratorText:
     def __init__(self, screen, anaconda):
         self.screen = screen
         self.anaconda = anaconda
-        self.netdevs = self.anaconda.network.netdevices
+        self.netdevs = network.getDevices()
 
         self._initValues()
 
@@ -68,14 +68,13 @@ class NetworkConfiguratorText:
         dev_list = []
         selected_devname = None
 
-        devnames = self.netdevs.keys()
-        devnames.sort()
+        devnames = self.netdevs.sort()
 
         # Preselect device set in kickstart
         ksdevice = network.get_ksdevice_name()
 
         for devname in devnames:
-            hwaddr = self.netdevs[devname].get("HWADDR")
+            hwaddr = isys.getMacAddress(devname)
 
             if hwaddr:
                 desc = "%s - %.50s" % (devname, hwaddr)
@@ -348,7 +347,9 @@ class NetworkConfiguratorText:
            Returns True in case of success, False if failed.
         """
 
-        dev = self.netdevs[devname]
+        dev = network.NetworkDevice(ROOT_PATH, devname)
+        dev.loadIfcfgFile()
+
         nameservers = ''
 
         if self.ipv4Selected:
@@ -395,15 +396,18 @@ class NetworkConfiguratorText:
         dev.set(('ONBOOT', 'yes'))
 
         w = self.anaconda.intf.waitWindow(_("Configuring Network Interfaces"), _("Waiting for NetworkManager"))
-        result = self.anaconda.network.bringUp()
+        dev.writeIfcfgFile()
+        result = network.waitForConnection()
         w.pop()
         if not result:
             self.anaconda.intf.messageWindow(_("Network Error"),
                                              _("There was an error configuring "
                                                "network device %s") % dev.iface)
             dev.set(("ONBOOT", "no"))
+            dev.writeIfcfgFile()
             return False
 
+        network.resetResolver()
         return True
 
     def _ipv4MethodToggled(self, *args):
diff --git a/pyanaconda/vnc.py b/pyanaconda/vnc.py
index b38f233..64c2ce1 100644
--- a/pyanaconda/vnc.py
+++ b/pyanaconda/vnc.py
@@ -80,12 +80,11 @@ class VncServer:
         # see if we can sniff out network info
         netinfo = network.Network()
 
-        devices = netinfo.netdevices
         active_devs = network.getActiveNetDevs()
 
         self.ip = None
         if active_devs != []:
-            devname = devices[active_devs[0]].iface
+            devname = active_devs[0]
             try:
                 ips = (isys.getIPAddresses(devname, version=4) +
                        isys.getIPAddresses(devname, version=6))
diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py
index fd7ba3e..bb98b86 100644
--- a/pyanaconda/yuminstall.py
+++ b/pyanaconda/yuminstall.py
@@ -1623,11 +1623,11 @@ 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", 
                                 ROOT_PATH + "/etc/modprobe.d/anaconda.conf")
-            if not anaconda.ksdata:
-                anaconda.instClass.setNetworkOnbootDefault(anaconda.network)
             network.write_sysconfig_network()
             network.disableIPV6()
             network.copyConfigToPath(ROOT_PATH)
+            if not anaconda.ksdata:
+                anaconda.instClass.setNetworkOnbootDefault()
             anaconda.storage.write()
         else:
             # ensure that /etc/mtab is a symlink to /proc/self/mounts
-- 
1.7.4



More information about the anaconda-patches mailing list