bd32d28777642cb6c8527a2e62628ec3e4589345
[bootmanager.git] / source / steps / InstallNodeInit.py
1 # Copyright (c) 2003 Intel Corporation
2 # All rights reserved.
3
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7
8 #     * Redistributions of source code must retain the above copyright
9 #       notice, this list of conditions and the following disclaimer.
10
11 #     * Redistributions in binary form must reproduce the above
12 #       copyright notice, this list of conditions and the following
13 #       disclaimer in the documentation and/or other materials provided
14 #       with the distribution.
15
16 #     * Neither the name of the Intel Corporation nor the names of its
17 #       contributors may be used to endorse or promote products derived
18 #       from this software without specific prior written permission.
19
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 # EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
33 # YOUR JURISDICTION. It is licensee's responsibility to comply with any
34 # export regulations applicable in licensee's jurisdiction. Under
35 # CURRENT (May 2000) U.S. export regulations this software is eligible
36 # for export from the U.S. and can be downloaded by or otherwise
37 # exported or reexported worldwide EXCEPT to U.S. embargoed destinations
38 # which include Cuba, Iraq, Libya, North Korea, Iran, Syria, Sudan,
39 # Afghanistan and any other country to which the U.S. has embargoed
40 # goods and services.
41
42
43 from Exceptions import *
44 import utils
45
46
47 def Run( vars, log ):
48     """
49     Initialize the node:
50     - runs planetlabconf
51
52     Except the following variables from the store:
53     SYSIMG_PATH             the path where the system image will be mounted
54     (always starts with TEMP_PATH)
55     NODE_ID                  The db node_id for this machine
56     PLCONF_DIR               The directory to store the configuration file in
57     
58     Sets the following variables:
59     None
60     
61     """
62
63     log.write( "\n\nStep: Install: Final node initialization.\n" )
64
65     # make sure we have the variables we need
66     try:
67         SYSIMG_PATH= vars["SYSIMG_PATH"]
68         if SYSIMG_PATH == "":
69             raise ValueError, "SYSIMG_PATH"
70         
71         NODE_ID= vars["NODE_ID"]
72         if NODE_ID == "":
73             raise ValueError, "NODE_ID"
74
75         PLCONF_DIR= vars["PLCONF_DIR"]
76         if PLCONF_DIR == "":
77             raise ValueError, "PLCONF_DIR"
78         
79     except KeyError, var:
80         raise BootManagerException, "Missing variable in vars: %s\n" % var
81     except ValueError, var:
82         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
83
84
85     log.write( "Running PlanetLabConf to update any configuration files\n" )
86
87     # PlanetLabConf requires /etc/planetlab/node_id, which is normally
88     # maintained in ValidateNodeInstal. so, write out the node_id here
89     # so PlanetLabConf can run.
90     try:
91         node_id_file_path= "%s/%s/node_id" % (SYSIMG_PATH,PLCONF_DIR)
92         node_id_file= file( node_id_file_path, "w" )
93         node_id_file.write( str(NODE_ID) )
94         node_id_file.close()
95         node_id_file= None
96     except IOError, e:
97         raise BootManagerException, \
98                   "Unable to write out /etc/planetlab/node_id for PlanetLabConf"
99
100     if not utils.sysexec( "chroot %s PlanetLabConf.py noscripts" %
101                           SYSIMG_PATH, log ):
102         log.write( "PlanetLabConf failed, install incomplete.\n" )
103         return 0
104                 
105     services= [ "netfs", "rawdevices", "cpuspeed", "smartd" ]
106     for service in services:
107         log.write( "Disabling unneeded service: %s\n" % service )
108         utils.sysexec( "chroot %s chkconfig --level 12345 %s off" %
109                        (SYSIMG_PATH,service), log )
110             
111     return 1