Ignore:
Timestamp:
Apr 21, 2008, 7:14:17 PM (17 years ago)
Author:
ecprice
Message:

Cleaner HVM/paravm validation

Location:
trunk/packages/sipb-xen-www/code
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-www/code/controls.py

    r419 r437  
    100100    remctl('web', 'unregister', machine.name)
    101101
    102 def createVm(owner, contact, name, memory, disk_size, is_hvm, cdrom, clone_from):
     102def createVm(owner, contact, name, memory, disk_size, machine_type, cdrom, clone_from):
    103103    """Create a VM and put it in the database"""
    104104    # put stuff in the table
     
    120120        machine.uuid = uuidToString(randomUUID())
    121121        machine.boot_off_cd = True
    122         machine_type = Type.get_by(hvm=is_hvm)
    123122        machine.type_id = machine_type.type_id
    124123        ctx.current.save(machine)
  • trunk/packages/sipb-xen-www/code/main.py

    r432 r437  
    153153
    154154    vm_type = fields.getfirst('vmtype')
    155     if vm_type not in ('hvm', 'paravm'):
    156         raise CodeError("Invalid vm type '%s'"  % vm_type)   
    157     is_hvm = (vm_type == 'hvm')
     155    vm_type = validation.validVmType(vm_type)
    158156
    159157    cdrom = fields.getfirst('cdrom')
     
    166164   
    167165    return dict(contact=user, name=name, memory=memory, disk_size=disk_size,
    168                 owner=owner, is_hvm=is_hvm, cdrom=cdrom, clone_from=clone_from)
     166                owner=owner, machine_type=vm_type, cdrom=cdrom, clone_from=clone_from)
    169167
    170168def create(user, fields):
  • trunk/packages/sipb-xen-www/code/validation.py

    r431 r437  
    55import re
    66import string
    7 from sipb_xen_database import Machine, NIC
     7from sipb_xen_database import Machine, NIC, Type
    88from webcommon import InvalidInput, g
    99
     
    124124                           "Minimum %s GiB" % MIN_DISK_SINGLE)
    125125    return disk
    126            
     126
     127def validVmType(vm_type):
     128    if vm_type == 'hvm':
     129        return Type.get('linux-hvm')
     130    elif vm_type == 'paravm':
     131        return Type.get('linux')
     132    else:
     133        raise CodeError("Invalid vm type '%s'"  % vm_type)
     134
    127135def testMachineId(user, machine_id, exists=True):
    128136    """Parse, validate and check authorization for a given user and machine.
Note: See TracChangeset for help on using the changeset viewer.