]> scripts.mit.edu Git - xen.git/blob - scripts-server
Support for automatically downloading kernel/initramfs, and broken Kickstart support.
[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,100],
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 make_ramdisk(base_image, machine_name, install):
46   """
47   Create a ramdisk containing our kickstart file in /root/kickstart.ks
48   """
49   import socket
50   import tempfile
51   import subprocess
52   import os
53   import os.path
54   import gzip
55   import StringIO
56   import string
57   import shutil
58
59   # some calculations
60   hostname = machine_name + ".mit.edu"
61   ip = socket.gethostbyname(hostname)
62
63   # create the playground
64   tmpdir = tempfile.mkdtemp()
65   rootdir = os.path.join(tmpdir, "root")
66
67   # add the kickstart file
68   os.mkdir(rootdir)
69   ks_orig = open("/etc/xen/scripts.ks").read()
70   ks = string.Template(ks_orig).substitute(
71     local_mirror = "ftp://mirrors.mit.edu",
72     official_mirror = "http://download3.fedora.redhat.com/pub",
73     arch = "x86_64",
74     fedora_release = install[1:],
75     hostname = hostname,
76     ip = ip,
77     )
78   open(os.path.join(rootdir, "scripts.ks"), 'w').write(ks)
79
80   # generate the final image
81   (tmpfd, tmpname) = tempfile.mkstemp(suffix=".img")
82   tmp = os.fdopen(tmpfd, 'w')
83   tmp.write(gzip.open(base_image).read())
84   tmp.close()
85   find = subprocess.Popen(["find", ".", "-depth", "-print"],
86             stdout=subprocess.PIPE, cwd=tmpdir)
87   cpio = subprocess.Popen(["cpio", "-v", "--append", "-o", "--file", tmpname, "-H", "newc"],
88             stdin=find.stdout, cwd=tmpdir)
89   cpio.communicate()
90   find.wait()
91
92   print "Using initramfs at %s" % tmpname
93   return tmpname
94
95 if 'install' in locals():
96   kernel = "/root/%s-install/vmlinuz" % install
97   extra = "selinux=0 ks=file:/root/scripts.ks"
98   maybe_download_isolinux(install)
99   ramdisk = make_ramdisk("/root/%s-install/initrd.img" % install, machine_name, install)
100 elif 'type' in locals() and type == 'hvm':
101   kernel = "/usr/lib/xen/boot/hvmloader"
102   builder = "hvm"
103   vnc = 1
104   vncpassword = "foobar"
105 else:
106   # Fedora installs GRUB.
107   bootloader = "/usr/bin/pygrub"
108
109 vcpus = vm[vm_cpus]
110 if 'memory' not in locals(): memory = vm[vm_mem]
111 maxmem = 16384
112 name = machine_name
113 vg = vm[vm_host]
114 disk = [i % (vg, name) for i in ['phy:/dev/%s/%s-root,xvda,w',
115                                  'phy:/dev/%s/%s-swap,xvde,w']]
116 vif = [i % mac5 for i in ['bridge=eth0, mac=ac:de:48:00:%s:01',
117                           'bridge=eth1, mac=ac:de:48:00:%s:02']]
118
119 if 'builder' not in locals() or builder != "hvm":
120   # https://bugzilla.redhat.com/show_bug.cgi?id=466681
121   # pygrub uses cached and eventually outdated grub.conf, kernel and initrd
122   file('/proc/sys/vm/drop_caches', 'w').write('1')
123
124 #if 'install' in locals():
125 #  disk.append('file:/root/%s-install/cdimg.ext3.img,hdc1,r' % install)