[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH 3/3] Use NM applet for network enablement.



---
 pyanaconda/__init__.py       |    3 +
 pyanaconda/gui.py            |  130 ++++--------------------------------
 pyanaconda/iw/network_gui.py |  153 ------------------------------------------
 pyanaconda/network.py        |   54 +--------------
 pyanaconda/yuminstall.py     |    3 +
 5 files changed, 22 insertions(+), 321 deletions(-)

diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py
index b167bd5..db12ffd 100644
--- a/pyanaconda/__init__.py
+++ b/pyanaconda/__init__.py
@@ -290,6 +290,9 @@ class Anaconda(object):
         self.instLanguage.write(self.rootPath)
 
         self.timezone.write(self.rootPath)
+        if self.displayMode == 'g':
+            # we need to do this in case nm-c-e was run
+            self.network.update()
         self.network.write()
         self.network.copyConfigToPath(instPath=self.rootPath)
         self.network.disableNMForStorageDevices(self,
diff --git a/pyanaconda/gui.py b/pyanaconda/gui.py
index 48537f7..3b4574d 100755
--- a/pyanaconda/gui.py
+++ b/pyanaconda/gui.py
@@ -895,123 +895,21 @@ class InstallInterface(InstallInterfaceBase):
     def resume(self):
         pass
 
-
-    # just_setup is used for [Configure Network] button
-    def enableNetwork(self, just_setup=False):
-
-        if len(self.anaconda.network.netdevices) == 0:
-            return False
-
-
-        from iw.network_gui import (runNMCE,
-                                 selectInstallNetDeviceDialog,
-                                 selectSSIDsDialog)
-
-        networkEnabled = False
-        while not networkEnabled:
-
-            # We need to do it in each iteration because user can
-            # delete ifcfg file in nm-c-e
-            nm_controlled_devices = [devname for (devname, dev)
-                                     in self.anaconda.network.netdevices.items()
-                                     if not dev.usedByFCoE(self.anaconda)]
-            if not just_setup and not nm_controlled_devices:
+    def enableNetwork(self):
+        title = _("No Network Available")
+        msg = _("This requires that you have an active "
+              "network connection during the installation "
+              "process.  Please configure a network interface "
+            "and continue.")
+        buttons = [_("Cancel"), _("_Continue")]
+        while not network.hasActiveNetDev():
+            rc = self.anaconda.intf.messageWindow(title, msg,
+                                    type="custom", custom_icon="info",
+                                    custom_buttons=buttons)
+            if rc == 0:
                 return False
-
-            if just_setup:
-                install_device = None
-            else:
-                install_device = selectInstallNetDeviceDialog(self.anaconda.network,
-                                                              nm_controlled_devices)
-                if not install_device:
-                    break
-
-            # update ifcfg files for nm-c-e
-            self.anaconda.network.setNMControlledDevices(nm_controlled_devices)
-            if not just_setup:
-                self.anaconda.network.presetDefaultConfiguration([install_device])
-
-            # we might want to do this only once
-            if self.anaconda.network.hasWirelessDev():
-                # NOTE: For wireless, we need supplicant to go to ready state,
-                #       that means to get the wireless device managed by NM
-                self.anaconda.network.writeIfcfgFiles()
-                w = self.anaconda.intf.waitWindow(_("Wireless setup"),
-                                    _("Scanning access points for wireless devices"))
-                # get available wireless APs
-                dev_all_ssids = self.anaconda.network.getSSIDs()
-                w.pop()
-                # prefer APs we already have set e.g. via kickstart or stage 1
-                self.anaconda.network.selectPreferredSSIDs(dev_all_ssids)
-                # select wireless APs
-                dev_ssids = selectSSIDsDialog(dev_all_ssids) or dev_all_ssids
-                self.anaconda.network.updateIfcfgsSSID(dev_ssids)
-
-            self.anaconda.network.writeIfcfgFiles()
-            # Logging can race here with ifcfg-rh updating the file
-            network.logIfcfgFiles(message="Dump before nm-c-e (can race "
-                                           "with ifcfg updating). ")
-            runNMCE(self.anaconda)
-            network.logIfcfgFiles(message="Dump after nm-c-e. ")
-
-            self.anaconda.network.update()
-
-            if just_setup:
-                waited_devs = self.anaconda.network.getOnbootControlledIfaces()
-            else:
-                waited_devs = [install_device]
-                self.anaconda.network.updateActiveDevices([install_device])
-
-            self.anaconda.network.write()
-
-            if waited_devs:
-                w = WaitWindow(_("Waiting for NetworkManager"),
-                               _("Waiting for NetworkManager to activate "
-                                 "these devices: %s" % ",".join(waited_devs)))
-                failed_devs = self.anaconda.network.waitForDevicesActivation(waited_devs)
-                w.pop()
-
-                if just_setup:
-                    if failed_devs:
-                        self._handleDeviceActivationFail(failed_devs)
-                    if len(failed_devs) < len(waited_devs):
-                        # if any device was activated, remember to reset
-                        # resolver
-                        networkEnabled = True
-                else:
-                    networkEnabled = install_device not in failed_devs
-                    if not networkEnabled:
-                        self._handleNetworkError(install_device)
-
-            if just_setup:
-                break
-
-        if networkEnabled:
-            network.resetResolver()
-        return networkEnabled
-
-    def _handleDeviceActivationFail(self, devices):
-        d = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
-                              gtk.BUTTONS_OK,
-                              _("Failed to activate these "
-                                "network interfaces: %s" %
-                                ",".join(devices)))
-        d.set_title(_("Network Configuration"))
-        d.set_position(gtk.WIN_POS_CENTER)
-        addFrame(d)
-        d.run()
-        d.destroy()
-
-    def _handleNetworkError(self, field):
-        d = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
-                              gtk.BUTTONS_OK,
-                              _("An error occurred trying to bring up the "
-                                "%s network interface.") % (field,))
-        d.set_title(_("Error Enabling Network"))
-        d.set_position(gtk.WIN_POS_CENTER)
-        addFrame(d)
-        d.run()
-        d.destroy()
+        network.resetResolver()
+        return True
 
     def setInstallProgressClass(self, c):
         self.instProgress = c
diff --git a/pyanaconda/iw/network_gui.py b/pyanaconda/iw/network_gui.py
index b3484fe..e3d3d5b 100644
--- a/pyanaconda/iw/network_gui.py
+++ b/pyanaconda/iw/network_gui.py
@@ -87,156 +87,3 @@ class NetworkWindow(InstallWindow):
         self.anaconda.network.hostname = hostname
         return None
 
-def NMCEExited(pid, condition, anaconda):
-    if anaconda:
-        anaconda.intf.icw.window.set_sensitive(True)
-
-# TODORV: get rid of setting sensitive completely?
-def runNMCE(anaconda=None, blocking=True):
-    if not blocking and anaconda:
-        anaconda.intf.icw.window.set_sensitive(False)
-    cmd = ["/usr/bin/nm-connection-editor"]
-    out = open("/dev/tty5", "w")
-    try:
-        proc = subprocess.Popen(cmd, stdout=out, stderr=out)
-    except Exception as e:
-        if not blocking and anaconda:
-            anaconda.intf.icw.window.set_sensitive(True)
-        import logging
-        log = logging.getLogger("anaconda")
-        log.error("Could not start nm-connection-editor: %s" % e)
-        return None
-    else:
-        if blocking:
-            proc.wait()
-        else:
-            gobject.child_watch_add(proc.pid, NMCEExited, data=anaconda, priority=gobject.PRIORITY_DEFAULT)
-
-
-def selectInstallNetDeviceDialog(network, devices = None):
-
-    devs = devices or network.netdevices.keys()
-    if not devs:
-        return None
-    devs.sort()
-
-    dialog = gtk.Dialog(_("Select network interface"))
-    dialog.add_button('gtk-cancel', gtk.RESPONSE_CANCEL)
-    dialog.add_button('gtk-ok', 1)
-    dialog.set_position(gtk.WIN_POS_CENTER)
-    gui.addFrame(dialog)
-
-    dialog.vbox.pack_start(gui.WrappingLabel(
-        _("This requires that you have an active "
-          "network connection during the installation "
-          "process.  Please configure a network interface.")))
-
-    combo = gtk.ComboBox()
-    cell = gtk.CellRendererText()
-    combo.pack_start(cell, True)
-    combo.set_attributes(cell, text = 0)
-    cell.set_property("wrap-width", 525)
-    combo.set_size_request(480, -1)
-    store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
-    combo.set_model(store)
-
-    ksdevice = network.getKSDevice()
-    if ksdevice:
-        ksdevice = ksdevice.get('DEVICE')
-    preselected = None
-
-    for dev in devices:
-        i = store.append(None)
-        if not preselected:
-            preselected = i
-
-        desc = network.netdevices[dev].description
-        if desc:
-            desc = "%s - %s" %(dev, desc)
-        else:
-            desc = "%s" %(dev,)
-
-        hwaddr = network.netdevices[dev].get("HWADDR")
-
-        if hwaddr:
-            desc = "%s - %s" %(desc, hwaddr,)
-
-        if ksdevice and ksdevice == dev:
-            preselected = i
-
-        store[i] = (desc, dev)
-
-    combo.set_active_iter(preselected)
-    dialog.vbox.pack_start(combo)
-
-    dialog.show_all()
-
-    rc = dialog.run()
-
-    if rc in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]:
-        install_device = None
-    else:
-        active = combo.get_active_iter()
-        install_device = combo.get_model().get_value(active, 1)
-
-    dialog.destroy()
-    return install_device
-
-def selectSSIDsDialog(devssids):
-    """Dialog for access point selection.
-
-    devssids - dict iface->[ssid1, ssid2, ssid3, ...]
-    returns  - dict iface->[ssidX] or None on Cancel
-    """
-
-    # If there are no choices, don't ask
-    for dev, ssids in devssids.items():
-        if len(ssids) > 1:
-            break
-    else:
-        return devssids
-
-    rv = {}
-    dialog = gtk.Dialog(_("Select APs"))
-    dialog.add_button('gtk-cancel', gtk.RESPONSE_CANCEL)
-    dialog.add_button('gtk-ok', 1)
-    dialog.set_position(gtk.WIN_POS_CENTER)
-    gui.addFrame(dialog)
-
-    dialog.vbox.pack_start(gui.WrappingLabel(
-        _("Select APs for wireless devices")))
-
-    table = gtk.Table(len(devssids), 2)
-    table.set_row_spacings(5)
-    table.set_col_spacings(5)
-
-    combos = {}
-    for i, (dev, ssids) in enumerate(devssids.items()):
-
-        label = gtk.Label(dev)
-        table.attach(label, 0, 1, i, i+1, gtk.FILL, gtk.FILL)
-
-        combo = gtk.combo_box_new_text()
-        for ssid in ssids:
-            combo.append_text(ssid)
-        table.attach(combo, 1, 2, i, i+1, gtk.FILL, gtk.FILL)
-        combo.set_active(0)
-        combos[dev] = combo
-
-    dialog.vbox.pack_start(table)
-
-    dialog.show_all()
-
-    rc = dialog.run()
-
-    # cancel
-    if rc in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]:
-        rv = None
-    else:
-        for dev, combo in combos.items():
-            rv[dev] = [combo.get_active_text()]
-
-    dialog.destroy()
-    return rv
-
-
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 7a11c4f..7f8bfda 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -350,13 +350,10 @@ class Network:
         self.overrideDHCPhostname = False
 
         self.update()
-        # We want wireless devices to be nm controlled by default
-        self.controlWireless()
 
         # Set all devices to be controlled by NM by default.
-        # We can filter out storage devices only after
-        # we have device tree populated. So we do it before
-        # running nm-c-e and before writing ifcfg files to system.
+        # Note: We can filter out FCoE devices with usedByFCoE only after
+        # we have device tree populated.
         self.setNMControlledDevices(self.netdevices.keys())
 
     def update(self):
@@ -497,47 +494,6 @@ class Network:
             else:
                 device.set(('NM_CONTROLLED', 'yes'))
 
-    # devices == None => set for all
-    def updateActiveDevices(self, devices=None):
-        for devname, device in self.netdevices.items():
-            if devices and devname not in devices:
-                device.set(('ONBOOT', 'no'))
-            else:
-                device.set(('ONBOOT', 'yes'))
-
-    def presetDefaultConfiguration(self, devices=None):
-        for devname, device in self.netdevices.items():
-            if not devices or devname in devices:
-                device.set(('BOOTPROTO', 'dhcp'))
-
-    def getOnbootControlledIfaces(self):
-        ifaces = []
-        for iface, device in self.netdevices.items():
-            if (device.get('ONBOOT') == "yes" and
-                device.get('NM_CONTROLLED') == "yes"):
-                ifaces.append(iface)
-        return ifaces
-
-    def updateIfcfgsSSID(self, devssids):
-        for devname, device in self.netdevices.items():
-            if devname in devssids.keys() and devssids[devname]:
-                device.set(('ESSID', devssids[devname][0]))
-                device.writeIfcfgFile()
-
-    def getSSIDs(self):
-        return getSSIDs(self.netdevices.keys())
-
-    def selectPreferredSSIDs(self, dev_ssids):
-        for iface, device in self.netdevices.items():
-            preferred = device.get('ESSID')
-            if preferred and preferred in dev_ssids[iface]:
-                dev_ssids[iface] = [preferred]
-
-    def controlWireless(self):
-        for devname, device in self.netdevices.items():
-            if isys.isWirelessDevice(devname):
-                device.set(('NM_CONTROLLED', 'yes'))
-
     def writeKS(self, f):
         devNames = self.netdevices.keys()
         devNames.sort()
@@ -629,12 +585,6 @@ class Network:
 
         return False
 
-    def hasWirelessDev(self):
-        for dev in self.netdevices:
-            if isys.isWirelessDevice(dev):
-                return True
-        return False
-
     def _copyFileToPath(self, file, instPath='', overwrite=False):
         if not os.path.isfile(file):
             return False
diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py
index 4ceafcc..25991e9 100644
--- a/pyanaconda/yuminstall.py
+++ b/pyanaconda/yuminstall.py
@@ -1687,6 +1687,9 @@ 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", 
                                 anaconda.rootPath + "/etc/modprobe.d/anaconda.conf")
+            if anaconda.displayMode == 'g':
+                # we need to do this in case nm-c-e was run
+                anaconda.network.update()
             anaconda.network.write()
             anaconda.network.copyConfigToPath(instPath=anaconda.rootPath)
             anaconda.storage.write(anaconda.rootPath)
-- 
1.7.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]