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

Last change on this file since 1757 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
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)
[1090]21machine_type = machine.type
22cdrom = None
23if 'cdrom_image' in locals():
[1101]24    cdrom = models.CDROM.query().filter_by(cdrom_id=cdrom_image).one()
[1090]25    check(cdrom is not None)
[24]26
27memory = machine.memory
[1635]28maxmem = '2048'
[109]29check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
[146]30name = prefix + machine.name
[109]31check(re.match('^[0-9a-f-]+$', machine.uuid))
[24]32uuid = machine.uuid
33
34vcpus = machine.cpus
35
[65]36diskioemu = ""
37viftype = ""
[24]38
[762]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
[1091]52if 'installer_options' in locals(): #Installer
[1079]53    disk.append('phy:/dev/xenvg/s_install_hda,hdb,r')
[762]54
[1680]55    import os
56    release = os.uname()[2]
57    kernel = '/boot/vmlinuz-%s' % release
58    ramdisk = '/boot/initrd.img-%s' % release
[762]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'
[842]64    extra += (' ip=%s::%s:%s:%s:eth0:off'
[1079]65         % (n.ip, config.dhcp.gateway, config.dhcp.netmask, machine.name))
[1098]66    extra += ' %s' % installer_options
[762]67    root = '/dev/hdb1'
68    codepath = None
[1090]69elif cdrom is not None:
[1126]70    disk.append('phy:/dev/xenvg/image_' + cdrom.cdrom_id + ',hdc:cdrom,r')
[762]71    boot = 'd'
72    codepath = 'hvm'
73
74if codepath == 'hvm':
[65]75    ioemu = "ioemu:"
[101]76    viftype = "type=ioemu, "
[1016]77    kernel = '/usr/lib/xen/boot/hvmloader'
[65]78    builder = 'hvm'
79    vnc = 1
[104]80    vncpasswd = 'moocow'
[1262]81    device_model = '/usr/sbin/qemu-dm-invirt'
[762]82    serial = "pty"
83elif codepath == 'paravm':
[1107]84    bootloader = '/usr/bin/pygrub'
[65]85
86
87for n in machine.nics:
[109]88    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
[1636]89    d = '%smac=%s, ip=%s, script=vif-invirtroute netdev=eth2' % (viftype, n.mac_addr, n.ip)
[84]90    vif.append(d)
[65]91
[24]92for d in machine.disks:
[109]93    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
[146]94    device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
[65]95    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
[24]96    disk.append(dspec)
97
[433]98usbdevice = 'tablet'
99
[24]100on_poweroff = 'destroy'
101on_reboot = 'restart'
[109]102on_crash = 'destroy'
103if machine.autorestart:
104    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.