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

Last change on this file since 828 was 828, checked in by price, 16 years ago

check in uncommitted changes to /etc/xen/sipb-database on black-mesa

File size: 2.6 KB
Line 
1# -*- mode: python; -*-
2import sipb_xen_database.models as models
3from sipb_xen_database import connect
4import re
5import tempfile
6from subprocess import call
7
8connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
9prefix = "d_"
10
11# 'machine_name', and optionally 'cdrom_image', should get passed in
12# from the xm create call
13
14def check(b):
15    if not b:
16        import sys
17        sys.exit(1)
18
19machine = models.Machine.get_by(name=machine_name)
20check(machine is not None)
21machine_type = models.Type.get_by(type_id=machine.type_id)
22
23memory = machine.memory
24maxmem = memory
25check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
26name = prefix + machine.name
27check(re.match('^[0-9a-f-]+$', machine.uuid))
28uuid = machine.uuid
29
30vcpus = machine.cpus
31
32diskioemu = ""
33viftype = ""
34
35pae = machine_type.pae
36acpi = machine_type.acpi
37apic = machine_type.apic
38
39vif = []
40
41disk = []
42
43if machine_type.hvm:
44    codepath = 'hvm'
45else:
46    codepath = 'paravm'
47
48if 'mirror' in locals(): #Installer
49    disk.append('phy:/dev/xenvg/d_foobar3_hda,hdb,r')
50
51    kernel = '/boot/vmlinuz-2.6.24-19-xen' #From hardy
52    ramdisk = '/boot/initrd.img-2.6.24-19-xen'
53
54    if not machine.nics:
55        raise RuntimeError('You must have a nic to autoinstall')
56    n = machine.nics[0]
57    extra = 'ro noresume'
58    extra += ' ip=%s::18.181.0.1:255.255.0.0:%s:eth0:off' % (n.ip, machine.name)
59    extra += ' mirror=%s dist=%s' % (mirror, dist)
60    extra += ' imagesize=%s' % imagesize
61    if 'noinstall' in locals():
62        extra += ' noinstall'
63    root = '/dev/hdb1'
64    codepath = None
65elif '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    codepath = 'hvm'
70
71if codepath == 'hvm':
72    ioemu = "ioemu:"
73    viftype = "type=ioemu, "
74    kernel = 'hvmloader'
75    builder = 'hvm'
76    vnc = 1
77    vncpasswd = 'moocow'
78    device_model = '/usr/sbin/qemu-dm-sipb'
79    serial = "pty"
80elif codepath == 'paravm':
81    bootloader = '/usr/lib/xen-default/bin/pygrub'
82
83
84for n in machine.nics:
85    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
86    d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip)
87    vif.append(d)
88
89for d in machine.disks:
90    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
91    device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
92    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
93    disk.append(dspec)
94
95usbdevice = 'tablet'
96
97on_poweroff = 'destroy'
98on_reboot = 'restart'
99on_crash = 'destroy'
100if machine.autorestart:
101    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.