3 # Copyright (c) 2003 Intel Corporation
6 # Copyright (c) 2004-2007 The Trustees of Princeton University
8 # expected /proc/partitions format
10 import os, sys, string
15 from Exceptions import *
17 import BootServerRequest
23 Download enough files to run rpm and yum from a chroot in
24 the system image directory
26 Expect the following variables from the store:
27 SYSIMG_PATH the path where the system image will be mounted
28 PARTITIONS dictionary of generic part. types (root/swap)
29 and their associated devices.
30 SUPPORT_FILE_DIR directory on the boot servers containing
31 scripts and support files
32 NODE_ID the id of this machine
34 Sets the following variables:
35 TEMP_BOOTCD_PATH where the boot cd is remounted in the temp
37 ROOT_MOUNTED set to 1 when the the base logical volumes
41 log.write( "\n\nStep: Install: bootstrapfs tarball.\n" )
43 # make sure we have the variables we need
45 SYSIMG_PATH= vars["SYSIMG_PATH"]
47 raise ValueError, "SYSIMG_PATH"
49 PARTITIONS= vars["PARTITIONS"]
50 if PARTITIONS == None:
51 raise ValueError, "PARTITIONS"
53 SUPPORT_FILE_DIR= vars["SUPPORT_FILE_DIR"]
54 if SUPPORT_FILE_DIR == None:
55 raise ValueError, "SUPPORT_FILE_DIR"
57 NODE_ID= vars["NODE_ID"]
59 raise ValueError, "NODE_ID"
62 raise BootManagerException, "Missing variable in vars: %s\n" % var
63 except ValueError, var:
64 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
68 # make sure the required partitions exist
69 val= PARTITIONS["root"]
70 val= PARTITIONS["swap"]
71 val= PARTITIONS["vservers"]
72 except KeyError, part:
73 log.write( "Missing partition in PARTITIONS: %s\n" % part )
76 bs_request= BootServerRequest.BootServerRequest(vars)
78 log.write( "turning on swap space\n" )
79 utils.sysexec( "swapon %s" % PARTITIONS["swap"], log )
81 # make sure the sysimg dir is present
82 utils.makedirs( SYSIMG_PATH )
84 log.write( "mounting root file system\n" )
85 utils.sysexec( "mount -t ext3 %s %s" % (PARTITIONS["root"],SYSIMG_PATH), log )
87 log.write( "mounting vserver partition in root file system\n" )
88 utils.makedirs( SYSIMG_PATH + "/vservers" )
89 utils.sysexec( "mount -t ext3 %s %s/vservers" % (PARTITIONS["vservers"],
92 vars['ROOT_MOUNTED']= 1
94 # which extensions are we part of ?
95 utils.breakpoint("Checking for the extension(s) tags")
98 extension_tag = BootAPI.call_api_function(vars, "GetNodeExtensions", (NODE_ID,) )
100 extensions = extension_tag.split()
103 log.write("WARNING : Failed to query tag 'extensions'\n")
104 log.write(traceback.format_exc())
107 log.write("installing only core software\n")
109 # check if the plain-bootstrapfs tag is set
110 download_suffix=".tar.bz2"
113 if BootAPI.call_api_function (vars, "GetNodePlainBootstrapfs", (NODE_ID,) ):
114 download_suffix=".tar"
117 log.write("WARNING : Failed to query tag 'plain-bootstrapfs'\n")
118 log.write(traceback.format_exc())
121 log.write("Using uncompressed bootstrapfs images\n")
123 # see also GetBootMedium in PLCAPI that does similar things
124 # figuring the default node family:
125 # (1) get node's tags 'arch' and 'pldistro'
126 # (2) if unsuccessful search /etc/planetlab/nodefamily on the bootcd
127 # (3) if that fails, set to planetlab-i386
130 api_pldistro = BootAPI.call_api_function(vars, "GetNodePldistro", (NODE_ID,) )
132 log.write("WARNING : Failed to query tag 'pldistro'\n")
135 api_arch = BootAPI.call_api_function(vars, "GetNodeArch", (NODE_ID,) )
137 log.write("WARNING : Failed to query tag 'arch'\n")
140 (etc_pldistro,etc_arch) = file("/etc/planetlab/nodefamily").read().strip().split("-")
142 log.write("WARNING : Failed to parse /etc/planetlab/nodefamily\n")
143 (etc_pldistro,etc_arch)=(None,None)
144 default_pldistro="planetlab"
148 pldistro = api_pldistro
149 log.write ("Using pldistro from pldistro API tag\n")
151 pldistro = etc_pldistro
152 log.write ("Using pldistro from /etc/planetlab/nodefamily\n")
154 pldistro = default_pldistro
155 log.write ("Using default pldistro\n")
159 log.write ("Using arch from arch API tag\n")
162 log.write ("Using arch from /etc/planetlab/nodefamily\n")
165 log.write ("Using default arch\n")
167 log.write ("Using nodefamily=%s-%s\n"%(pldistro,arch))
169 bootstrapfs_names = [ pldistro ] + extensions
171 # download and extract support tarball for this step, which has
172 # everything we need to successfully run
174 # we first try to find a tarball, if it is not found we use yum instead
176 # download and extract support tarball for this step,
177 for bootstrapfs_name in bootstrapfs_names:
178 tarball = "bootstrapfs-%s-%s%s"%(bootstrapfs_name,arch,download_suffix)
179 source_file= "%s/%s" % (SUPPORT_FILE_DIR,tarball)
180 dest_file= "%s/%s" % (SYSIMG_PATH, tarball)
182 # 30 is the connect timeout, 14400 is the max transfer time in
184 log.write( "downloading %s\n" % source_file )
185 result= bs_request.DownloadFile( source_file, None, None,
189 log.write( "extracting %s in %s\n" % (dest_file,SYSIMG_PATH) )
190 result= utils.sysexec( "tar -C %s -xpf %s %s" % (SYSIMG_PATH,dest_file,untar_option), log )
192 utils.removefile( dest_file )
194 # the main tarball is required
195 if bootstrapfs_name == pldistro:
196 raise BootManagerException, "Unable to download main tarball %s from server." % \
199 log.write("tarball for %s-%s not found, scheduling a yum attempt\n"%(bootstrapfs_name,arch))
200 yum_extensions.append(bootstrapfs_name)
202 # copy resolv.conf from the base system into our temp dir
203 # so DNS lookups work correctly while we are chrooted
204 log.write( "Copying resolv.conf to temp dir\n" )
205 utils.sysexec( "cp /etc/resolv.conf %s/etc/" % SYSIMG_PATH, log )
207 # Copy the boot server certificate(s) and GPG public key to
208 # /usr/boot in the temp dir.
209 log.write( "Copying boot server certificates and public key\n" )
211 if os.path.exists("/usr/boot"):
212 utils.makedirs(SYSIMG_PATH + "/usr")
213 shutil.copytree("/usr/boot", SYSIMG_PATH + "/usr/boot")
214 elif os.path.exists("/usr/bootme"):
215 utils.makedirs(SYSIMG_PATH + "/usr/boot")
216 boot_server = file("/usr/bootme/BOOTSERVER").readline().strip()
217 shutil.copy("/usr/bootme/cacert/" + boot_server + "/cacert.pem",
218 SYSIMG_PATH + "/usr/boot/cacert.pem")
219 file(SYSIMG_PATH + "/usr/boot/boot_server", "w").write(boot_server)
220 shutil.copy("/usr/bootme/pubring.gpg", SYSIMG_PATH + "/usr/boot/pubring.gpg")
222 # For backward compatibility
223 if os.path.exists("/usr/bootme"):
224 utils.makedirs(SYSIMG_PATH + "/mnt/cdrom")
225 shutil.copytree("/usr/bootme", SYSIMG_PATH + "/mnt/cdrom/bootme")
227 # Import the GPG key into the RPM database so that RPMS can be verified
228 utils.makedirs(SYSIMG_PATH + "/etc/pki/rpm-gpg")
229 utils.sysexec("gpg --homedir=/root --export --armor" \
230 " --no-default-keyring --keyring %s/usr/boot/pubring.gpg" \
231 " >%s/etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab" % (SYSIMG_PATH, SYSIMG_PATH))
232 utils.sysexec_chroot(SYSIMG_PATH, "rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab")
234 # the yum config has changed entirely;
235 # in addition yum installs have more or less never worked - let's forget about this
236 # maybe NodeManager could profitably do the job instead
238 log.write("WARNING : yum installs for node extensions are not supported anymore\n")