Remove extraneous whitespace and add documentation
[invirt/packages/invirt-web.git] / code / validation.py
index 4886638..a2e19fe 100644 (file)
@@ -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.
 
@@ -162,7 +170,10 @@ def testAdmin(user, admin, machine):
         if user in getafsgroups.getAfsGroupMembers(admin, 'athena.mit.edu'):
             return admin
     except getafsgroups.AfsProcessError, e:
-        raise InvalidInput('administrator', admin, str(e))
+        errmsg = str(e)
+        if errmsg.startswith("pts: User or group doesn't exist"):
+            errmsg = 'The group "%s" does not exist.' % admin
+        raise InvalidInput('administrator', admin, errmsg)
     #XXX Should we require that user is in the admin group?
     return admin