* Add in import for notify_messages
[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
59     for type in sysmods:
60         if type == systeminfo.MODULE_CLASS_SCSI:
61             for a_mod in sysmods[type]:
62                 if scsi_count == 0:
63                     modulesconf_file.write( "alias scsi_hostadapter %s\n" %
64                                             a_mod )
65                 else:
66                     modulesconf_file.write( "alias scsi_hostadapter%d %s\n" %
67                                             (scsi_count,a_mod) )
68                 scsi_count= scsi_count + 1
69
70         elif type == systeminfo.MODULE_CLASS_NETWORK:
71             for a_mod in sysmods[type]:
72                 modulesconf_file.write( "alias eth%d %s\n" %
73                                         (eth_count,a_mod) )
74                 eth_count= eth_count + 1
75
76     modulesconf_file.close()
77     modulesconf_file= None
78
79     # dump the modprobe.conf file to the log (not to screen)
80     log.write( "Contents of new modprobe.conf file:\n" )
81     modulesconf_file= file("%s/%s" % (SYSIMG_PATH,filename), "r" )
82     contents= modulesconf_file.read()
83     log.write( contents + "\n" )
84     modulesconf_file.close()
85     modulesconf_file= None
86     log.write( "End contents of new modprobe.conf file.\n" )
87
88     # before we do the real kexec, check to see if we had any
89     # network drivers written to modprobe.conf. if not, return -1,
90     # which will cause this node to be switched to a debug state.
91     if eth_count == 0:
92         log.write( "\nIt appears we don't have any network drivers. Aborting.\n" )
93         
94         vars['BOOT_STATE']= 'dbg'
95         vars['STATE_CHANGE_NOTIFY']= 1
96         vars['STATE_CHANGE_NOTIFY_MESSAGE']= \
97              notify_messages.MSG_NO_DETECTED_NETWORK
98         raise BootManagerException, \
99               notify_messages.MSG_NO_DETECTED_NETWORK
100
101