Changeset 2132 for trunk/packages/invirt-remote/server/usr
- Timestamp:
- Feb 16, 2009, 11:52:01 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/invirt-remote/server/usr/sbin/invirt-remote-create
r2106 r2132 13 13 import sys 14 14 import yaml 15 import invirt.database 16 17 def 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) 15 27 16 28 def choose_host(): … … 50 62 return 1 51 63 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 52 76 host = choose_host() 53 77 print 'Creating on host %s...' % host
Note: See TracChangeset
for help on using the changeset viewer.