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

Last change on this file since 223 was 223, checked in by price, 17 years ago

new remctl command "install" to invoke autoinstaller

e.g.,

$ remctl black-mesa control moobarspam install etch /path/to/rootpasshash

The root password to be used is taken from a given file local to black-mesa...
probably this should be in the database or something, randomly generated
by the web interface, and available for reminders.

File size: 2.3 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)
[65]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
[65]35if machine_type.hvm:
36    ioemu = "ioemu:"
[101]37    viftype = "type=ioemu, "
[65]38
39    kernel = 'hvmloader'
40    builder = 'hvm'
41    vnc = 1
[104]42    vncpasswd = 'moocow'
43    device_model = '/usr/sbin/qemu-dm-sipb'
[65]44else:
45    kernel  = '/boot/vmlinuz-2.6.18-4-xen-amd64'
46    ramdisk = '/boot/initrd.img-2.6.18-4-xen-amd64'
47    builder = 'linux'
48
49pae = machine_type.pae
50acpi = machine_type.acpi
51apic = machine_type.apic
52
53vif = []
54
55for n in machine.nics:
[109]56    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
[101]57    d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip)
[84]58    vif.append(d)
[65]59
[24]60disk = []
61
62for d in machine.disks:
[109]63    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
[146]64    device = '/dev/xenvg/' + prefix + machine.name + '_' + d.guest_device_name
[65]65    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
[24]66    disk.append(dspec)
67
[223]68if 'installer' in locals():
69    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', installer))
70    tmptree = tempfile.mkdtemp('', 'auto-install.', '/tmp')
71    call(['/usr/sbin/sipb-xen-make-iso', installer, tmptree]
72         + installer_options.split(' '))
73    disk.append('file:'+tmptree+'/install.iso,hdc:cdrom,r')
74    boot = 'd'
75   
76elif 'cdrom_image' in locals():
[109]77    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', cdrom_image))
78    disk.append('file:/srv/images/' + cdrom_image + '.iso,hdc:cdrom,r')
79    boot = 'd'
[24]80
81on_poweroff = 'destroy'
82on_reboot = 'restart'
[109]83on_crash = 'destroy'
84if machine.autorestart:
85    on_crash = 'restart'
Note: See TracBrowser for help on using the repository browser.