Updated to use modprobe module to update an existing /etc/modprobe.conf file rather...
authorMarc Fiuczynski <mef@cs.princeton.edu>
Tue, 24 Feb 2009 21:40:57 +0000 (21:40 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Tue, 24 Feb 2009 21:40:57 +0000 (21:40 +0000)
source/steps/WriteModprobeConfig.py

index a9b0d2a..bb8cb2f 100644 (file)
@@ -14,6 +14,7 @@ import systeminfo
 import BootAPI
 import ModelOptions
 import notify_messages
+import modprobe
 
 def Run( vars, log, filename = "/etc/modprobe.conf"):
     """
@@ -51,27 +52,28 @@ def Run( vars, log, filename = "/etc/modprobe.conf"):
     if sysmods is None:
         raise BootManagerException, "Unable to get list of system modules."
         
-    eth_count= 0
-    scsi_count= 0
-
-    modulesconf_file= file("%s/%s" % (SYSIMG_PATH,filename), "w" )
-    modulesconf_file.write("options ata_generic all_generic_ide=1\n")
-
-    for type in sysmods:
-        if type == systeminfo.MODULE_CLASS_SCSI:
-            for a_mod in sysmods[type]:
-                modulesconf_file.write( "alias scsi_hostadapter%d %s\n" %
-                                        (scsi_count,a_mod) )
-                scsi_count= scsi_count + 1
+    # parse the existing modprobe.conf file, if one exists
+    mfile = "%s/%s" % (SYSIMG_PATH,filename)
+    m = modprobe.Modprobe(mfile)
+    try:
+        m.input(mfile)
+    except:
+        pass
 
-        elif type == systeminfo.MODULE_CLASS_NETWORK:
-            for a_mod in sysmods[type]:
-                modulesconf_file.write( "alias eth%d %s\n" %
-                                        (eth_count,a_mod) )
-                eth_count= eth_count + 1
+    # storage devices
+    m.optionsset("ata_generic","all_generic_ide=1")
+    scsi_count= 0
+    for a_mod in sysmods[systeminfo.MODULE_CLASS_SCSI]:
+        m.aliasset("scsi_hostadapter%d"%scsi_count,a_mod)
+        scsi_count= scsi_count + 1
 
-    modulesconf_file.close()
-    modulesconf_file= None
+    # network devices
+    eth_count= 0
+    for a_mod in sysmods[systeminfo.MODULE_CLASS_NETWORK]:
+        m.aliasset("eth%d"%eth_count,a_mod)
+        eth_count= eth_count + 1
+    m.output(mfile, "BootManager")
+    m.output("%s.bak"%mfile, "BootManager") # write a backup version of this file
 
     # dump the modprobe.conf file to the log (not to screen)
     log.write( "Contents of new modprobe.conf file:\n" )