From 18419fb468c963312d396e729f32a821bd6b490d Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 20 Sep 2010 12:41:01 -0400 Subject: [PATCH] Spawn an HTTPD daemon to serve the Kickstart file. Signed-off-by: Edward Z. Yang --- scripts-server | 80 ++++++++++++++++++++++++++------------------------ scripts.ks | 2 +- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/scripts-server b/scripts-server index 3af9346..8885c50 100644 --- a/scripts-server +++ b/scripts-server @@ -42,67 +42,71 @@ def maybe_download_isolinux(install): 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': diff --git a/scripts.ks b/scripts.ks index 061ad4d..49ac916 100644 --- a/scripts.ks +++ b/scripts.ks @@ -13,7 +13,7 @@ install url --url=${local_mirror}/fedora/linux/releases/${fedora_release}/Fedora/${arch}/os lang en_US.UTF-8 keyboard us -network --device eth0 --bootproto static --ip ${ip} --netmask 255.255.0.0 --gateway 18.181.0.1 --nameserver 18.71.0.151 --hostname ${hostname} +network --device eth0 --bootproto static --ip ${ip} --netmask 255.255.0.0 --gateway 18.181.0.1 --nameserver 18.70.0.160,18.71.0.151,18.72.0.3 --hostname ${hostname} #network --device eth1 --bootproto static --ip ${backend_ip} --netmask 255.255.0.0 timezone --utc America/New_York -- 2.45.0