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

Last change on this file since 2336 was 2055, checked in by price, 16 years ago

eth2 -> config.xen.network.iface

File size: 2.6 KB
Line 
1# -*- mode: python; -*-
2from invirt.database import models, connect
3from invirt.config import structs as config
4import re
5
6connect()
7prefix = "d_"
8
9# 'machine_name', and optionally 'cdrom_image', should get passed in
10# from the xm create call
11
12def check(b):
13    if not b:
14        import sys
15        sys.exit(1)
16
17machine = models.Machine.query().filter_by(name=machine_name).one()
18check(machine is not None)
19machine_type = machine.type
20cdrom = None
21if 'cdrom_image' in locals():
22    cdrom = models.CDROM.query().filter_by(cdrom_id=cdrom_image).one()
23    check(cdrom is not None)
24
25memory = machine.memory
26maxmem = '2048'
27check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
28name = prefix + machine.name
29check(re.match('^[0-9a-f-]+$', machine.uuid))
30uuid = machine.uuid
31
32vcpus = machine.cpus
33
34diskioemu = ""
35viftype = ""
36
37pae = machine_type.pae
38acpi = machine_type.acpi
39apic = machine_type.apic
40
41vif = []
42
43disk = []
44
45if machine_type.hvm:
46    codepath = 'hvm'
47else:
48    codepath = 'paravm'
49
50if 'installer_options' in locals(): #Installer
51    disk.append('phy:/dev/xenvg/s_install_hda,hdb,r')
52
53    import os
54    release = os.uname()[2]
55    kernel = '/boot/vmlinuz-%s' % release
56    ramdisk = '/boot/initrd.img-%s' % release
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 += ' %s' % installer_options
65    root = '/dev/hdb1'
66    codepath = None
67elif cdrom is not None:
68    disk.append('phy:/dev/xenvg/image_' + cdrom.cdrom_id + ',hdc:cdrom,r')
69    boot = 'd'
70    codepath = 'hvm'
71
72if codepath == 'hvm':
73    ioemu = "ioemu:"
74    viftype = "type=ioemu, "
75    kernel = '/usr/lib/xen/boot/hvmloader'
76    builder = 'hvm'
77    vnc = 1
78    vncpasswd = 'moocow'
79    device_model = '/usr/sbin/qemu-dm-invirt'
80    serial = "pty"
81elif codepath == 'paravm':
82    bootloader = '/usr/bin/pygrub'
83
84
85for n in machine.nics:
86    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
87    d = ('%smac=%s, ip=%s, script=vif-invirtroute netdev=%s'
88         % (viftype, n.mac_addr, n.ip, config.xen.network.iface))
89    vif.append(d)
90
91for d in machine.disks:
92    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
93    device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
94    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
95    disk.append(dspec)
96
97usbdevice = 'tablet'
98
99on_poweroff = 'destroy'
100on_reboot = 'restart'
101on_crash = 'destroy'
102if machine.autorestart:
103    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.