source: trunk/packages/invirt-xen-config/invirt-database @ 1693

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

Choose what kernel to use for the autoinstaller based on what dom0 is
running

File size: 2.6 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(cdrom_id=cdrom_image).one()
25    check(cdrom is not None)
26
27memory = machine.memory
28maxmem = '2048'
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 'installer_options' in locals(): #Installer
53    disk.append('phy:/dev/xenvg/s_install_hda,hdb,r')
54
55    import os
56    release = os.uname()[2]
57    kernel = '/boot/vmlinuz-%s' % release
58    ramdisk = '/boot/initrd.img-%s' % release
59
60    if not machine.nics:
61        raise RuntimeError('You must have a nic to autoinstall')
62    n = machine.nics[0]
63    extra = 'ro noresume'
64    extra += (' ip=%s::%s:%s:%s:eth0:off'
65         % (n.ip, config.dhcp.gateway, config.dhcp.netmask, machine.name))
66    extra += ' %s' % installer_options
67    root = '/dev/hdb1'
68    codepath = None
69elif cdrom is not None:
70    disk.append('phy:/dev/xenvg/image_' + cdrom.cdrom_id + ',hdc:cdrom,r')
71    boot = 'd'
72    codepath = 'hvm'
73
74if codepath == 'hvm':
75    ioemu = "ioemu:"
76    viftype = "type=ioemu, "
77    kernel = '/usr/lib/xen/boot/hvmloader'
78    builder = 'hvm'
79    vnc = 1
80    vncpasswd = 'moocow'
81    device_model = '/usr/sbin/qemu-dm-invirt'
82    serial = "pty"
83elif codepath == 'paravm':
84    bootloader = '/usr/bin/pygrub'
85
86
87for n in machine.nics:
88    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
89    d = '%smac=%s, ip=%s, script=vif-invirtroute netdev=eth2' % (viftype, n.mac_addr, n.ip)
90    vif.append(d)
91
92for d in machine.disks:
93    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
94    device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
95    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
96    disk.append(dspec)
97
98usbdevice = 'tablet'
99
100on_poweroff = 'destroy'
101on_reboot = 'restart'
102on_crash = 'destroy'
103if machine.autorestart:
104    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.