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
14 from Exceptions import *
16 import BootServerRequest
22 Download enough files to run rpm and yum from a chroot in
23 the system image directory
25 Expect the following variables from the store:
26 SYSIMG_PATH the path where the system image will be mounted
27 PARTITIONS dictionary of generic part. types (root/swap)
28 and their associated devices.
29 SUPPORT_FILE_DIR directory on the boot servers containing
30 scripts and support files
31 NODE_ID the id of this machine
33 Sets the following variables:
34 TEMP_BOOTCD_PATH where the boot cd is remounted in the temp
36 ROOT_MOUNTED set to 1 when the the base logical volumes
40 log.write( "\n\nStep: Install: bootstrapfs tarball.\n" )
42 # make sure we have the variables we need
44 SYSIMG_PATH= vars["SYSIMG_PATH"]
46 raise ValueError, "SYSIMG_PATH"
48 PARTITIONS= vars["PARTITIONS"]
49 if PARTITIONS == None:
50 raise ValueError, "PARTITIONS"
52 SUPPORT_FILE_DIR= vars["SUPPORT_FILE_DIR"]
53 if SUPPORT_FILE_DIR == None:
54 raise ValueError, "SUPPORT_FILE_DIR"
56 NODE_ID= vars["NODE_ID"]
58 raise ValueError, "NODE_ID"
61 raise BootManagerException, "Missing variable in vars: %s\n" % var
62 except ValueError, var:
63 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
67 # make sure the required partitions exist
68 val= PARTITIONS["root"]
69 val= PARTITIONS["swap"]
70 val= PARTITIONS["vservers"]
71 except KeyError, part:
72 log.write( "Missing partition in PARTITIONS: %s\n" % part )
75 bs_request= BootServerRequest.BootServerRequest()
77 log.write( "turning on swap space\n" )
78 utils.sysexec( "swapon %s" % PARTITIONS["swap"], log )
80 # make sure the sysimg dir is present
81 utils.makedirs( SYSIMG_PATH )
83 log.write( "mounting root file system\n" )
84 utils.sysexec( "mount -t ext3 %s %s" % (PARTITIONS["root"],SYSIMG_PATH), log )
86 log.write( "mounting vserver partition in root file system\n" )
87 utils.makedirs( SYSIMG_PATH + "/vservers" )
88 utils.sysexec( "mount -t ext3 %s %s/vservers" % (PARTITIONS["vservers"],
91 vars['ROOT_MOUNTED']= 1
93 # check which nodegroups we are part of (>=4.0)
94 utils.breakpoint("querying nodegroups for loading extensions")
96 nodes = BootAPI.call_api_function(vars, "GetNodes", ([NODE_ID], ['nodegroup_ids']))
98 nodegroups = BootAPI.call_api_function(vars, "GetNodeGroups", (node['nodegroup_ids'], ['name']))
99 nodegroupnames = [ nodegroup['name'].lower() for nodegroup in nodegroups ]
102 log.write("WARNING : Failed to query nodegroups - installing only core software\n")
106 # fetch the distribution our myplc was built upon
108 plc_release = BootAPI.call_api_function (vars, "GetPlcRelease",())
109 distribution = plc_release ['build']['planetlab-distro']
111 distribution = 'planetlab'
113 # fetch the distribution our myplc was built upon
116 # plc_release = BootAPI.call_api_function (var, "GetPlcRelease",())
117 arch = plc_release ['build']['target-arch']
121 # scan nodegroupnames - temporary, as most of this nodegroup-based info
122 # should be more adequately defined in the nodes data model
124 for nodegroupname in nodegroupnames:
125 if nodegroupname in [ 'x86_64','i386' ] :
127 elif nodegroupname in [ 'planetlab', 'onelab', 'vini' ] :
128 distribution = nodegroupname
130 extensions.append(nodegroupname)
132 bootstrapfs_names = [ distribution ] + extensions
134 # download and extract support tarball for this step, which has
135 # everything we need to successfully run
137 # we first try to find a tarball, if it is not found we use yum instead
139 # download and extract support tarball for this step, which has
140 for bootstrapfs_name in bootstrapfs_names:
141 tarball = "bootstrapfs-%s-%s.tar.bz2"%(bootstrapfs_name,arch)
142 source_file= "%s/%s" % (SUPPORT_FILE_DIR,tarball)
143 dest_file= "%s/%s" % (SYSIMG_PATH, tarball)
145 # 30 is the connect timeout, 14400 is the max transfer time in
147 log.write( "downloading %s\n" % source_file )
148 result= bs_request.DownloadFile( source_file, None, None,
152 log.write( "extracting %s in %s\n" % (dest_file,SYSIMG_PATH) )
153 result= utils.sysexec( "tar -C %s -xpjf %s" % (SYSIMG_PATH,dest_file), log )
155 utils.removefile( dest_file )
157 # the main tarball is required
158 if bootstrapfs_name == distribution:
159 raise BootManagerException, "Unable to download main tarball %s from server." % \
162 log.write("tarball for %s-%s not found, scheduling a yum attempt\n"%(bootstrapfs_name,arch))
163 yum_extensions.append(bootstrapfs_name)
165 # copy resolv.conf from the base system into our temp dir
166 # so DNS lookups work correctly while we are chrooted
167 log.write( "Copying resolv.conf to temp dir\n" )
168 utils.sysexec( "cp /etc/resolv.conf %s/etc/" % SYSIMG_PATH, log )
170 # Copy the boot server certificate(s) and GPG public key to
171 # /usr/boot in the temp dir.
172 log.write( "Copying boot server certificates and public key\n" )
174 if os.path.exists("/usr/boot"):
175 utils.makedirs(SYSIMG_PATH + "/usr")
176 shutil.copytree("/usr/boot", SYSIMG_PATH + "/usr/boot")
177 elif os.path.exists("/usr/bootme"):
178 utils.makedirs(SYSIMG_PATH + "/usr/boot")
179 boot_server = file("/usr/bootme/BOOTSERVER").readline().strip()
180 shutil.copy("/usr/bootme/cacert/" + boot_server + "/cacert.pem",
181 SYSIMG_PATH + "/usr/boot/cacert.pem")
182 file(SYSIMG_PATH + "/usr/boot/boot_server", "w").write(boot_server)
183 shutil.copy("/usr/bootme/pubring.gpg", SYSIMG_PATH + "/usr/boot/pubring.gpg")
185 # For backward compatibility
186 if os.path.exists("/usr/bootme"):
187 utils.makedirs(SYSIMG_PATH + "/mnt/cdrom")
188 shutil.copytree("/usr/bootme", SYSIMG_PATH + "/mnt/cdrom/bootme")
190 # Import the GPG key into the RPM database so that RPMS can be verified
191 utils.makedirs(SYSIMG_PATH + "/etc/pki/rpm-gpg")
192 utils.sysexec("gpg --homedir=/root --export --armor" \
193 " --no-default-keyring --keyring %s/usr/boot/pubring.gpg" \
194 " >%s/etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab" % (SYSIMG_PATH, SYSIMG_PATH))
195 utils.sysexec("chroot %s rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab" % \
198 # yum-based extensions:
199 # before we can use yum, yum.conf needs to get installed
200 # xxx this should probably depend on the node's nodegroup, at least among alpha, beta ..
201 # however there does not seem to be a clear interface for that in yum.conf.php
202 # so let's keep it simple for the bootstrap phase, as yum.conf will get overwritten anyway
204 getDict = {'gpgcheck':1,'arch':arch}
205 url="PlanetLabConf/yum.conf.php"
206 dest="%s/etc/yum.conf"%SYSIMG_PATH
207 log.write("downloading bootstrap yum.conf\n")
208 yumconf=bs_request.DownloadFile (url,getDict,None,
211 log.write("Cannot fetch %s from %s - aborting yum extensions"%(dest,url))
212 # failures here should not stop the install process
215 # yum also needs /proc to be mounted
216 # do it here so as to not break the tarballs-only case
217 cmd = "mount -t proc none %s/proc" % SYSIMG_PATH
218 utils.sysexec( cmd, log )
219 # we now just need to yum groupinstall everything
220 for extension in yum_extensions:
221 yum_command="yum groupinstall extension%s"%extension
222 utils.breakpoint ("before chroot %s %s"%(SYSIMG_PATH,yum_command))
223 log.write("Attempting to install extension %s through yum\n"%extension)
224 utils.sysexec_noerr("chroot %s %s" % (SYSIMG_PATH,yum_command))
225 # xxx how to check that this completed correctly ?
227 utils.sysexec_noerr( "umount %s/proc" % SYSIMG_PATH, log )
228 utils.breakpoint ("Done with yum extensions")