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

Last change on this file since 1090 was 1090, checked in by broder, 16 years ago

Look for CD images in /dev/xenvg/image_* and validate them against the
database

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