pyroutefs api changes
[invirt/packages/invirt-remote.git] / server / usr / sbin / invirt-remote-create
index bae10c0..25a1120 100755 (executable)
@@ -18,12 +18,12 @@ 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)
+    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)
+    return min(quota_single, quota_total - mem_usage)
 
 def choose_host():
     # Query each of the hosts.
@@ -37,10 +37,12 @@ def main(argv):
     operation = argv[1]
     machine_name = argv[2]
     args = argv[3:]
-    
+
+    invirt.database.connect()
+
     if operation == 'install':
         options = dict(arg.split('=', 1) for arg in args)
-        valid_keys = set(('mirror', 'dist', 'arch', 'imagesize', 'noinstall'))
+        valid_keys = set(('mirror', 'dist', 'arch', 'imagesize', 'noinstall', 'preseed'))
         if not set(options.keys()).issubset(valid_keys):
             print >> sys.stderr, "Invalid argument. Use the help command to see valid arguments to install"
             return 1
@@ -62,15 +64,14 @@ def main(argv):
         return 1
 
     if operation == "create":
-        invirt.database.connect()
-        machine = invirt.database.Machine.query().filter_by(name=machine_name).first()
+        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)
+            print >>sys.stderr, "owner %s requested %d MiB of memory for vm %s; %d MiB allowed" % (owner, vm_memory, machine_name, max_memory)
             return 1
 
     host = choose_host()