From 2248234ffe4df0cfb4d839c12fa7694e40bcb924 Mon Sep 17 00:00:00 2001 From: Peter Iannucci Date: Mon, 16 Feb 2009 23:52:01 -0500 Subject: [PATCH] RAM quotas at remctl; RAM quota exception script, table, and usage in -web and -remote-create; /etc/nocreate support svn path=/trunk/packages/invirt-remote/; revision=2132 --- debian/changelog | 6 ++++-- server/usr/sbin/invirt-remote-create | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 53994ea..1c55796 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,10 +1,12 @@ 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 Sat, 14 Feb 2009 18:10:54 -0500 + -- Peter A. Iannucci Mon, 16 Feb 2009 23:49:14 -0500 invirt-remote (0.3.3) unstable; urgency=low diff --git a/server/usr/sbin/invirt-remote-create b/server/usr/sbin/invirt-remote-create index 991b3c8..bae10c0 100755 --- a/server/usr/sbin/invirt-remote-create +++ b/server/usr/sbin/invirt-remote-create @@ -12,6 +12,18 @@ from invirt.remote import bcast 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. @@ -49,6 +61,18 @@ def main(argv): % (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() -- 1.7.9.5