Changeset 109 for trunk


Ignore:
Timestamp:
Oct 7, 2007, 2:45:37 AM (17 years ago)
Author:
andersk
Message:

Add cdrom_image parameter; do some simple regex sanity checking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-database/sipb-xen-database/client/etc/xen/sipb-database

    r104 r109  
    22import sipb_xen_database.models as models
    33from sipb_xen_database import connect
     4import re
     5import sys
    46
    57connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
    6 # `machine_name' should get passed in from the xm create call
     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        exit(1)
    715
    816machine = models.Machine.get_by(name=machine_name)
     17check(machine is not None)
    918machine_type = models.Type.get_by(type_id=machine.type_id)
    1019
    1120memory = machine.memory
    1221maxmem = memory
     22check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
    1323name = machine.name
     24check(re.match('^[0-9a-f-]+$', machine.uuid))
    1425uuid = machine.uuid
    1526
     
    4051
    4152for n in machine.nics:
     53    check(re.match('^[0-9a-fA-F:]+$', n.mac_addr) and re.match('^[0-9.]*$', n.ip))
    4254    d = '%smac=%s, ip=%s, bridge=xenbr0, script=vif-sipbroute' % (viftype, n.mac_addr, n.ip)
    4355    vif.append(d)
     
    4658
    4759for d in machine.disks:
     60    check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
    4861    device = '/dev/xenvg/' + machine.name + '_' + d.guest_device_name
    4962    dspec = 'phy:%s,%s%s,w' % (device, diskioemu, d.guest_device_name)
    5063    disk.append(dspec)
    5164
    52 restart = 'destroy'
    53 if machine.autorestart:
    54     restart = 'restart'
     65if 'cdrom_image' in locals():
     66    check(re.match('^[A-Za-z0-9][A-Za-z0-9_.-]*$', cdrom_image))
     67    disk.append('file:/srv/images/' + cdrom_image + '.iso,hdc:cdrom,r')
     68    boot = 'd'
    5569
    5670on_poweroff = 'destroy'
    5771on_reboot = 'restart'
    58 on_crash = restart
     72on_crash = 'destroy'
     73if machine.autorestart:
     74    on_crash = 'restart'
Note: See TracChangeset for help on using the changeset viewer.