[PATCH] Bonding support: kickstart

Radek Vykydal rvykydal at redhat.com
Thu Feb 28 15:50:42 UTC 2013


TODO:
- sync dracut and NM naming convention for slaves?
  perhaps better: don't write any ifcfg files for kickstart case
- test with new NM (dhcp on slaves)
---
 dracut/parse-kickstart  | 57 ++++++++++++++++++++++++++++++++++++++-----------
 pyanaconda/kickstart.py |  2 +-
 2 files changed, 45 insertions(+), 14 deletions(-)

diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart
index fcf847a..9337e17 100755
--- a/dracut/parse-kickstart
+++ b/dracut/parse-kickstart
@@ -93,7 +93,7 @@ class DriverDisk(commands.driverdisk.F14_DriverDisk):
         if location:
             return "inst.driverdisk=%s" % location
 
-class Network(commands.network.F16_Network):
+class Network(commands.network.F19_Network):
     def dracut_args(self, args, lineno, net):
         '''
         NOTE: The first 'network' line get special treatment:
@@ -259,7 +259,8 @@ def ksnet_to_ifcfg(net, filename=None):
         dev = find_devname(dev)
     if not dev:
         return
-    if not os.path.isdir("/sys/class/net/%s" % dev):
+    if (not os.path.isdir("/sys/class/net/%s" % dev)
+        and not net.bondslaves):
         log.info("can't find device %s" % dev)
         return
     ifcfg = dict()
@@ -269,8 +270,7 @@ def ksnet_to_ifcfg(net, filename=None):
             os.makedirs("/tmp/ifcfg")
     ifcfg['DEVICE'] = dev
     ifcfg['HWADDR'] = readsysfile("/sys/class/net/%s/address" % dev)
-    if_uuid = str(uuid.uuid4())
-    ifcfg['UUID'] = if_uuid
+    ifcfg['UUID'] = str(uuid.uuid4())
     # we set real ONBOOT value in anaconda, here
     # we use it to activate devcies by NM on start
     ifcfg['ONBOOT'] = "yes" if net.activate else "no"
@@ -313,23 +313,54 @@ def ksnet_to_ifcfg(net, filename=None):
     if net.bootProto == 'dhcp':
         srcpath = "/tmp/dhclient.%s.lease" % dev
         dstdir = "/tmp/ifcfg-leases"
-        dstpath = "%s/dhclient-%s-%s.lease" % (dstdir, if_uuid, dev)
+        dstpath = "%s/dhclient-%s-%s.lease" % (dstdir, ifcfg['UUID'], dev)
         if os.path.exists(srcpath):
             if not os.path.isdir(dstdir):
                 os.makedirs(dstdir)
             shutil.copyfile(srcpath, dstpath)
 
+    if net.bondslaves:
+        ifcfg.pop('HWADDR')
+        ifcfg['TYPE'] = "Bond"
+        ifcfg['BONDING_MASTER'] = "yes"
+        ifcfg['NAME'] = "Bond connection %s" % dev
+        if ';' in net.bondopts:
+            sep = ";"
+        else:
+            sep = ","
+        ifcfg['BONDING_OPTS'] = '"' + " ".join(net.bondopts.split(sep)) + '"'
+
+        for i, slave in enumerate(net.bondslaves.split(","), 1):
+            slave_ifcfg = {
+                            'TYPE' : "Ethernet",
+                            'NAME' : "%s slave %s" % (dev, i),
+                            'UUID' : str(uuid.uuid4()),
+                            'ONBOOT' : "yes",
+                            'MASTER' : dev,
+                            'HWADDR' : readsysfile("/sys/class/net/%s/address" % slave),
+                          }
+            # not using NM naming conventions, following dracut so that it does not
+            # override kickstart config by generating its own ifcfg files for slaves
+            #slave_filename = "/tmp/ifcfg/ifcfg-%s" % "_".join(slave_ifcfg['NAME'].split(" "))
+            # FIXME - change in dracut?
+            slave_filename = "/tmp/ifcfg/ifcfg-%s" % slave
+            log.info("writing ifcfg %s for slave %s of bond %s" % (slave_filename, slave, dev))
+            write_ifcfg(slave_filename, slave_ifcfg)
+
+    log.info("writing ifcfg %s for %s" % (filename, dev))
+    if write_ifcfg(filename, ifcfg):
+        return filename
+
+def write_ifcfg(filename, ifcfg):
     try:
-        log.info("writing ifcfg for %s", dev)
-        outf = open(filename, "w")
-        outf.write('# Generated by parse-kickstart\n')
-        for k,v in ifcfg.items():
-            outf.write("%s=%s\n" % (k,v))
-        outf.close()
+        with open(filename, "w") as f:
+            f.write('# Generated by parse-kickstart\n')
+            for k,v in ifcfg.items():
+                f.write("%s=%s\n" % (k,v))
     except IOError as e:
         log.error("can't write %s: %s" % (filename, str(e)))
-    else:
-        return filename
+        return False
+    return True
 
 def process_kickstart(ksfile):
     handler = DracutHandler()
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 7dcba00..b41d198 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -757,7 +757,7 @@ class Logging(commands.logging.FC6_Logging):
                 remote_server = "%s:%s" %(self.host, self.port)
             logger.updateRemote(remote_server)
 
-class Network(commands.network.F18_Network):
+class Network(commands.network.F19_Network):
     def execute(self, storage, ksdata, instClass):
         network.write_network_config(storage, ksdata, instClass, ROOT_PATH)
 
-- 
1.7.11.7



More information about the anaconda-patches mailing list