2 Various functions that are used to allow the boot manager to run on various
3 different cds are included here
9 from Exceptions import *
11 import BootServerRequest
14 def setup_lvm_2x_cd( vars, log ):
16 make available a set of lvm utilities for 2.x cds that don't have them
19 Expect the following variables to be set:
20 TEMP_PATH somewhere to store what we need to run
21 BOOT_CD_VERSION A tuple of the current bootcd version
22 SUPPORT_FILE_DIR directory on the boot servers containing
23 scripts and support files
24 LVM_SETUP_2X_CD indicates if lvm is downloaded and setup for 2.x cds
26 Set the following variables upon successfully running:
27 LVM_SETUP_2X_CD indicates if lvm is downloaded and setup for 2.x cds
30 # make sure we have the variables we need
32 TEMP_PATH= vars["TEMP_PATH"]
34 raise ValueError, "TEMP_PATH"
36 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
37 if BOOT_CD_VERSION == "":
38 raise ValueError, "BOOT_CD_VERSION"
40 SUPPORT_FILE_DIR= vars["SUPPORT_FILE_DIR"]
41 if SUPPORT_FILE_DIR == None:
42 raise ValueError, "SUPPORT_FILE_DIR"
45 raise BootManagerException, "Missing variable in vars: %s\n" % var
46 except ValueError, var:
47 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
50 if BOOT_CD_VERSION[0] != 2:
51 log.write( "Only 2.x boot cds need lvm setup manually.\n" )
55 if 'LVM_SETUP_2X_CD' in vars.keys():
56 LVM_SETUP_2X_CD= vars['LVM_SETUP_2X_CD']
59 log.write( "LVM already downloaded and setup\n" )
62 log.write( "Downloading additional libraries for lvm\n" )
64 bs_request= BootServerRequest.BootServerRequest()
66 utils.makedirs(TEMP_PATH)
68 # download and extract support tarball for this step,
69 # which has everything we need to successfully run
70 step_support_file= "alpina-BootLVM.tar.gz"
71 source_file= "%s/%s" % (SUPPORT_FILE_DIR,step_support_file)
72 dest_file= "%s/%s" % (TEMP_PATH, step_support_file)
74 log.write( "Downloading support file for this step\n" )
75 result= bs_request.DownloadFile( source_file, None, None,
78 raise BootManagerException, "Download failed."
80 log.write( "Extracting support files\n" )
82 utils.chdir( TEMP_PATH )
83 utils.sysexec( "tar -C / -xzf %s" % step_support_file, log )
84 utils.removefile( dest_file )
87 utils.sysexec( "ldconfig", log )
90 log.write( "Loading lvm module\n" )
91 utils.sysexec( "modprobe lvm-mod", log )
93 # take note that we have lvm setup
95 vars['LVM_SETUP_2X_CD']= LVM_SETUP_2X_CD
101 def setup_partdisks_2x_cd( vars, log ):
103 download necessary files to handle partitioning disks on 2.x cds
105 Expect the following variables to be set:
106 TEMP_PATH somewhere to store what we need to run
107 BOOT_CD_VERSION A tuple of the current bootcd version
108 SUPPORT_FILE_DIR directory on the boot servers containing
109 scripts and support files
110 PARTDISKS_SETUP_2X_CD indicates if lvm is downloaded and setup for 2.x cds
112 Set the following variables upon successfully running:
113 PARTDISKS_SETUP_2X_CD indicates if lvm is downloaded and setup for 2.x cds
116 # make sure we have the variables we need
118 TEMP_PATH= vars["TEMP_PATH"]
120 raise ValueError, "TEMP_PATH"
122 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
123 if BOOT_CD_VERSION == "":
124 raise ValueError, "BOOT_CD_VERSION"
126 SUPPORT_FILE_DIR= vars["SUPPORT_FILE_DIR"]
127 if SUPPORT_FILE_DIR == None:
128 raise ValueError, "SUPPORT_FILE_DIR"
130 except KeyError, var:
131 raise BootManagerException, "Missing variable in vars: %s\n" % var
132 except ValueError, var:
133 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
136 if BOOT_CD_VERSION[0] != 2:
137 log.write( "Only 2.x boot cds need partition disk tools setup manually.\n" )
140 PARTDISKS_SETUP_2X_CD= 0
141 if 'PARTDISKS_SETUP_2X_CD' in vars.keys():
142 PARTDISKS_SETUP_2X_CD= vars['PARTDISKS_SETUP_2X_CD']
144 if PARTDISKS_SETUP_2X_CD:
145 log.write( "Partition disk tools already downloaded and setup\n" )
148 log.write( "Downloading additional libraries for partitioning disks\n" )
150 bs_request= BootServerRequest.BootServerRequest()
152 # download and extract support tarball for this step,
153 # which has everything we need to successfully run
154 step_support_file= "alpina-PartDisks.tar.gz"
155 source_file= "%s/%s" % (SUPPORT_FILE_DIR,step_support_file)
156 dest_file= "%s/%s" % (TEMP_PATH, step_support_file)
158 log.write( "Downloading support file for this step\n" )
159 result= bs_request.DownloadFile( source_file, None, None,
162 raise BootManagerException, "Download failed."
164 log.write( "Extracting support files\n" )
166 utils.chdir( TEMP_PATH )
167 utils.sysexec( "tar -xzf %s" % step_support_file, log )
168 utils.removefile( dest_file )
169 utils.chdir( old_wd )
171 # also included in the support package was a list of extra
172 # paths (lib-paths) for /etc/ld.so.conf.
173 # so add those, and rerun ldconfig
174 # so we can make our newly downloaded libraries available
176 ldconf_file= file("/etc/ld.so.conf","a+")
177 lib_paths_file= file( TEMP_PATH + "/lib-paths","r")
179 for line in lib_paths_file:
180 path= string.strip(line)
182 ldconf_file.write( "%s/%s\n" % (TEMP_PATH,path) )
184 lib_paths_file.close()
186 utils.sysexec( "ldconfig", log )
188 # update the PYTHONPATH to include the python modules in
189 # the support package
190 sys.path.append( TEMP_PATH + "/usr/lib/python2.2" )
191 sys.path.append( TEMP_PATH + "/usr/lib/python2.2/site-packages" )
193 # update the environment variable PATH to include
194 # TEMP_PATH/sbin and others there
195 new_paths= ('%s/sbin'% TEMP_PATH,
197 '%s/user/sbin'% TEMP_PATH,
198 '%s/user/bin'% TEMP_PATH)
200 old_path= os.environ['PATH']
201 os.environ['PATH']= old_path + ":" + string.join(new_paths,":")
203 # everything should be setup to import parted. this
204 # import is just to make sure it'll work when this step
206 log.write( "Imported parted\n" )
210 raise BootManagerException, "Unable to import parted."
212 # take note that we have part disks setup
213 PARTDISKS_SETUP_2X_CD= 1
214 vars['PARTDISKS_SETUP_2X_CD']= PARTDISKS_SETUP_2X_CD