[PATCH 4/5 newui] Network spoke: implement apply method

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

 



---
 pyanaconda/network.py               |  148 ++++++++++++++++++-----------------
 pyanaconda/ui/gui/spokes/network.py |   39 +++++++++-
 2 files changed, 114 insertions(+), 73 deletions(-)

diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 61470c6..7e4796f 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -586,77 +586,7 @@ class Network:
 
         for devName in devNames:
             dev = self.netdevices[devName]
-
-            line = "network"
-
-            # ipv4 and ipv6
-            if dev.get("ONBOOT"):
-                line += " --onboot %s" % dev.get("ONBOOT")
-            line += " --device %s" % dev.iface
-            if dev.get('MTU') and dev.get('MTU') != "0":
-                line += " --mtu=%s" % dev.get('MTU')
-
-            # ipv4
-            if not dev.get('BOOTPROTO'):
-                line += " --noipv4"
-            else:
-                if dev.get('BOOTPROTO').lower() == 'dhcp':
-                    line += " --bootproto dhcp"
-                    if dev.get('DHCPCLASS'):
-                        line += " --dhcpclass %s" % dev.get('DHCPCLASS')
-                elif dev.get('IPADDR'):
-                    line += " --bootproto static --ip %s" % dev.get('IPADDR')
-                    netmask = dev.get('NETMASK')
-                    prefix  = dev.get('PREFIX')
-                    if not netmask and prefix:
-                        netmask = isys.prefix2netmask(int(prefix))
-                    if netmask:
-                        line += " --netmask %s" % netmask
-                    # note that --gateway is common for ipv4 and ipv6
-                    if dev.get('GATEWAY'):
-                        line += " --gateway %s" % dev.get('GATEWAY')
-
-            # ipv6
-            if (not dev.get('IPV6INIT') or
-                dev.get('IPV6INIT') == "no"):
-                line += " --noipv6"
-            else:
-                if dev.get('IPV6_AUTOCONF') == "yes":
-                    line += " --ipv6 auto"
-                else:
-                    if dev.get('IPV6ADDR'):
-                        line += " --ipv6 %s" % dev.get('IPV6ADDR')
-                        if dev.get('IPV6_DEFAULTGW'):
-                            line += " --gateway %s" % dev.get('IPV6_DEFAULTGW')
-                    if dev.get('DHCPV6') == "yes":
-                        line += " --ipv6 dhcp"
-
-            # ipv4 and ipv6
-            dnsline = ''
-            for key in dev.info.keys():
-                if key.upper().startswith('DNS'):
-                    if dnsline == '':
-                        dnsline = dev.get(key)
-                    else:
-                        dnsline += "," + dev.get(key)
-            if dnsline:
-                line += " --nameserver %s" % dnsline
-
-            if dev.get("ETHTOOL_OPTS"):
-                line += " --ethtool %s" % dev.get("ETHTOOL_OPTS")
-
-            if dev.get("ESSID"):
-                line += " --essid %s" % dev.get("ESSID")
-
-            # hostname
-            if dev.get("DHCP_HOSTNAME"):
-                line += " --hostname %s" % dev.get("DHCP_HOSTNAME")
-            elif dev.get("BOOTPROTO").lower != "dhcp":
-                if (self.hostname and
-                    self.hostname != "localhost.localdomain"):
-                    line += " --hostname %s" % self.hostname
-
-            line += "\n"
+            line = "%s" % kickstartNetworkData(dev, self.hostname)
             f.write(line)
 
     def hasNameServers(self, hash):
@@ -921,6 +851,82 @@ class Network:
 
         return netargs
 
+def kickstartNetworkData(ifcfg, hostname=None):
+
+    from pyanaconda.kickstart import NetworkData
+    kwargs = {}
+
+    # ipv4 and ipv6
+    if not ifcfg.get("ESSID"):
+        kwargs["device"] = ifcfg.iface
+    if ifcfg.get("ONBOOT") and ifcfg.get("ONBOOT" ) == "no":
+        kwargs["onboot"] = False
+    if ifcfg.get('MTU') and ifcfg.get('MTU') != "0":
+        kwargs["mtu"] = ifcfg.get('MTU')
+
+    # ipv4
+    if not ifcfg.get('BOOTPROTO'):
+        kwargs["noipv4"] = True
+    else:
+        if ifcfg.get('BOOTPROTO').lower() == 'dhcp':
+            kwargs["bootProto"] = "dhcp"
+            if ifcfg.get('DHCPCLASS'):
+                kwargs["dhcpclass"] = ifcfg.get('DHCPCLASS')
+        elif ifcfg.get('IPADDR'):
+            kwargs["bootProto"] = "static"
+            kwargs["ip"] = ifcfg.get('IPADDR')
+            netmask = ifcfg.get('NETMASK')
+            prefix  = ifcfg.get('PREFIX')
+            if not netmask and prefix:
+                netmask = isys.prefix2netmask(int(prefix))
+            if netmask:
+                kwargs["netmask"] = netmask
+            # note that --gateway is common for ipv4 and ipv6
+            if ifcfg.get('GATEWAY'):
+                kwargs["gateway"] = ifcfg.get('GATEWAY')
+
+    # ipv6
+    if (not ifcfg.get('IPV6INIT') or
+        ifcfg.get('IPV6INIT') == "no"):
+        kwargs["noipv6"] = True
+    else:
+        if ifcfg.get('IPV6_AUTOCONF') == "yes":
+            kwargs["ipv6"] = "auto"
+        else:
+            if ifcfg.get('IPV6ADDR'):
+                kwargs["ipv6"] = ifcfg.get('IPV6ADDR')
+                if ifcfg.get('IPV6_DEFAULTGW'):
+                    kwargs["gateway"] = ifcfg.get('IPV6_DEFAULTGW')
+            if ifcfg.get('DHCPV6') == "yes":
+                kwargs["ipv6"] = "dhcp"
+
+    # ipv4 and ipv6
+    dnsline = ''
+    for key in ifcfg.info.keys():
+        if key.upper().startswith('DNS'):
+            if dnsline == '':
+                dnsline = ifcfg.get(key)
+            else:
+                dnsline += "," + ifcfg.get(key)
+    if dnsline:
+        kwargs["nameserver"] = dnsline
+
+    if ifcfg.get("ETHTOOL_OPTS"):
+        kwargs["ethtool"] = ifcfg.get("ETHTOOL_OPTS")
+
+    if ifcfg.get("ESSID"):
+        kwargs["essid"] = ifcfg.get("ESSID")
+
+    # hostname
+    if ifcfg.get("DHCP_HOSTNAME"):
+        kwargs["hostname"] = ifcfg.get("DHCP_HOSTNAME")
+    elif ifcfg.get("BOOTPROTO").lower != "dhcp":
+        if (hostname and
+            hostname != "localhost.localdomain"):
+            kwargs["hostname"] = hostname
+
+    return NetworkData(**kwargs)
+
 def getSSIDs(devices_to_scan=None):
 
     rv = {}
diff --git a/pyanaconda/ui/gui/spokes/network.py b/pyanaconda/ui/gui/spokes/network.py
index c513b94..0552650 100644
--- a/pyanaconda/ui/gui/spokes/network.py
+++ b/pyanaconda/ui/gui/spokes/network.py
@@ -39,6 +39,8 @@ from pyanaconda.ui.gui.spokes import NormalSpoke, StandaloneSpoke
 from pyanaconda.ui.gui.categories.software import SoftwareCategory
 from pyanaconda.ui.gui.hubs.summary import SummaryHub
 
+from pyanaconda.network import NetworkDevice, netscriptsDir, kickstartNetworkData, getActiveNetDevs
+
 from gi.repository import GLib, GObject, Pango, Gio, NetworkManager, NMClient
 import dbus
 import socket
@@ -923,6 +925,11 @@ class NetworkControlBox():
 
         return sec_str
 
+    @property
+    def listed_devices(self):
+        return [row[DEVICES_COLUMN_OBJECT] for
+                row in self.builder.get_object("liststore_devices")]
+
 class NetworkSpoke(NormalSpoke):
     builderObjects = ["networkWindow", "liststore_wireless_network", "liststore_devices"]
     mainWidgetName = "networkWindow"
@@ -938,7 +945,11 @@ class NetworkSpoke(NormalSpoke):
         self.network_control_box = NetworkControlBox(self.builder)
 
     def apply(self):
-        pass
+        self.data.network.network = []
+        for dev in self.network_control_box.listed_devices:
+            network_data = getKSNetworkData(dev)
+            if network_data is not None:
+                self.data.network.network.append(network_data)
 
     @property
     def completed(self):
@@ -957,7 +968,6 @@ class NetworkSpoke(NormalSpoke):
         NormalSpoke.refresh(self)
         self.network_control_box.refresh()
 
-
 class NetworkStandaloneSpoke(StandaloneSpoke):
     builderObjects = ["networkStandaloneWindow", "networkControlBox_vbox", "liststore_wireless_network", "liststore_devices"]
     mainWidgetName = "networkStandaloneWindow"
@@ -976,6 +986,12 @@ class NetworkStandaloneSpoke(StandaloneSpoke):
         self._now_available = False
 
     def apply(self):
+        self.data.network.network = []
+        for dev in self.network_control_box.listed_devices:
+            network_data = getKSNetworkData(dev)
+            if network_data is not None:
+                self.data.network.network.append(network_data)
+
         self._now_available = self.network_control_box.status() != _("Not connected")
 
         if not self.payload.baseRepo and not self._initially_available and self._now_available:
@@ -1002,6 +1018,25 @@ class NetworkStandaloneSpoke(StandaloneSpoke):
         self.window.hide()
         Gtk.main_quit()
 
+def getKSNetworkData(device):
+    retval = None
+
+    ifcfg_suffix = None
+    if device.get_device_type() == NetworkManager.DeviceType.ETHERNET:
+        ifcfg_suffix = device.get_iface()
+    elif device.get_device_type() == NetworkManager.DeviceType.WIFI:
+        ap = device.get_active_access_point()
+        if ap:
+            ifcfg_suffix = ap.get_ssid()
+
+    if ifcfg_suffix:
+        device_cfg = NetworkDevice(netscriptsDir, ifcfg_suffix)
+        device_cfg.loadIfcfgFile()
+        retval = kickstartNetworkData(device_cfg)
+        if device.get_iface() in getActiveNetDevs():
+            retval.activate = True
+
+    return retval
 
 if __name__ == "__main__":
 
-- 
1.7.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux