Cleaner HVM/paravm validation
authorEric Price <ecprice@mit.edu>
Mon, 21 Apr 2008 23:14:17 +0000 (19:14 -0400)
committerEric Price <ecprice@mit.edu>
Mon, 21 Apr 2008 23:14:17 +0000 (19:14 -0400)
svn path=/trunk/packages/sipb-xen-www/; revision=437

code/controls.py
code/main.py
code/validation.py

index 2aeb924..14ba689 100644 (file)
@@ -99,7 +99,7 @@ def unregisterMachine(machine):
     """Unregister a machine to not be controlled by the web interface"""
     remctl('web', 'unregister', machine.name)
 
     """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()
     """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.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, 
         machine.type_id = machine_type.type_id
         ctx.current.save(machine)
         disk = Disk(machine_id=machine.machine_id, 
index c0e9a98..df2ef4e 100755 (executable)
@@ -152,9 +152,7 @@ def parseCreate(user, fields):
     disk_size = validation.validDisk(owner, disk_size)
 
     vm_type = fields.getfirst('vmtype')
     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):
 
     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,
         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."""
 
 def create(user, fields):
     """Handler for create requests."""
index 3f05017..a2e19fe 100644 (file)
@@ -4,7 +4,7 @@ import cache_acls
 import getafsgroups
 import re
 import string
 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
 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
         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.
 
 def testMachineId(user, machine_id, exists=True):
     """Parse, validate and check authorization for a given user and machine.