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

Last change on this file since 803 was 762, checked in by ecprice, 16 years ago

Add autoinstall to sipb-database.

File size: 2.6 KB
RevLine 
[101]1# -*- mode: python; -*-
[24]2import sipb_xen_database.models as models
[85]3from sipb_xen_database import connect
[109]4import re
[223]5import tempfile
6from subprocess import call
[24]7
[99]8connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
[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
[85]19machine = models.Machine.get_by(name=machine_name)
[109]20check(machine is not None)
[762]21machine_type = models.Type.get_by(type_id=machine.type_id)
[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
49    disk.append('phy:/dev/xenvg/d_foobar4_hda,hdb,r')
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'
58    extra += ' ip=%s::18.181.0.1:255.255.0.0:%s:eth0:off' % (n.ip, machine.name)
59    extra += ' mirror=%s dist=%s' % (mirror, dist)
60    extra += ' imagesize=%s' % imagesize
61    #extra += ' noinstall'
62    root = '/dev/hdb1'
63    codepath = None
64elif 'cdrom_image' in locals():
65    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', cdrom_image))
66    disk.append('file:/srv/images/' + cdrom_image + '.iso,hdc:cdrom,r')
67    boot = 'd'
68    codepath = 'hvm'
69
70if codepath == 'hvm':
[65]71    ioemu = "ioemu:"
[101]72    viftype = "type=ioemu, "
[65]73    kernel = 'hvmloader'
74    builder = 'hvm'
75    vnc = 1
[104]76    vncpasswd = 'moocow'
77    device_model = '/usr/sbin/qemu-dm-sipb'
[762]78    serial = "pty"
79elif codepath == 'paravm':
80    bootloader = '/usr/lib/xen-default/bin/pygrub'
[65]81
82
83for n in machine.nics:
[109]84    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
[101]85    d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip)
[84]86    vif.append(d)
[65]87
[24]88for d in machine.disks:
[109]89    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
[146]90    device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
[65]91    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
[24]92    disk.append(dspec)
93
[433]94usbdevice = 'tablet'
95
[24]96on_poweroff = 'destroy'
97on_reboot = 'restart'
[109]98on_crash = 'destroy'
99if machine.autorestart:
100    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.