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

Last change on this file since 146 was 146, checked in by tabbott, 17 years ago

1) reworking of lvm stuff into a single python script rather than a pile of shell scripts

2) changing naming for database VMs to always start with d_

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