source: trunk/packages/sipb-xen-database/sipb-xen-database/client/etc/xen/sipb-database @ 245

Last change on this file since 245 was 245, checked in by price, 16 years ago

Prototype fast installer using a special guest.

Rather than poke directly in the boot sector, partition table,
etc, which caused so much pain last week (r231), we just dd
the entire disk. Then we poke at the bits that need to change
(like secrets, the hostname, the root password, the filesystem uuids).
Since this poking is distribution-dependent, we want it to be
supplied by the image, so to make that safe we run it in a VM.

The plan is

  1. source image is dd'd (in the host) to the target image
  2. special copying-installer image is booted, with access to target and to a small image containing its arguments
  3. copying-installer guest reads arguments, mounts target, runs a script with a well-known name in target, passing arguments.

Bits I haven't done yet include

  • frob grub config in the copying-installer image so it boots with init = the copying-installer script (doing this manually for testing)
  • install script into copying-installer, or into my example image, in a sane automated way (they're checked into partial/ here)
  • all the tasks the image's script ought to actually carry out
  • make this all available from remctl and the web pages.
File size: 2.4 KB
Line 
1# -*- mode: python; -*-
2import sipb_xen_database.models as models
3from sipb_xen_database import connect
4import re
5import tempfile
6from subprocess import call
7
8connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
9prefix = "d_"
10
11# 'machine_name', and optionally 'cdrom_image', should get passed in
12# from the xm create call
13
14def check(b):
15    if not b:
16        import sys
17        sys.exit(1)
18
19machine = models.Machine.get_by(name=machine_name)
20check(machine is not None)
21machine_type = models.Type.get_by(type_id=machine.type_id)
22
23memory = machine.memory
24maxmem = memory
25check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
26name = prefix + machine.name
27check(re.match('^[0-9a-f-]+$', machine.uuid))
28uuid = machine.uuid
29
30vcpus = machine.cpus
31
32diskioemu = ""
33viftype = ""
34
35if machine_type.hvm:
36    ioemu = "ioemu:"
37    viftype = "type=ioemu, "
38
39    kernel = 'hvmloader'
40    builder = 'hvm'
41    vnc = 1
42    vncpasswd = 'moocow'
43    device_model = '/usr/sbin/qemu-dm-sipb'
44else:
45    kernel  = '/boot/vmlinuz-2.6.18-4-xen-amd64'
46    ramdisk = '/boot/initrd.img-2.6.18-4-xen-amd64'
47    builder = 'linux'
48
49pae = machine_type.pae
50acpi = machine_type.acpi
51apic = machine_type.apic
52
53vif = []
54
55for n in machine.nics:
56    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
57    d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip)
58    vif.append(d)
59
60disk = []
61
62for d in machine.disks:
63    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
64    device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
65    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
66    disk.append(dspec)
67
68if 'installer' in locals():
69    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', installer))
70    tmptree = tempfile.mkdtemp('', 'auto-install.', '/tmp')
71    call(['/usr/sbin/sipb-xen-make-iso', installer, tmptree]
72         + installer_options.split(' '))
73    disk.append('file:'+tmptree+'/install.iso,hdc:cdrom,r')
74    boot = 'd'
75
76elif 'disks' in locals(): # for the copying installer's use
77    disk = disks.split(' ')
78    boot = 'c'
79
80elif 'cdrom_image' in locals():
81    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', cdrom_image))
82    disk.append('file:/srv/images/' + cdrom_image + '.iso,hdc:cdrom,r')
83    boot = 'd'
84
85on_poweroff = 'destroy'
86on_reboot = 'restart'
87on_crash = 'destroy'
88if machine.autorestart:
89    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.