]> scripts.mit.edu Git - xen.git/commitdiff
Spawn an HTTPD daemon to serve the Kickstart file.
authorEdward Z. Yang <ezyang@mit.edu>
Mon, 20 Sep 2010 16:41:01 +0000 (12:41 -0400)
committerEdward Z. Yang <ezyang@mit.edu>
Mon, 20 Sep 2010 16:41:55 +0000 (12:41 -0400)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
scripts-server
scripts.ks

index 3af934607de2d801d56e6e9c769443d0787c1353..8885c501f1843874d9f60a9be3c7755403569cee 100644 (file)
@@ -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':
index 061ad4d46f1590234b7d73c2d5bf163fb52693d4..49ac916403b14ae671c04436200ca66980fa75c2 100644 (file)
@@ -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