1 # -*- mode: python; -*-
2 import sipb_xen_database.models as models
3 from sipb_xen_database import connect
6 from subprocess import call
8 connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
11 # 'machine_name', and optionally 'cdrom_image', should get passed in
12 # from the xm create call
19 machine = models.Machine.get_by(name=machine_name)
20 check(machine is not None)
21 machine_type = models.Type.get_by(type_id=machine.type_id)
23 memory = machine.memory
25 check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
26 name = prefix + machine.name
27 check(re.match('^[0-9a-f-]+$', machine.uuid))
37 viftype = "type=ioemu, "
43 device_model = '/usr/sbin/qemu-dm-sipb'
45 kernel = '/boot/vmlinuz-2.6.18-4-xen-amd64'
46 ramdisk = '/boot/initrd.img-2.6.18-4-xen-amd64'
49 pae = machine_type.pae
50 acpi = machine_type.acpi
51 apic = machine_type.apic
55 for n in machine.nics:
56 check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
57 d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip)
62 for d in machine.disks:
63 check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
64 device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
65 dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
68 if 'installer' in locals():
69 check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', installer))
70 tmptree = tempfile.mkdtemp('', 'auto-install.', '/tmp')
71 call(['/usr/sbin/sipb-xen-make-iso', installer, tmptree]
72 + installer_options.split(' '))
73 disk.append('file:'+tmptree+'/install.iso,hdc:cdrom,r')
76 elif 'cdrom_image' in locals():
77 check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', cdrom_image))
78 disk.append('file:/srv/images/' + cdrom_image + '.iso,hdc:cdrom,r')
81 on_poweroff = 'destroy'
84 if machine.autorestart: