]> scripts.mit.edu Git - xen.git/blob - scripts-server
ab9aff3d95d74a55d4a753e70512fc0f4cd3b22d
[xen.git] / scripts-server
1 # Xen domain configuration file for scripts.mit.edu virtualized web servers
2 #
3 # usage, e.g.:
4 #   xm create scripts-server machine_name=bees-knees
5 #   xm create scripts-server machine_name=cats-whiskers
6 # name is the name of the server (as used in the LV volumes)
7 # mac5 is the fifth octet of the MAC address: ac:de:48:00:xx:01
8 # set install=fcX if you want to run a Fedora install, where X
9 # is the version of Fedora to install
10
11 vm_host = 0
12 vm_cpus = 1
13 vm_mem  = 2
14 vm_mac5 = 3
15 machines = { 'bees-knees'     : ['david-letterman',  2, 6144, '10'],
16              'cats-whiskers'  : ['david-letterman',  2, 6144, '20'],
17              'not-backward'   : ['david-letterman',  2, 2560, '30'],
18              'busy-beaver'    : ['conan-obrien',     2, 4096, '40'],
19              'pancake-bunny'  : ['conan-obrien',     2, 4096, '50'],
20              'whole-enchilada': ['jay-leno',         1, 2048, '60'],
21              'real-mccoy'     : ['jay-leno',         2, 4096, '70'],
22              'not-forward'    : ['jay-leno',         2,  512, '80'],
23              'old-faithful'   : ['johnny-carson',    2, 4096, '90'],
24              'better-mousetrap' : ['johnny-carson',  2, 4096, 'a0'],
25            }
26 vm = machines[machine_name]
27
28 mac5 = vm[vm_mac5]
29
30 def maybe_download_isolinux(install):
31   """
32   Download the release image if it isn't already in /root.
33   """
34   import subprocess
35   import os.path
36
37   install_dir = "/root/%s-install" % install
38   if os.path.exists(install_dir): return
39   print "Downloading %s..." % install_dir
40   fedora_release = install[1:],
41   download_dir = "ftp://mirrors.mit.edu/fedora/linux/releases/%s/Fedora/x86_64/os" % fedora_release
42   os.mkdir(install_dir)
43   subprocess.check_call(["wget", "-r", "-nd", download_dir], cwd=install_dir)
44
45 def serve_kickstart(machine_name, install):
46   """
47   Serve a parametrized /root/kickstart.ks to localhost once.
48   """
49   import socket
50   import string
51   import re
52   import os
53   import BaseHTTPServer
54   import sys
55
56   # some calculations
57   hostname = machine_name + ".mit.edu"
58   ip = socket.gethostbyname(hostname)
59
60   source_server = "cats-whiskers.mit.edu" # hard-coded
61   source_ip = re.sub('^18.181.0.', '172.21.0.', socket.gethostbyname(source_server))
62
63   # generate the kickstart file
64   ks_orig = open("/etc/xen/scripts.ks").read()
65   ks = string.Template(ks_orig).substitute(
66     local_mirror = "ftp://mirrors.mit.edu",
67     official_mirror = "http://download3.fedora.redhat.com/pub",
68     arch = "x86_64",
69     fedora_release = re.sub('^f', '', install),
70     hostname = hostname,
71     ip = ip,
72     backend_ip = re.sub('^18.181.0.', '172.21.0.', ip),
73     branch = "branches/fc13-dev",
74     source_server = source_server,
75     source_ip = source_ip,
76     )
77
78   class SingleFileHandler(BaseHTTPServer.BaseHTTPRequestHandler):
79     def do_GET(self):
80       self.send_response(200)
81       self.end_headers()
82       self.wfile.write(ks)
83
84   if os.fork(): return
85
86   # brief race condition
87   try:
88     BaseHTTPServer.HTTPServer(('', 55555), SingleFileHandler).handle_request()
89   except Exception, e:
90     print "Serving kickstart failed."
91     print e
92   else:
93     print "Kickstart served"
94
95   sys.exit()
96
97 if 'install' in locals():
98   maybe_download_isolinux(install)
99
100   kernel = "/root/%s-install/vmlinuz" % install
101   ramdisk = "/root/%s-install/initrd.img" % install
102
103   ip = socket.gethostbyname(machine_name + ".mit.edu")
104
105   serve_kickstart(machine_name, install)
106
107   ks_url = "http://%s.mit.edu:55555/" % vm[vm_host]
108   extra = ' '.join([
109       "selinux=0",
110       "ks=" + ks_url,
111       "ip=" + ip,
112       "netmask=255.255.0.0",
113       "gateway=18.181.0.1",
114       "dns=18.70.0.160,18.71.0.151,18.72.0.3",
115       "ksdevice=eth0",
116       # "syslog=18.181.0.51:514 debug=1 loglevel=debug telnet",
117       ])
118   on_reboot = 'destroy' # don't rerun the installer
119
120 elif 'type' in locals() and type == 'hvm':
121   kernel = "/usr/lib/xen/boot/hvmloader"
122   builder = "hvm"
123   vnc = 1
124   vncpassword = "foobar"
125 else:
126   # Fedora installs GRUB.
127   bootloader = "/usr/bin/pygrub"
128
129 vcpus = vm[vm_cpus]
130 if 'memory' not in locals(): memory = vm[vm_mem]
131 maxmem = 16384
132 name = machine_name
133 vg = vm[vm_host]
134 disk = [i % (vg, name) for i in ['phy:/dev/%s/%s-root,xvda,w',
135                                  'phy:/dev/%s/%s-swap,xvde,w']]
136 vif = [i % mac5 for i in ['bridge=eth0, mac=ac:de:48:00:%s:01',
137                           'bridge=eth1, mac=ac:de:48:00:%s:02']]
138
139 if 'builder' not in locals() or builder != "hvm":
140   # https://bugzilla.redhat.com/show_bug.cgi?id=466681
141   # pygrub uses cached and eventually outdated grub.conf, kernel and initrd
142   file('/proc/sys/vm/drop_caches', 'w').write('1')
143
144 #if 'install' in locals():
145 #  disk.append('file:/root/%s-install/cdimg.ext3.img,hdc1,r' % install)