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

Last change on this file since 711 was 671, checked in by quentin, 16 years ago

Boot VMs as HVM when there is a boot CD, regardless of machine type

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)
21hvm = machine.type.hvm
22if 'cdrom_image' in locals():
23    hvm = True
24
25memory = machine.memory
26maxmem = memory
27check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
28name = prefix + machine.name
29check(re.match('^[0-9a-f-]+$', machine.uuid))
30uuid = machine.uuid
31
32vcpus = machine.cpus
33
34diskioemu = ""
35viftype = ""
36
37if hvm:
38    ioemu = "ioemu:"
39    viftype = "type=ioemu, "
40
41    kernel = 'hvmloader'
42    builder = 'hvm'
43    vnc = 1
44    vncpasswd = 'moocow'
45    device_model = '/usr/sbin/qemu-dm-sipb'
46    serial = 'pty'
47else:
48    kernel  = '/boot/vmlinuz-2.6.18-5-xen-amd64'
49    ramdisk = '/boot/initrd.img-2.6.18-5-xen-amd64'
50    builder = 'linux'
51
52pae = machine.type.pae
53acpi = machine.type.acpi
54apic = machine.type.apic
55
56vif = []
57
58for n in machine.nics:
59    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
60    d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip)
61    vif.append(d)
62
63disk = []
64
65for d in machine.disks:
66    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
67    device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
68    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
69    disk.append(dspec)
70
71if 'installer' in locals():
72    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', installer))
73    tmptree = tempfile.mkdtemp('', 'auto-install.', '/tmp')
74    call(['/usr/sbin/sipb-xen-make-iso', installer, tmptree]
75         + installer_options.split(' '))
76    disk.append('file:'+tmptree+'/install.iso,hdc:cdrom,r')
77    boot = 'd'
78
79elif 'disks' in locals(): # for the copying installer's use
80    disk = disks.split(' ')
81    boot = 'c'
82
83elif 'cdrom_image' in locals():
84    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', cdrom_image))
85    disk.append('file:/srv/images/' + cdrom_image + '.iso,hdc:cdrom,r')
86    boot = 'd'
87
88usbdevice = 'tablet'
89
90on_poweroff = 'destroy'
91on_reboot = 'restart'
92on_crash = 'destroy'
93if machine.autorestart:
94    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.