+def maybe_download_isolinux(install):
+ """
+ Download the release image if it isn't already in /root.
+ """
+ import subprocess
+ import os.path
+
+ install_dir = "/root/%s-install" % install
+ if os.path.exists(install_dir): return
+ print "Downloading %s..." % install_dir
+ fedora_release = install[1:],
+ download_dir = "ftp://mirrors.mit.edu/fedora/linux/releases/%s/Fedora/x86_64/os" % fedora_release
+ os.mkdir(install_dir)
+ subprocess.check_call(["wget", "-r", "-nd", download_dir], cwd=install_dir)
+
+def make_ramdisk(base_image, machine_name, install):
+ """
+ Create a ramdisk containing our kickstart file in /root/kickstart.ks
+ """
+ import socket
+ import tempfile
+ import subprocess
+ import os
+ import os.path
+ import gzip
+ import StringIO
+ import string
+ import shutil
+
+ # some calculations
+ hostname = machine_name + ".mit.edu"
+ ip = socket.gethostbyname(hostname)
+
+ # create the playground
+ tmpdir = tempfile.mkdtemp()
+ rootdir = os.path.join(tmpdir, "root")
+
+ # add the kickstart file
+ os.mkdir(rootdir)
+ ks_orig = open("/etc/xen/scripts.ks").read()
+ ks = string.Template(ks_orig).substitute(
+ local_mirror = "ftp://mirrors.mit.edu",
+ official_mirror = "http://download3.fedora.redhat.com/pub",
+ arch = "x86_64",
+ fedora_release = install[1:],
+ hostname = hostname,
+ ip = ip,
+ )
+ open(os.path.join(rootdir, "scripts.ks"), 'w').write(ks)
+
+ # generate the final image
+ (tmpfd, tmpname) = tempfile.mkstemp(suffix=".img")
+ tmp = os.fdopen(tmpfd, 'w')
+ tmp.write(gzip.open(base_image).read())
+ tmp.close()
+ find = subprocess.Popen(["find", ".", "-depth", "-print"],
+ stdout=subprocess.PIPE, cwd=tmpdir)
+ cpio = subprocess.Popen(["cpio", "-v", "--append", "-o", "--file", tmpname, "-H", "newc"],
+ stdin=find.stdout, cwd=tmpdir)
+ cpio.communicate()
+ find.wait()
+
+ print "Using initramfs at %s" % tmpname
+ return tmpname
+