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