Use scsi_hostadapterX for the first one too.
[bootmanager.git] / source / steps / WriteModprobeConfig.py
1 #!/usr/bin/python2 -u
2
3 # Copyright (c) 2003 Intel Corporation
4 # All rights reserved.
5 #
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
7 # All rights reserved.
8
9 import os, string
10
11 from Exceptions import *
12 import utils
13 import systeminfo
14 import BootAPI
15 import ModelOptions
16 import notify_messages
17
18 def Run( vars, log, filename = "/etc/modprobe.conf"):
19     """
20     write out the system file /etc/modprobe.conf with the current
21     set of modules.
22
23     returns a tuple of the number of network driver lines and storage
24     driver lines written as (networkcount,storagecount)
25     """
26
27     # write out the modprobe.conf file for the system. make sure
28     # the order of the ethernet devices are listed in the same order
29     # as the boot cd loaded the modules. this is found in /tmp/loadedmodules
30     # ultimately, the order will only match the boot cd order if
31     # the kernel modules have the same name - which should be true for the later
32     # version boot cds because they use the same kernel version.
33     # older boot cds use a 2.4.19 kernel, and its possible some of the network
34     # module names have changed, in which case the system might not boot
35     # if the network modules are activated in a different order that the
36     # boot cd.
37
38     # make sure we have this class loaded
39     
40     try:
41         SYSIMG_PATH= vars["SYSIMG_PATH"]
42         if SYSIMG_PATH == "":
43             raise ValueError, "SYSIMG_PATH"
44
45     except KeyError, var:
46         raise BootManagerException, "Missing variable in vars: %s\n" % var
47     except ValueError, var:
48         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
49
50     sysmods= systeminfo.get_system_modules(vars, log)
51     if sysmods is None:
52         raise BootManagerException, "Unable to get list of system modules."
53         
54     eth_count= 0
55     scsi_count= 0
56
57     modulesconf_file= file("%s/%s" % (SYSIMG_PATH,filename), "w" )
58     modulesconf_file.write("options ata_generic all_generic_ide=1\n")
59
60     for type in sysmods:
61         if type == systeminfo.MODULE_CLASS_SCSI:
62             for a_mod in sysmods[type]:
63                 modulesconf_file.write( "alias scsi_hostadapter%d %s\n" %
64                                         (scsi_count,a_mod) )
65                 scsi_count= scsi_count + 1
66
67         elif type == systeminfo.MODULE_CLASS_NETWORK:
68             for a_mod in sysmods[type]:
69                 modulesconf_file.write( "alias eth%d %s\n" %
70                                         (eth_count,a_mod) )
71                 eth_count= eth_count + 1
72
73     modulesconf_file.close()
74     modulesconf_file= None
75
76     # dump the modprobe.conf file to the log (not to screen)
77     log.write( "Contents of new modprobe.conf file:\n" )
78     modulesconf_file= file("%s/%s" % (SYSIMG_PATH,filename), "r" )
79     contents= modulesconf_file.read()
80     log.write( contents + "\n" )
81     modulesconf_file.close()
82     modulesconf_file= None
83     log.write( "End contents of new modprobe.conf file.\n" )
84
85     # before we do the real kexec, check to see if we had any
86     # network drivers written to modprobe.conf. if not, return -1,
87     # which will cause this node to be switched to a debug state.
88     if eth_count == 0:
89         log.write( "\nIt appears we don't have any network drivers. Aborting.\n" )
90         
91         vars['BOOT_STATE']= 'dbg'
92         vars['STATE_CHANGE_NOTIFY']= 1
93         vars['STATE_CHANGE_NOTIFY_MESSAGE']= \
94              notify_messages.MSG_NO_DETECTED_NETWORK
95         raise BootManagerException, \
96               notify_messages.MSG_NO_DETECTED_NETWORK
97
98