1 | # -*- mode: python; -*- |
---|
2 | import sipb_xen_database.models as models |
---|
3 | from sipb_xen_database import connect |
---|
4 | import re |
---|
5 | import sys |
---|
6 | |
---|
7 | connect('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 | |
---|
12 | def check(b): |
---|
13 | if not b: |
---|
14 | exit(1) |
---|
15 | |
---|
16 | machine = models.Machine.get_by(name=machine_name) |
---|
17 | check(machine is not None) |
---|
18 | machine_type = models.Type.get_by(type_id=machine.type_id) |
---|
19 | |
---|
20 | memory = machine.memory |
---|
21 | maxmem = memory |
---|
22 | check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name)) |
---|
23 | name = machine.name |
---|
24 | check(re.match('^[0-9a-f-]+$', machine.uuid)) |
---|
25 | uuid = machine.uuid |
---|
26 | |
---|
27 | vcpus = machine.cpus |
---|
28 | |
---|
29 | diskioemu = "" |
---|
30 | viftype = "" |
---|
31 | |
---|
32 | if 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' |
---|
41 | else: |
---|
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 | |
---|
46 | pae = machine_type.pae |
---|
47 | acpi = machine_type.acpi |
---|
48 | apic = machine_type.apic |
---|
49 | |
---|
50 | vif = [] |
---|
51 | |
---|
52 | for 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 | |
---|
57 | disk = [] |
---|
58 | |
---|
59 | for 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 | |
---|
65 | if '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 | |
---|
70 | on_poweroff = 'destroy' |
---|
71 | on_reboot = 'restart' |
---|
72 | on_crash = 'destroy' |
---|
73 | if machine.autorestart: |
---|
74 | on_crash = 'restart' |
---|