X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/blobdiff_plain/eabe84bd3f3ea514893ec700d598a06c2418f37e..refs/heads/dvorak42:/code/validation.py?ds=sidebyside diff --git a/code/validation.py b/code/validation.py index 18666be..4782fdb 100755 --- a/code/validation.py +++ b/code/validation.py @@ -16,7 +16,7 @@ MIN_DISK_SINGLE = 0.1 class Validate: def __init__(self, username, state, machine_id=None, name=None, description=None, owner=None, admin=None, contact=None, memory=None, disksize=None, - vmtype=None, cdrom=None, autoinstall=None, strict=False): + vmtype=None, nictype=None, cdrom=None, autoinstall=None, strict=False): # XXX Successive quota checks aren't a good idea, since you # can't necessarily change the locker and disk size at the # same time. @@ -56,6 +56,8 @@ class Validate: self.disksize = validDisk(self.owner, state, disksize, machine) if vmtype is not None: self.vmtype = validVmType(vmtype) + if nictype is not None: + self.nictype = validNICType(nictype) if cdrom is not None: if not CDROM.query.get(cdrom): raise CodeError("Invalid cdrom type '%s'" % cdrom) @@ -107,9 +109,10 @@ def maxDisk(owner, machine=None): machine_id = machine.machine_id else: machine_id = None - disk_usage = Disk.query.filter(Disk.c.machine_id != machine_id).\ - join('machine').\ - filter_by(owner=owner).sum(Disk.c.size) or 0 + disk_usage_query = Disk.query.filter(Disk.machine_id != machine_id).\ + join('machine').filter_by(owner=owner) + + disk_usage = sum([m.size for m in disk_usage_query]) or 0 return min(quota_single, quota_total-disk_usage/1024.) def cantAddVm(owner, g): @@ -186,6 +189,14 @@ def validVmType(vm_type): raise CodeError("Invalid vm type '%s'" % vm_type) return t +def validNICType(nic_type): + if nic_type is None: + return None + t = nic_type + if not (t is "e1000" or t is "pcnet"): + raise CodeError("Invalid nic type '%s'" % nic_type) + return t + def testMachineId(user, state, machine_id, exists=True): """Parse, validate and check authorization for a given user and machine.