Made some changes requested by Broder.
[invirt/packages/invirt-remote.git] / server / usr / sbin / invirt-remote-create
index 3ec70a5..add3113 100755 (executable)
@@ -23,7 +23,7 @@ def maxMemory(owner, xmlist):
 
     active_machines = [m for m in machines if m.name in xmlist]
     mem_usage = sum([x.memory for x in active_machines])
 
     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.
 
 def choose_host():
     # Query each of the hosts.
@@ -37,7 +37,9 @@ def main(argv):
     operation = argv[1]
     machine_name = argv[2]
     args = argv[3:]
     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'))
     if operation == 'install':
         options = dict(arg.split('=', 1) for arg in args)
         valid_keys = set(('mirror', 'dist', 'arch', 'imagesize', 'noinstall'))
@@ -62,7 +64,6 @@ def main(argv):
         return 1
 
     if operation == "create":
         return 1
 
     if operation == "create":
-        invirt.database.connect()
         machine = invirt.database.Machine.query().filter_by(name=machine_name).first()
 
         owner = machine.owner
         machine = invirt.database.Machine.query().filter_by(name=machine_name).first()
 
         owner = machine.owner