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

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

get db uri from invirt.config in sipb-database

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