From: Eric Price Date: Mon, 21 Apr 2008 23:14:17 +0000 (-0400) Subject: Cleaner HVM/paravm validation X-Git-Tag: sipb-xen-www/3.4~29 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/commitdiff_plain/fa88b9bd09fdc75e26422604bb2b74821e3a9b07?ds=sidebyside Cleaner HVM/paravm validation svn path=/trunk/packages/sipb-xen-www/; revision=437 --- diff --git a/code/controls.py b/code/controls.py index 2aeb924..14ba689 100644 --- a/code/controls.py +++ b/code/controls.py @@ -99,7 +99,7 @@ def unregisterMachine(machine): """Unregister a machine to not be controlled by the web interface""" remctl('web', 'unregister', machine.name) -def createVm(owner, contact, name, memory, disk_size, is_hvm, cdrom, clone_from): +def createVm(owner, contact, name, memory, disk_size, machine_type, cdrom, clone_from): """Create a VM and put it in the database""" # put stuff in the table transaction = ctx.current.create_transaction() @@ -119,7 +119,6 @@ def createVm(owner, contact, name, memory, disk_size, is_hvm, cdrom, clone_from) machine.contact = contact machine.uuid = uuidToString(randomUUID()) machine.boot_off_cd = True - machine_type = Type.get_by(hvm=is_hvm) machine.type_id = machine_type.type_id ctx.current.save(machine) disk = Disk(machine_id=machine.machine_id, diff --git a/code/main.py b/code/main.py index c0e9a98..df2ef4e 100755 --- a/code/main.py +++ b/code/main.py @@ -152,9 +152,7 @@ def parseCreate(user, fields): disk_size = validation.validDisk(owner, disk_size) vm_type = fields.getfirst('vmtype') - if vm_type not in ('hvm', 'paravm'): - raise CodeError("Invalid vm type '%s'" % vm_type) - is_hvm = (vm_type == 'hvm') + vm_type = validation.validVmType(vm_type) cdrom = fields.getfirst('cdrom') if cdrom is not None and not CDROM.get(cdrom): @@ -165,7 +163,7 @@ def parseCreate(user, fields): raise CodeError("Invalid clone image '%s'" % clone_from) return dict(contact=user, name=name, memory=memory, disk_size=disk_size, - owner=owner, is_hvm=is_hvm, cdrom=cdrom, clone_from=clone_from) + owner=owner, machine_type=vm_type, cdrom=cdrom, clone_from=clone_from) def create(user, fields): """Handler for create requests.""" diff --git a/code/validation.py b/code/validation.py index 3f05017..a2e19fe 100644 --- a/code/validation.py +++ b/code/validation.py @@ -4,7 +4,7 @@ import cache_acls import getafsgroups import re import string -from sipb_xen_database import Machine, NIC +from sipb_xen_database import Machine, NIC, Type from webcommon import InvalidInput, g MAX_MEMORY_TOTAL = 512 @@ -123,7 +123,15 @@ def validDisk(user, disk, machine=None): raise InvalidInput('disk', disk, "Minimum %s GiB" % MIN_DISK_SINGLE) return disk - + +def validVmType(vm_type): + if vm_type == 'hvm': + return Type.get('linux-hvm') + elif vm_type == 'paravm': + return Type.get('linux') + else: + raise CodeError("Invalid vm type '%s'" % vm_type) + def testMachineId(user, machine_id, exists=True): """Parse, validate and check authorization for a given user and machine.