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 NODE_ID the id of this machine
32 Sets the following variables:
33 TEMP_BOOTCD_PATH where the boot cd is remounted in the temp
35 ROOT_MOUNTED set to 1 when the the base logical volumes
39 log.write( "\n\nStep: Install: bootstrapfs tarball.\n" )
41 # make sure we have the variables we need
43 SYSIMG_PATH= vars["SYSIMG_PATH"]
45 raise ValueError, "SYSIMG_PATH"
47 PARTITIONS= vars["PARTITIONS"]
48 if PARTITIONS == None:
49 raise ValueError, "PARTITIONS"
51 NODE_ID= vars["NODE_ID"]
53 raise ValueError, "NODE_ID"
56 raise BootManagerException, "Missing variable in vars: %s\n" % var
57 except ValueError, var:
58 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
62 # make sure the required partitions exist
63 val= PARTITIONS["root"]
64 val= PARTITIONS["swap"]
65 val= PARTITIONS["vservers"]
66 except KeyError, part:
67 log.write( "Missing partition in PARTITIONS: %s\n" % part )
70 bs_request= BootServerRequest.BootServerRequest(vars)
72 log.write( "turning on swap space\n" )
73 utils.sysexec( "swapon %s" % PARTITIONS["swap"], log )
75 # make sure the sysimg dir is present
76 utils.makedirs( SYSIMG_PATH )
78 log.write( "mounting root file system\n" )
79 utils.sysexec( "mount -t ext3 %s %s" % (PARTITIONS["root"],SYSIMG_PATH), log )
81 log.write( "mounting vserver partition in root file system\n" )
82 utils.makedirs( SYSIMG_PATH + "/vservers" )
83 utils.sysexec( "mount -t ext3 %s %s/vservers" % (PARTITIONS["vservers"],
86 vars['ROOT_MOUNTED']= 1
88 # fetch deployment tag (like, 'alpha' or the like)
90 deployment = BootAPI.call_api_function(vars, "GetNodeDeployment", (NODE_ID,) )
92 log.write("WARNING : Failed to query tag 'deployment'\n")
95 # which extensions are we part of ?
96 utils.breakpoint("Checking for the extension(s) tags")
99 extension_tag = BootAPI.call_api_function(vars, "GetNodeExtensions", (NODE_ID,) )
101 extensions = extension_tag.split()
104 log.write("WARNING : Failed to query tag 'extensions'\n")
105 log.write(traceback.format_exc())
108 log.write("installing only core software\n")
110 # check if the plain-bootstrapfs tag is set
111 download_suffix=".tar.bz2"
114 if BootAPI.call_api_function (vars, "GetNodePlainBootstrapfs", (NODE_ID,) ):
115 download_suffix=".tar"
118 log.write("WARNING : Failed to query tag 'plain-bootstrapfs'\n")
119 log.write(traceback.format_exc())
122 log.write("Using uncompressed bootstrapfs images\n")
124 # see also GetBootMedium in PLCAPI that does similar things
125 # figuring the default node family:
126 # (1) get node's tags 'arch' and 'pldistro'
127 # (2) if unsuccessful search /etc/planetlab/nodefamily on the bootcd
128 # (3) if that fails, set to planetlab-i386
131 api_pldistro = BootAPI.call_api_function(vars, "GetNodePldistro", (NODE_ID,) )
133 log.write("WARNING : Failed to query tag 'pldistro'\n")
136 api_arch = BootAPI.call_api_function(vars, "GetNodeArch", (NODE_ID,) )
138 log.write("WARNING : Failed to query tag 'arch'\n")
141 (etc_pldistro,etc_arch) = file("/etc/planetlab/nodefamily").read().strip().split("-")
143 log.write("WARNING : Failed to parse /etc/planetlab/nodefamily\n")
144 (etc_pldistro,etc_arch)=(None,None)
145 default_pldistro="planetlab"
149 pldistro = api_pldistro
150 log.write ("Using pldistro from pldistro API tag\n")
152 pldistro = etc_pldistro
153 log.write ("Using pldistro from /etc/planetlab/nodefamily\n")
155 pldistro = default_pldistro
156 log.write ("Using default pldistro\n")
160 log.write ("Using arch from arch API tag\n")
163 log.write ("Using arch from /etc/planetlab/nodefamily\n")
166 log.write ("Using default arch\n")
168 log.write ("Using nodefamily=%s-%s\n"%(pldistro,arch))
170 # deployment is enough, let operators put what they want in there
172 bootstrapfs_names = [ deployment ]
174 bootstrapfs_names = [ "%s-%s"%(x,arch) for x in [ pldistro ] + extensions ]
176 # download and extract support tarball for this step, which has
177 # everything we need to successfully run
179 # installing extensions through yum has been dismantled
181 # download and extract support tarball for this step,
182 for name in bootstrapfs_names:
183 tarball = "bootstrapfs-%s%s"%(name,download_suffix)
184 source_file= "/boot/%s" % (SUPPORT_FILE_DIR,tarball)
185 dest_file= "%s/%s" % (SYSIMG_PATH, tarball)
187 # 30 is the connect timeout, 14400 is the max transfer time in
189 log.write( "downloading %s\n" % source_file )
190 result= bs_request.DownloadFile( source_file, None, None,
194 log.write( "extracting %s in %s\n" % (dest_file,SYSIMG_PATH) )
195 result= utils.sysexec( "tar -C %s -xpf %s %s" % (SYSIMG_PATH,dest_file,untar_option), log )
197 utils.removefile( dest_file )
199 # the main tarball is required
200 if name == "%s-%s"%(pldistro,arch):
201 raise BootManagerException, "Unable to download main tarball %s from server." % \
204 log.write("tarball for %s not found, scheduling a yum attempt\n"%(name))
205 yum_extensions.append(name)
207 # copy resolv.conf from the base system into our temp dir
208 # so DNS lookups work correctly while we are chrooted
209 log.write( "Copying resolv.conf to temp dir\n" )
210 utils.sysexec( "cp /etc/resolv.conf %s/etc/" % SYSIMG_PATH, log )
212 # Copy the boot server certificate(s) and GPG public key to
213 # /usr/boot in the temp dir.
214 log.write( "Copying boot server certificates and public key\n" )
216 if os.path.exists("/usr/boot"):
217 utils.makedirs(SYSIMG_PATH + "/usr")
218 shutil.copytree("/usr/boot", SYSIMG_PATH + "/usr/boot")
219 elif os.path.exists("/usr/bootme"):
220 utils.makedirs(SYSIMG_PATH + "/usr/boot")
221 boot_server = file("/usr/bootme/BOOTSERVER").readline().strip()
222 shutil.copy("/usr/bootme/cacert/" + boot_server + "/cacert.pem",
223 SYSIMG_PATH + "/usr/boot/cacert.pem")
224 file(SYSIMG_PATH + "/usr/boot/boot_server", "w").write(boot_server)
225 shutil.copy("/usr/bootme/pubring.gpg", SYSIMG_PATH + "/usr/boot/pubring.gpg")
227 # For backward compatibility
228 if os.path.exists("/usr/bootme"):
229 utils.makedirs(SYSIMG_PATH + "/mnt/cdrom")
230 shutil.copytree("/usr/bootme", SYSIMG_PATH + "/mnt/cdrom/bootme")
232 # Import the GPG key into the RPM database so that RPMS can be verified
233 utils.makedirs(SYSIMG_PATH + "/etc/pki/rpm-gpg")
234 utils.sysexec("gpg --homedir=/root --export --armor" \
235 " --no-default-keyring --keyring %s/usr/boot/pubring.gpg" \
236 " >%s/etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab" % (SYSIMG_PATH, SYSIMG_PATH))
237 utils.sysexec_chroot(SYSIMG_PATH, "rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab")
239 # the yum config has changed entirely;
240 # in addition yum installs have more or less never worked - let's forget about this
241 # maybe NodeManager could profitably do the job instead
243 log.write("WARNING : yum installs for node extensions are not supported anymore\n")