3 # Copyright (c) 2003 Intel Corporation
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
11 Various functions that are used to allow the boot manager to run on various
12 different cds are included here
18 from Exceptions import *
20 import BootServerRequest
23 def setup_lvm_2x_cd( vars, log ):
25 make available a set of lvm utilities for 2.x cds that don't have them
28 Expect the following variables to be set:
29 TEMP_PATH somewhere to store what we need to run
30 BOOT_CD_VERSION A tuple of the current bootcd version
31 SUPPORT_FILE_DIR directory on the boot servers containing
32 scripts and support files
33 LVM_SETUP_2X_CD indicates if lvm is downloaded and setup for 2.x cds
35 Set the following variables upon successfully running:
36 LVM_SETUP_2X_CD indicates if lvm is downloaded and setup for 2.x cds
39 # make sure we have the variables we need
41 TEMP_PATH= vars["TEMP_PATH"]
43 raise ValueError, "TEMP_PATH"
45 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
46 if BOOT_CD_VERSION == "":
47 raise ValueError, "BOOT_CD_VERSION"
49 SUPPORT_FILE_DIR= vars["SUPPORT_FILE_DIR"]
50 if SUPPORT_FILE_DIR == None:
51 raise ValueError, "SUPPORT_FILE_DIR"
54 raise BootManagerException, "Missing variable in vars: %s\n" % var
55 except ValueError, var:
56 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
59 if BOOT_CD_VERSION[0] != 2:
60 log.write( "Only 2.x boot cds need lvm setup manually.\n" )
64 if 'LVM_SETUP_2X_CD' in vars.keys():
65 LVM_SETUP_2X_CD= vars['LVM_SETUP_2X_CD']
68 log.write( "LVM already downloaded and setup\n" )
71 log.write( "Downloading additional libraries for lvm\n" )
73 bs_request= BootServerRequest.BootServerRequest()
75 utils.makedirs(TEMP_PATH)
77 # download and extract support tarball for this step,
78 # which has everything we need to successfully run
79 step_support_file= "alpina-BootLVM.tar.gz"
80 source_file= "%s/%s" % (SUPPORT_FILE_DIR,step_support_file)
81 dest_file= "%s/%s" % (TEMP_PATH, step_support_file)
83 log.write( "Downloading support file for this step\n" )
84 result= bs_request.DownloadFile( source_file, None, None,
87 raise BootManagerException, "Download failed."
89 log.write( "Extracting support files\n" )
91 utils.chdir( TEMP_PATH )
92 utils.sysexec( "tar -C / -xzf %s" % step_support_file, log )
93 utils.removefile( dest_file )
96 utils.sysexec( "ldconfig", log )
99 log.write( "Loading lvm module\n" )
100 utils.sysexec( "modprobe lvm-mod", log )
102 # take note that we have lvm setup
104 vars['LVM_SETUP_2X_CD']= LVM_SETUP_2X_CD
110 def setup_partdisks_2x_cd( vars, log ):
112 download necessary files to handle partitioning disks on 2.x cds
114 Expect the following variables to be set:
115 TEMP_PATH somewhere to store what we need to run
116 BOOT_CD_VERSION A tuple of the current bootcd version
117 SUPPORT_FILE_DIR directory on the boot servers containing
118 scripts and support files
119 PARTDISKS_SETUP_2X_CD indicates if lvm is downloaded and setup for 2.x cds
121 Set the following variables upon successfully running:
122 PARTDISKS_SETUP_2X_CD indicates if lvm is downloaded and setup for 2.x cds
125 # make sure we have the variables we need
127 TEMP_PATH= vars["TEMP_PATH"]
129 raise ValueError, "TEMP_PATH"
131 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
132 if BOOT_CD_VERSION == "":
133 raise ValueError, "BOOT_CD_VERSION"
135 SUPPORT_FILE_DIR= vars["SUPPORT_FILE_DIR"]
136 if SUPPORT_FILE_DIR == None:
137 raise ValueError, "SUPPORT_FILE_DIR"
139 except KeyError, var:
140 raise BootManagerException, "Missing variable in vars: %s\n" % var
141 except ValueError, var:
142 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
145 if BOOT_CD_VERSION[0] != 2:
146 log.write( "Only 2.x boot cds need partition disk tools setup manually.\n" )
149 PARTDISKS_SETUP_2X_CD= 0
150 if 'PARTDISKS_SETUP_2X_CD' in vars.keys():
151 PARTDISKS_SETUP_2X_CD= vars['PARTDISKS_SETUP_2X_CD']
153 if PARTDISKS_SETUP_2X_CD:
154 log.write( "Partition disk tools already downloaded and setup\n" )
157 log.write( "Downloading additional libraries for partitioning disks\n" )
159 bs_request= BootServerRequest.BootServerRequest()
161 # download and extract support tarball for this step,
162 # which has everything we need to successfully run
163 step_support_file= "alpina-PartDisks.tar.gz"
164 source_file= "%s/%s" % (SUPPORT_FILE_DIR,step_support_file)
165 dest_file= "%s/%s" % (TEMP_PATH, step_support_file)
167 log.write( "Downloading support file for this step\n" )
168 result= bs_request.DownloadFile( source_file, None, None,
171 raise BootManagerException, "Download failed."
173 log.write( "Extracting support files\n" )
175 utils.chdir( TEMP_PATH )
176 utils.sysexec( "tar -xzf %s" % step_support_file, log )
177 utils.removefile( dest_file )
178 utils.chdir( old_wd )
180 # also included in the support package was a list of extra
181 # paths (lib-paths) for /etc/ld.so.conf.
182 # so add those, and rerun ldconfig
183 # so we can make our newly downloaded libraries available
185 ldconf_file= file("/etc/ld.so.conf","a+")
186 lib_paths_file= file( TEMP_PATH + "/lib-paths","r")
188 for line in lib_paths_file:
189 path= string.strip(line)
191 ldconf_file.write( "%s/%s\n" % (TEMP_PATH,path) )
193 lib_paths_file.close()
195 utils.sysexec( "ldconfig", log )
197 # update the PYTHONPATH to include the python modules in
198 # the support package
199 sys.path.append( TEMP_PATH + "/usr/lib/python2.2" )
200 sys.path.append( TEMP_PATH + "/usr/lib/python2.2/site-packages" )
202 # update the environment variable PATH to include
203 # TEMP_PATH/sbin and others there
204 new_paths= ('%s/sbin'% TEMP_PATH,
206 '%s/user/sbin'% TEMP_PATH,
207 '%s/user/bin'% TEMP_PATH)
209 old_path= os.environ['PATH']
210 os.environ['PATH']= old_path + ":" + string.join(new_paths,":")
212 # everything should be setup to import parted. this
213 # import is just to make sure it'll work when this step
215 log.write( "Imported parted\n" )
219 raise BootManagerException, "Unable to import parted."
221 # take note that we have part disks setup
222 PARTDISKS_SETUP_2X_CD= 1
223 vars['PARTDISKS_SETUP_2X_CD']= PARTDISKS_SETUP_2X_CD