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.
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)
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):
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.