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

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

Some fixes in the sipb-database Xen config script

File size: 2.7 KB
RevLine 
[101]1# -*- mode: python; -*-
[829]2from invirt.database import models, connect
[842]3from invirt.config import structs as config
[109]4import re
[223]5import tempfile
6from subprocess import call
[24]7
[829]8connect()
[146]9prefix = "d_"
[24]10
[109]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:
[117]16        import sys
17        sys.exit(1)
[109]18
[1016]19machine = models.Machine.query().filter_by(name=machine_name).one()
[109]20check(machine is not None)
[1016]21machine_type = models.Type.query().filter_by(type_id=machine.type_id).one()
[24]22
23memory = machine.memory
24maxmem = memory
[109]25check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
[146]26name = prefix + machine.name
[109]27check(re.match('^[0-9a-f-]+$', machine.uuid))
[24]28uuid = machine.uuid
29
30vcpus = machine.cpus
31
[65]32diskioemu = ""
33viftype = ""
[24]34
[762]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
[1079]49    disk.append('phy:/dev/xenvg/s_install_hda,hdb,r')
[762]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'
[842]58    extra += (' ip=%s::%s:%s:%s:eth0:off'
[1079]59         % (n.ip, config.dhcp.gateway, config.dhcp.netmask, machine.name))
[762]60    extra += ' mirror=%s dist=%s' % (mirror, dist)
61    extra += ' imagesize=%s' % imagesize
[828]62    if 'noinstall' in locals():
63        extra += ' noinstall'
[762]64    root = '/dev/hdb1'
65    codepath = None
66elif 'cdrom_image' in locals():
67    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', cdrom_image))
[1079]68    disk.append('phy:/srv/images/' + cdrom_image + '.iso,hdc:cdrom,r')
[762]69    boot = 'd'
70    codepath = 'hvm'
71
72if codepath == 'hvm':
[65]73    ioemu = "ioemu:"
[101]74    viftype = "type=ioemu, "
[1016]75    kernel = '/usr/lib/xen/boot/hvmloader'
[65]76    builder = 'hvm'
77    vnc = 1
[104]78    vncpasswd = 'moocow'
79    device_model = '/usr/sbin/qemu-dm-sipb'
[762]80    serial = "pty"
81elif codepath == 'paravm':
82    bootloader = '/usr/lib/xen-default/bin/pygrub'
[65]83
84
85for n in machine.nics:
[109]86    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
[101]87    d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip)
[84]88    vif.append(d)
[65]89
[24]90for d in machine.disks:
[109]91    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
[146]92    device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
[65]93    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
[24]94    disk.append(dspec)
95
[433]96usbdevice = 'tablet'
97
[24]98on_poweroff = 'destroy'
99on_reboot = 'restart'
[109]100on_crash = 'destroy'
101if machine.autorestart:
102    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.