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
RevLine 
[101]1# -*- mode: python; -*-
[24]2import sipb_xen_database.models as models
[85]3from sipb_xen_database import connect
[109]4import re
5import sys
[24]6
[99]7connect('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
12def check(b):
13    if not b:
14        exit(1)
15
[85]16machine = models.Machine.get_by(name=machine_name)
[109]17check(machine is not None)
[65]18machine_type = models.Type.get_by(type_id=machine.type_id)
[24]19
20memory = machine.memory
21maxmem = memory
[109]22check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
[24]23name = machine.name
[109]24check(re.match('^[0-9a-f-]+$', machine.uuid))
[24]25uuid = machine.uuid
26
27vcpus = machine.cpus
28
[65]29diskioemu = ""
30viftype = ""
[24]31
[65]32if 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]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:
[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]57disk = []
58
59for 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]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'
[24]69
70on_poweroff = 'destroy'
71on_reboot = 'restart'
[109]72on_crash = 'destroy'
73if machine.autorestart:
74    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.