os.mkdir(install_dir)
subprocess.check_call(["wget", "-r", "-nd", download_dir], cwd=install_dir)
-def make_ramdisk(base_image, machine_name, install):
+def serve_kickstart(machine_name, install):
"""
- Create a ramdisk containing our kickstart file in /root/kickstart.ks
+ Serve a parametrized /root/kickstart.ks to localhost once.
"""
import socket
- import tempfile
- import subprocess
- import os
- import os.path
- import gzip
- import StringIO
import string
- import shutil
+ import re
+ import os
+ import BaseHTTPServer
+ import sys
# 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)
+ # generate the kickstart file
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:],
+ fedora_release = re.sub('^f', '', install),
hostname = hostname,
ip = ip,
+ backend_ip = re.sub('^18.181.0.', '172.21.0.', 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
+
+ class SingleFileHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+ def do_GET(self):
+ self.send_response(200)
+ self.end_headers()
+ self.wfile.write(ks)
+
+ if os.fork(): return
+
+ # brief race condition
+ try:
+ BaseHTTPServer.HTTPServer(('', 55555), SingleFileHandler).handle_request()
+ except Exception, e:
+ print "Serving kickstart failed."
+ print e
+
+ print "Kickstart served"
+ sys.exit()
if 'install' in locals():
+ maybe_download_isolinux(install)
+
kernel = "/root/%s-install/vmlinuz" % install
ramdisk = "/root/%s-install/initrd.img" % install
- # some calculations
- hostname = machine_name + ".mit.edu"
- ip = socket.gethostbyname(hostname)
+ ip = socket.gethostbyname(machine_name + ".mit.edu")
- extra = "selinux=0 ks=http://whole-enchilada.mit.edu/old-faithful.txt ip="+ip+" netmask=255.255.0.0 gateway=18.181.0.1 dns=18.70.0.160,18.71.0.151,18.72.0.3 syslog=18.181.0.51:514 debug=1 loglevel=debug telnet"
- maybe_download_isolinux(install)
- #ramdisk = make_ramdisk("/root/%s-install/initrd.img" % install, machine_name, install)
+ serve_kickstart(machine_name, install)
+
+ ks_url = "http://%s.mit.edu:55555/" % vm[vm_host]
+ extra = ' '.join([
+ "selinux=0",
+ "ks=" + ks_url,
+ "ip=" + ip,
+ "netmask=255.255.0.0",
+ "gateway=18.181.0.1",
+ "dns=18.70.0.160,18.71.0.151,18.72.0.3",
+ # "syslog=18.181.0.51:514 debug=1 loglevel=debug telnet",
+ ])
on_reboot = 'destroy' # don't rerun the installer
elif 'type' in locals() and type == 'hvm':