Ignore:
Timestamp:
Feb 16, 2009, 11:52:01 PM (16 years ago)
Author:
iannucci
Message:

RAM quotas at remctl; RAM quota exception script, table, and usage in -web and -remote-create; /etc/nocreate support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-remote/server/usr/sbin/invirt-remote-create

    r2106 r2132  
    1313import sys
    1414import yaml
     15import invirt.database
     16
     17def maxMemory(owner, xmlist):
     18    """
     19    Return the memory available for a new machine.
     20    """
     21    machines = invirt.database.Machine.query().filter_by(owner=owner)
     22    (quota_total, quota_single) = invirt.database.Owner.getQuotas(owner)
     23
     24    active_machines = [m for m in machines if m.name in xmlist]
     25    mem_usage = sum([x.memory for x in active_machines])
     26    return min(quota_single, quota_total-mem_usage)
    1527
    1628def choose_host():
     
    5062        return 1
    5163
     64    if operation == "create":
     65        invirt.database.connect()
     66        machine = invirt.database.Machine.query().filter_by(name=machine_name).first()
     67
     68        owner = machine.owner
     69        vm_memory = machine.memory
     70
     71        max_memory = maxMemory(owner, vms.keys())
     72        if vm_memory > max_memory:
     73            print >>sys.stderr, "owner %s requested %d MB of memory for vm %s; %d MB allowed" % (owner, vm_memory, machine_name, max_memory)
     74            return 1
     75
    5276    host = choose_host()
    5377    print 'Creating on host %s...' % host
Note: See TracChangeset for help on using the changeset viewer.