[PATCH rhel7-branch 3/4] network: GUI, add support for virtual devices removing (#1030870)

Radek Vykydal rvykydal at redhat.com
Fri Nov 29 12:17:02 UTC 2013


Resolves: rhbz#1030870
---
 pyanaconda/nm.py                    | 15 +++++++++++++++
 pyanaconda/ui/gui/spokes/network.py | 33 +++++++++++++++++++++++++++++----
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/pyanaconda/nm.py b/pyanaconda/nm.py
index 0d1d4a1..ceeb8fb 100644
--- a/pyanaconda/nm.py
+++ b/pyanaconda/nm.py
@@ -707,6 +707,21 @@ def nm_add_connection(values):
     connection = proxy.AddConnection('(a{sa{sv}})', settings)
     return connection
 
+def nm_delete_connection(uuid):
+    """Delete connection specified by uuid.
+
+       :param uuid: uuid of connection to be deleted
+       :type uuid: str
+       :return: True if connection was deleted, False if it was not found
+       :rtype: bool
+    """
+
+    settings_paths = _find_settings(uuid, "connection", "uuid")
+    if not settings_paths:
+        return False
+    proxy = _get_proxy(object_path=settings_paths[0], interface_name="org.freedesktop.NetworkManager.Settings.Connection")
+    settings = proxy.Delete()
+
 def nm_update_settings_of_device(name, new_values):
     """Update setting of device.
 
diff --git a/pyanaconda/ui/gui/spokes/network.py b/pyanaconda/ui/gui/spokes/network.py
index 0c822b7..fe89b7a 100644
--- a/pyanaconda/ui/gui/spokes/network.py
+++ b/pyanaconda/ui/gui/spokes/network.py
@@ -248,6 +248,11 @@ class DeviceConfiguration(object):
             iface = self.device.get_iface()
         else:
             iface = self.setting_value("connection", "interface-name")
+            if not iface:
+                hwaddr = self.setting_value("802-3-ethernet","mac-address")
+                if hwaddr:
+                    hwaddr = ":".join("%02X" % b for b in hwaddr)
+                    iface = nm.nm_hwaddr_to_device_name(hwaddr)
         return iface
 
     def setting_value(self, key1, key2):
@@ -312,6 +317,8 @@ class NetworkControlBox(GObject.GObject):
         self.builder.get_object("add_toolbutton").connect("clicked",
                                                            self.on_add_device_clicked)
         self.builder.get_object("remove_toolbutton").set_sensitive(False)
+        self.builder.get_object("remove_toolbutton").connect("clicked",
+                                                           self.on_remove_device_clicked)
 
         not_supported = ["start_hotspot_button",
                          "stop_hotspot_button",
@@ -423,6 +430,10 @@ class NetworkControlBox(GObject.GObject):
                 continue
             dev_cfg = DeviceConfiguration(con_uuid=uuid)
             if dev_cfg.device_type in self.supported_device_types:
+                # Configs for ethernet has been already added,
+                # this must be some slave.
+                if dev_cfg.device_type == NetworkManager.DeviceType.ETHERNET:
+                    continue
                 self.add_dev_cfg(dev_cfg)
 
         # select the first device
@@ -591,10 +602,19 @@ class NetworkControlBox(GObject.GObject):
             dev_type = model[ai][1]
             self.add_device(dev_type)
 
-    def add_device(self, type):
-        log.info("network: adding device of type %s" % type)
+    def on_remove_device_clicked(self, *args):
+        selection = self.builder.get_object("treeview_devices").get_selection()
+        model, itr = selection.get_selected()
+        if not itr:
+            return None
+        dev_cfg = model[itr][DEVICES_COLUMN_OBJECT]
+        model.remove(itr)
+        nm.nm_delete_connection(dev_cfg.con_uuid)
+
+    def add_device(self, ty):
+        log.info("network: adding device of type %s" % ty)
         self.kill_nmce(msg="Add device button clicked")
-        proc = subprocess.Popen(["nm-connection-editor", "--create", "--type=%s" % type])
+        proc = subprocess.Popen(["nm-connection-editor", "--create", "--ty=%s" % ty])
         self._running_nmce = proc
 
         GLib.child_watch_add(proc.pid, self.on_nmce_adding_exited)
@@ -694,7 +714,9 @@ class NetworkControlBox(GObject.GObject):
         # This should not concern wifi and ethernet devices,
         # just virtual devices e.g. vpn probably
         log.debug("network: GUI, device removed: %s" % (device.get_iface()))
-        self.dev_cfg(device=device).device = None
+        dev_cfg = self.dev_cfg(device=device)
+        if dev_cfg:
+            dev_cfg.device = None
 
     def refresh_ui(self, state=None):
 
@@ -863,6 +885,7 @@ class NetworkControlBox(GObject.GObject):
             self.builder.get_object("label_wired_vlanid").hide()
             self.builder.get_object("heading_wired_parent").hide()
             self.builder.get_object("label_wired_parent").hide()
+            self.builder.get_object("remove_toolbutton").set_sensitive(False)
         elif dev_type in [NetworkManager.DeviceType.BOND,
                           NetworkManager.DeviceType.TEAM]:
             notebook.set_current_page(0)
@@ -872,6 +895,7 @@ class NetworkControlBox(GObject.GObject):
             self.builder.get_object("label_wired_vlanid").hide()
             self.builder.get_object("heading_wired_parent").hide()
             self.builder.get_object("label_wired_parent").hide()
+            self.builder.get_object("remove_toolbutton").set_sensitive(True)
         elif dev_type == NetworkManager.DeviceType.VLAN:
             notebook.set_current_page(0)
             self.builder.get_object("heading_wired_slaves").hide()
@@ -880,6 +904,7 @@ class NetworkControlBox(GObject.GObject):
             self.builder.get_object("label_wired_vlanid").show()
             self.builder.get_object("heading_wired_parent").show()
             self.builder.get_object("label_wired_parent").show()
+            self.builder.get_object("remove_toolbutton").set_sensitive(True)
         elif dev_type == NetworkManager.DeviceType.WIFI:
             notebook.set_current_page(1)
             self.builder.get_object("button_wireless_options").set_sensitive(self.selected_ssid is not None)
-- 
1.7.11.7



More information about the anaconda-patches mailing list