[PATCH rhel6-branch] Add network --activate option (#638131)

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

 



So that we can activate more than one network device in installer
environment using kickstart.

Note: I am using flag option instead of option with (yes/no) values
because the point of the option is allowing device activation.
Moreover, we can't guarantee honoring of "no" setting in these two cases:
1) --onboot=yes activates device as side effect when we write out
ifcfg files before packages are downloaded.
2) If there is no active device and network method (repo) is used,
first device in ks will be activated.
---
 isys/isys.py |    2 ++
 kickstart.py |   12 ++++++++++--
 network.py   |   43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/isys/isys.py b/isys/isys.py
index 449ba5c..82ad8d8 100755
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -50,6 +50,8 @@ NM_CONNECTION_IFACE = "org.freedesktop.NetworkManagerSettings.Connection"
 NM_DEVICE_IFACE = "org.freedesktop.NetworkManager.Device"
 NM_IP4CONFIG_IFACE = "org.freedesktop.NetworkManager.IP4Config"
 NM_IP6CONFIG_IFACE = "org.freedesktop.NetworkManager.IP6Config"
+NM_SETTINGS_SERVICE = "org.freedesktop.NetworkManagerSystemSettings"
+NM_SETTINGS_PATH = "/org/freedesktop/NetworkManagerSettings"
 
 NM_STATE_UNKNOWN = 0
 NM_STATE_ASLEEP = 1
diff --git a/kickstart.py b/kickstart.py
index 65f557d..406d4aa 100644
--- a/kickstart.py
+++ b/kickstart.py
@@ -553,7 +553,7 @@ class Logging(commands.logging.FC6_Logging):
         elif self.host != "":
             logger.addSysLogHandler(log, self.host)
 
-class NetworkData(commands.network.F8_NetworkData):
+class NetworkData(commands.network.RHEL6_NetworkData):
     def execute(self, anaconda):
 
         devices = anaconda.id.network.netdevices
@@ -638,6 +638,14 @@ class NetworkData(commands.network.F8_NetworkData):
         if self.gateway != "":
             anaconda.id.network.setGateway(self.gateway, dev.iface)
 
+        if self.activate and dev.iface not in network.getActiveNetDevs():
+            log.info("Activating network device %s in stage2 kickstart ..." %
+                     dev.iface)
+            dev.writeIfcfgFile()
+            rc = (dev.activate()
+                  and len(anaconda.id.network.waitForDevicesActivation([dev.iface])) == 0)
+            log.info("Activation %s" % 'succeeded' if rc else 'failed')
+
         needs_net = (anaconda.methodstr and
                      (anaconda.methodstr.startswith("http:") or
                       anaconda.methodstr.startswith("ftp:") or
@@ -1131,7 +1139,7 @@ dataMap = {
         "VolGroupData": VolGroupData,
 }
 
-superclass = returnClassForVersion()
+superclass = returnClassForVersion(RHEL6)
 
 class AnacondaKSHandler(superclass):
     def __init__ (self, anaconda):
diff --git a/network.py b/network.py
index 3d9d014..ced7d60 100644
--- a/network.py
+++ b/network.py
@@ -317,6 +317,49 @@ class NetworkDevice(IfcfgFile):
                     return True
         return False
 
+    def activate(self):
+
+        bus = dbus.SystemBus()
+        nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
+
+        # get dbus path of connection setting object
+        settings = bus.get_object(isys.NM_SETTINGS_SERVICE,
+                                  isys.NM_SETTINGS_PATH)
+        connection_paths = settings.ListConnections()
+        for con_path in connection_paths:
+            con = bus.get_object(isys.NM_SERVICE, con_path)
+            cs = con.GetSettings()
+            try:
+                mac_bytes = cs[cs['connection']['type']]['mac-address']
+            except KeyError as e:
+                log.info("exception caught: %s" % e)
+            mac_addr = '{0:02X}:{1:02X}:{2:02X}:{3:02X}:{4:02X}:{5:02X}'.format(*mac_bytes)
+            if mac_addr == self.get('HWADDR'):
+                break
+        else:
+            log.info("DBus connection path for device %s not found" % self.iface)
+            return False
+
+        # get dbus path of this device
+        device_object_path = None
+        device_paths = nm.GetDevices()
+        for device_path in device_paths:
+            device = bus.get_object(isys.NM_SERVICE, device_path)
+            device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE)
+            iface = str(device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface"))
+            if iface == self.iface:
+                device_object_path = device_path
+                break
+        else:
+            log.info("DBus object path of device %s not found" % self.iface)
+            return False
+
+        nm.ActivateConnection(isys.NM_SETTINGS_SERVICE,
+                              con_path,
+                              device_path,
+                              dbus.ObjectPath("/"))
+        return True
+
 class Network:
 
     def __init__(self):
-- 
1.7.2

_______________________________________________
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