Detangled steps. No step makes calls into another step.
[bootmanager.git] / source / steps / InstallNodeInit.py
1 #!/usr/bin/python2
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 # expected /proc/partitions format
9
10 from Exceptions import *
11 import utils
12 import os
13
14
15 def Run( vars, log ):
16     """
17     Initialize the node:
18     - runs planetlabconf
19
20     Except the following variables from the store:
21     SYSIMG_PATH             the path where the system image will be mounted
22     (always starts with TEMP_PATH)
23     NODE_ID                  The db node_id for this machine
24     PLCONF_DIR               The directory to store the configuration file in
25     
26     Sets the following variables:
27     None
28     
29     """
30
31     log.write( "\n\nStep: Install: Final node initialization.\n" )
32
33     # make sure we have the variables we need
34     try:
35         SYSIMG_PATH= vars["SYSIMG_PATH"]
36         if SYSIMG_PATH == "":
37             raise ValueError, "SYSIMG_PATH"
38         
39         NODE_ID= vars["NODE_ID"]
40         if NODE_ID == "":
41             raise ValueError, "NODE_ID"
42
43         PLCONF_DIR= vars["PLCONF_DIR"]
44         if PLCONF_DIR == "":
45             raise ValueError, "PLCONF_DIR"
46         
47     except KeyError, var:
48         raise BootManagerException, "Missing variable in vars: %s\n" % var
49     except ValueError, var:
50         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
51
52
53     log.write( "Running PlanetLabConf to update any configuration files\n" )
54
55     # PlanetLabConf requires /etc/planetlab/node_id, which is normally
56     # maintained in ValidateNodeInstal. so, write out the node_id here
57     # so PlanetLabConf can run.
58     try:
59         node_id_file_path= "%s/%s/node_id" % (SYSIMG_PATH,PLCONF_DIR)
60         node_id_file= file( node_id_file_path, "w" )
61         node_id_file.write( str(NODE_ID) )
62         node_id_file.close()
63         node_id_file= None
64     except IOError, e:
65         raise BootManagerException, \
66                   "Unable to write out /etc/planetlab/node_id for PlanetLabConf"
67
68     if not utils.sysexec( "chroot %s PlanetLabConf.py noscripts" %
69                           SYSIMG_PATH, log ):
70         log.write( "PlanetLabConf failed, install incomplete.\n" )
71         return 0
72                 
73     services= [ "netfs", "rawdevices", "cpuspeed", "smartd" ]
74     for service in services:
75         if os.path.exists("%s/etc/init.d/%s" % (SYSIMG_PATH,service)):
76             log.write( "Disabling unneeded service: %s\n" % service )
77             utils.sysexec( "chroot %s chkconfig --level 12345 %s off" %
78                            (SYSIMG_PATH,service), log )
79             
80     return 1