source: branches/wsgi/packages/sipb-xen-database/client/etc/xen/sipb-database @ 1259

Last change on this file since 1259 was 490, checked in by quentin, 17 years ago

Configure serial console on boot

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'
44    serial = 'pty'
45else:
46    kernel  = '/boot/vmlinuz-2.6.18-5-xen-amd64'
47    ramdisk = '/boot/initrd.img-2.6.18-5-xen-amd64'
48    builder = 'linux'
49
50pae = machine_type.pae
51acpi = machine_type.acpi
52apic = machine_type.apic
53
54vif = []
55
56for n in machine.nics:
57    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
58    d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip)
59    vif.append(d)
60
61disk = []
62
63for d in machine.disks:
64    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
65    device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
66    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
67    disk.append(dspec)
68
69if 'installer' in locals():
70    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', installer))
71    tmptree = tempfile.mkdtemp('', 'auto-install.', '/tmp')
72    call(['/usr/sbin/sipb-xen-make-iso', installer, tmptree]
73         + installer_options.split(' '))
74    disk.append('file:'+tmptree+'/install.iso,hdc:cdrom,r')
75    boot = 'd'
76
77elif 'disks' in locals(): # for the copying installer's use
78    disk = disks.split(' ')
79    boot = 'c'
80
81elif 'cdrom_image' in locals():
82    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', cdrom_image))
83    disk.append('file:/srv/images/' + cdrom_image + '.iso,hdc:cdrom,r')
84    boot = 'd'
85
86usbdevice = 'tablet'
87
88on_poweroff = 'destroy'
89on_reboot = 'restart'
90on_crash = 'destroy'
91if machine.autorestart:
92    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.