Ignore:
Timestamp:
May 15, 2008, 9:55:17 PM (16 years ago)
Author:
ecprice
Message:

Use joins, new xmlist.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-www/code/validation.py

    r440 r535  
    55import re
    66import string
    7 from sipb_xen_database import Machine, NIC, Type
     7from sipb_xen_database import Machine, NIC, Type, Disk
    88from webcommon import InvalidInput, g
    99
     
    4545        return MAX_MEMORY_SINGLE
    4646    machines = getMachinesByOwner(user, machine)
    47     active_machines = [x for x in machines if g.uptimes.get(x)]
     47    active_machines = [x for x in machines if g.xmlist.get(x)]
    4848    mem_usage = sum([x.memory for x in active_machines if x != machine])
    4949    return min(MAX_MEMORY_SINGLE, MAX_MEMORY_TOTAL-mem_usage)
     
    5555    return the maximum that a given machine can be changed to.
    5656    """
    57     machines = getMachinesByOwner(user, machine)
    58     disk_usage = sum([sum([y.size for y in x.disks])
    59                       for x in machines if x != machine])
     57    if machine is not None:
     58        machine_id = machine.machine_id
     59    else:
     60        machine_id = None
     61    disk_usage = Disk.query().filter_by(Disk.c.machine_id != machine_id,
     62                                        owner=user).sum(Disk.c.size)
    6063    return min(MAX_DISK_SINGLE, MAX_DISK_TOTAL-disk_usage/1024.)
    6164
    6265def cantAddVm(user):
    6366    machines = getMachinesByOwner(user)
    64     active_machines = [x for x in machines if g.uptimes.get(x)]
     67    active_machines = [x for x in machines if g.xmlist.get(x)]
    6568    if len(machines) >= MAX_VMS_TOTAL:
    6669        return 'You have too many VMs to create a new one.'
Note: See TracChangeset for help on using the changeset viewer.