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 extensions = [ "__main__" ]
95 utils.breakpoint("querying nodegroups")
97 # for (k,v) in vars.iteritems():
98 # print "vars['%s']='%s'"%(k,v)
99 # print 'NODE_ID=%d'%NODE_ID
100 nodes = BootAPI.call_api_function(vars, "GetNodes", ([NODE_ID], ['nodegroup_ids']))
102 nodegroups = BootAPI.call_api_function(vars, "GetNodeGroups", (node['nodegroup_ids'], ['name']))
103 extensions += [ nodegroup['name'].lower() for nodegroup in nodegroups]
106 log.write("WARNING : Failed to query nodegroups - installing only core software\n")
107 utils.breakpoint('query failure')
110 # download and extract support tarball for this step, which has
111 # everything we need to successfully run
113 # we first try to find a tarball, if it is not found we use yum instead
115 # download and extract support tarball for this step, which has
116 for extension in extensions:
117 if extension == "__main__":
118 tarball = "PlanetLab-Bootstrap.tar.bz2"
120 tarball = "PlanetLab-Bootstrap-%s.tar.bz2"%extension
121 source_file= "%s/%s" % (SUPPORT_FILE_DIR,tarball)
122 dest_file= "%s/%s" % (SYSIMG_PATH, tarball)
124 # 30 is the connect timeout, 14400 is the max transfer time in
126 log.write( "downloading %s\n" % tarball )
127 result= bs_request.DownloadFile( source_file, None, None,
131 log.write( "extracting %s in %s\n" % (dest_file,SYSIMG_PATH) )
132 result= utils.sysexec( "tar -C %s -xpjf %s" % (SYSIMG_PATH,dest_file), log )
134 utils.removefile( dest_file )
136 # the main tarball is required
137 if extension == "__main__":
138 raise BootManagerException, "Unable to download %s from server." % \
141 log.write("tarball for %s not found, scheduling a yum attempt\n"%extension)
142 yum_extensions.append(extension)
144 # copy resolv.conf from the base system into our temp dir
145 # so DNS lookups work correctly while we are chrooted
146 log.write( "Copying resolv.conf to temp dir\n" )
147 utils.sysexec( "cp /etc/resolv.conf %s/etc/" % SYSIMG_PATH, log )
149 # Copy the boot server certificate(s) and GPG public key to
150 # /usr/boot in the temp dir.
151 log.write( "Copying boot server certificates and public key\n" )
153 if os.path.exists("/usr/boot"):
154 utils.makedirs(SYSIMG_PATH + "/usr")
155 shutil.copytree("/usr/boot", SYSIMG_PATH + "/usr/boot")
156 elif os.path.exists("/usr/bootme"):
157 utils.makedirs(SYSIMG_PATH + "/usr/boot")
158 boot_server = file("/usr/bootme/BOOTSERVER").readline().strip()
159 shutil.copy("/usr/bootme/cacert/" + boot_server + "/cacert.pem",
160 SYSIMG_PATH + "/usr/boot/cacert.pem")
161 file(SYSIMG_PATH + "/usr/boot/boot_server", "w").write(boot_server)
162 shutil.copy("/usr/bootme/pubring.gpg", SYSIMG_PATH + "/usr/boot/pubring.gpg")
164 # For backward compatibility
165 if os.path.exists("/usr/bootme"):
166 utils.makedirs(SYSIMG_PATH + "/mnt/cdrom")
167 shutil.copytree("/usr/bootme", SYSIMG_PATH + "/mnt/cdrom/bootme")
169 # Import the GPG key into the RPM database so that RPMS can be verified
170 utils.makedirs(SYSIMG_PATH + "/etc/pki/rpm-gpg")
171 utils.sysexec("gpg --homedir=/root --export --armor" \
172 " --no-default-keyring --keyring %s/usr/boot/pubring.gpg" \
173 " >%s/etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab" % (SYSIMG_PATH, SYSIMG_PATH))
174 utils.sysexec("chroot %s rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab" % \
177 for extension in yum_extensions:
178 yum_command="yum groupinstall extension%s"%extension
179 log.write("Attempting to install extension %s through yum\n"%extension)
180 utils.sysexec("chroot %s %s" % (SYSIMG_PATH,yum_command))