# Xen domain configuration file for scripts.mit.edu virtualized web servers # # usage, e.g.: # xm create scripts-server machine_name=bees-knees # xm create scripts-server machine_name=cats-whiskers # name is the name of the server (as used in the LV volumes) # mac5 is the fifth octet of the MAC address: ac:de:48:00:xx:01 # set install=fcX if you want to run a Fedora install, where X # is the version of Fedora to install vm_host = 0 vm_cpus = 1 vm_mem = 2 vm_mac5 = 3 machines = { 'bees-knees' : ['david-letterman', 2, 2560, '10'], 'cats-whiskers' : ['david-letterman', 2, 6144, '20'], 'not-backward' : ['david-letterman', 2, 2560, '30'], 'busy-beaver' : ['conan-obrien', 2, 4096, '40'], 'pancake-bunny' : ['conan-obrien', 2, 4096, '50'], 'whole-enchilada': ['jay-leno', 2, 4096, '60'], 'real-mccoy' : ['jay-leno', 2, 4096, '70'], 'not-forward' : ['jay-leno', 1, 512, '80'], 'old-faithful' : ['johnny-carson', 2, 4096, '90'], 'better-mousetrap' : ['johnny-carson', 2, 4096, 'a0'], 'shining-armor' : ['david-letterman', 2, 6144, 'b0'], } vm = machines[machine_name] mac5 = vm[vm_mac5] 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/isolinux" % fedora_release os.mkdir(install_dir) subprocess.check_call(["wget", "-r", "-nd", download_dir], cwd=install_dir) def serve_kickstart(machine_name, install): """ Serve a parametrized /root/kickstart.ks to localhost once. """ import socket import string import re import os import BaseHTTPServer import sys # some calculations hostname = machine_name + ".mit.edu" ip = socket.gethostbyname(hostname) source_server = "shining-armor.mit.edu" # hard-coded source_ip = re.sub('^18.181.0.', '172.21.0.', socket.gethostbyname(source_server)) # 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 = re.sub('^f', '', install), hostname = hostname, ip = ip, backend_ip = re.sub('^18.181.0.', '172.21.0.', ip), branch = "branches/fc13-dev", source_server = source_server, source_ip = source_ip, ) 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 else: 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 ip = socket.gethostbyname(machine_name + ".mit.edu") 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", "ksdevice=eth0", # "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': kernel = "/usr/lib/xen/boot/hvmloader" builder = "hvm" vnc = 1 vncpassword = "foobar" else: # Fedora installs GRUB. bootloader = "/usr/bin/pygrub" vcpus = vm[vm_cpus] if 'memory' not in locals(): memory = vm[vm_mem] maxmem = 16384 name = machine_name vg = vm[vm_host] disk = [i % (vg, name) for i in ['phy:/dev/%s/%s-root,xvda,w', 'phy:/dev/%s/%s-swap,xvde,w']] vif = [i % mac5 for i in ['bridge=eth0, mac=ac:de:48:00:%s:01', 'bridge=eth1, mac=ac:de:48:00:%s:02']] if 'builder' not in locals() or builder != "hvm": # https://bugzilla.redhat.com/show_bug.cgi?id=466681 # pygrub uses cached and eventually outdated grub.conf, kernel and initrd file('/proc/sys/vm/drop_caches', 'w').write('1') #if 'install' in locals(): # disk.append('file:/root/%s-install/cdimg.ext3.img,hdc1,r' % install)