+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.getMemoryQuotas(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)