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

Last change on this file since 109 was 109, checked in by andersk, 17 years ago

Add cdrom_image parameter; do some simple regex sanity checking.

File size: 1.9 KB
Line 
1# -*- mode: python; -*-
2import sipb_xen_database.models as models
3from sipb_xen_database import connect
4import re
5import sys
6
7connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
8
9# 'machine_name', and optionally 'cdrom_image', should get passed in
10# from the xm create call
11
12def check(b):
13    if not b:
14        exit(1)
15
16machine = models.Machine.get_by(name=machine_name)
17check(machine is not None)
18machine_type = models.Type.get_by(type_id=machine.type_id)
19
20memory = machine.memory
21maxmem = memory
22check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
23name = machine.name
24check(re.match('^[0-9a-f-]+$', machine.uuid))
25uuid = machine.uuid
26
27vcpus = machine.cpus
28
29diskioemu = ""
30viftype = ""
31
32if machine_type.hvm:
33    ioemu = "ioemu:"
34    viftype = "type=ioemu, "
35
36    kernel = 'hvmloader'
37    builder = 'hvm'
38    vnc = 1
39    vncpasswd = 'moocow'
40    device_model = '/usr/sbin/qemu-dm-sipb'
41else:
42    kernel  = '/boot/vmlinuz-2.6.18-4-xen-amd64'
43    ramdisk = '/boot/initrd.img-2.6.18-4-xen-amd64'
44    builder = 'linux'
45
46pae = machine_type.pae
47acpi = machine_type.acpi
48apic = machine_type.apic
49
50vif = []
51
52for n in machine.nics:
53    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
54    d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip)
55    vif.append(d)
56
57disk = []
58
59for d in machine.disks:
60    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
61    device = '/dev/xenvg/' + machine.name + '_' + d.guest_device_name
62    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
63    disk.append(dspec)
64
65if 'cdrom_image' in locals():
66    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', cdrom_image))
67    disk.append('file:/srv/images/' + cdrom_image + '.iso,hdc:cdrom,r')
68    boot = 'd'
69
70on_poweroff = 'destroy'
71on_reboot = 'restart'
72on_crash = 'destroy'
73if machine.autorestart:
74    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.