[101] | 1 | # -*- mode: python; -*- |
---|
[24] | 2 | import sipb_xen_database.models as models |
---|
[85] | 3 | from sipb_xen_database import connect |
---|
[109] | 4 | import re |
---|
| 5 | import sys |
---|
[24] | 6 | |
---|
[99] | 7 | connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen') |
---|
[24] | 8 | |
---|
[109] | 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 | |
---|
[85] | 16 | machine = models.Machine.get_by(name=machine_name) |
---|
[109] | 17 | check(machine is not None) |
---|
[65] | 18 | machine_type = models.Type.get_by(type_id=machine.type_id) |
---|
[24] | 19 | |
---|
| 20 | memory = machine.memory |
---|
| 21 | maxmem = memory |
---|
[109] | 22 | check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name)) |
---|
[24] | 23 | name = machine.name |
---|
[109] | 24 | check(re.match('^[0-9a-f-]+$', machine.uuid)) |
---|
[24] | 25 | uuid = machine.uuid |
---|
| 26 | |
---|
| 27 | vcpus = machine.cpus |
---|
| 28 | |
---|
[65] | 29 | diskioemu = "" |
---|
| 30 | viftype = "" |
---|
[24] | 31 | |
---|
[65] | 32 | if machine_type.hvm: |
---|
| 33 | ioemu = "ioemu:" |
---|
[101] | 34 | viftype = "type=ioemu, " |
---|
[65] | 35 | |
---|
| 36 | kernel = 'hvmloader' |
---|
| 37 | builder = 'hvm' |
---|
| 38 | vnc = 1 |
---|
[104] | 39 | vncpasswd = 'moocow' |
---|
| 40 | device_model = '/usr/sbin/qemu-dm-sipb' |
---|
[65] | 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: |
---|
[109] | 53 | check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip)) |
---|
[101] | 54 | d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip) |
---|
[84] | 55 | vif.append(d) |
---|
[65] | 56 | |
---|
[24] | 57 | disk = [] |
---|
| 58 | |
---|
| 59 | for d in machine.disks: |
---|
[109] | 60 | check(re.match('^[A-Za-z0-9]+$', d.guest_device_name)) |
---|
[104] | 61 | device = '/dev/xenvg/' + machine.name + '_' + d.guest_device_name |
---|
[65] | 62 | dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name) |
---|
[24] | 63 | disk.append(dspec) |
---|
| 64 | |
---|
[109] | 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' |
---|
[24] | 69 | |
---|
| 70 | on_poweroff = 'destroy' |
---|
| 71 | on_reboot = 'restart' |
---|
[109] | 72 | on_crash = 'destroy' |
---|
| 73 | if machine.autorestart: |
---|
| 74 | on_crash = 'restart' |
---|