invirt-remote (0.3.4) unstable; urgency=low
* modified host/usr/sbin/invirt-availability and invirt-vmcontrol to stat
- /etc/invirt/nocreate; if it exists, they advertise zero free memory and
+ /etc/invirt/nocreate; if it exists, they advertise zero free memory and
refuse to create VMs
+ * added memory quota validation to invirt-remote-create
+ * added owner table to database with ram_quota_total and ram_quota_single
- -- Peter A. Iannucci <iannucci@mit.edu> Sat, 14 Feb 2009 18:10:54 -0500
+ -- Peter A. Iannucci <iannucci@mit.edu> Mon, 16 Feb 2009 23:49:14 -0500
invirt-remote (0.3.3) unstable; urgency=low
from subprocess import PIPE, Popen, call
import sys
import yaml
+import invirt.database
+
+def maxMemory(owner, xmlist):
+ """
+ Return the memory available for a new machine.
+ """
+ machines = invirt.database.Machine.query().filter_by(owner=owner)
+ (quota_total, quota_single) = invirt.database.Owner.getQuotas(owner)
+
+ active_machines = [m for m in machines if m.name in xmlist]
+ mem_usage = sum([x.memory for x in active_machines])
+ return min(quota_single, quota_total-mem_usage)
def choose_host():
# Query each of the hosts.
% (machine_name, host))
return 1
+ if operation == "create":
+ invirt.database.connect()
+ machine = invirt.database.Machine.query().filter_by(name=machine_name).first()
+
+ owner = machine.owner
+ vm_memory = machine.memory
+
+ max_memory = maxMemory(owner, vms.keys())
+ if vm_memory > max_memory:
+ print >>sys.stderr, "owner %s requested %d MB of memory for vm %s; %d MB allowed" % (owner, vm_memory, machine_name, max_memory)
+ return 1
+
host = choose_host()
print 'Creating on host %s...' % host
sys.stdout.flush()