Make invirt-lvm lvcreate-all use sqlalchemy correctly.
[invirt/packages/invirt-remote.git] / host / usr / sbin / invirt-lvm
index cae6b2b..6860d9c 100755 (executable)
@@ -31,12 +31,12 @@ if machine_specific:
     lvpath = "/dev/" + vg + "/" + lvname
 
 if subcommand == "lvcreate-all":
     lvpath = "/dev/" + vg + "/" + lvname
 
 if subcommand == "lvcreate-all":
-    from invirt import database
+    from invirt.database import models, connect
     import re
     import re
-    database.connect()
-    for d in Disk.select():
+    connect()
+    for d in models.Disk.query().all():
         check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
         check(re.match('^[A-Za-z0-9]+$', d.guest_device_name))
-        machine = Machine.get(d.machine_id)
+        machine = models.Machine.query().filter_by(machine_id=d.machine_id).one()
         check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
         lvname = prefix + machine.name + "_" + d.guest_device_name
         if not os.path.exists("/dev/%s/%s" % (vg, lvname)):
         check(re.match('^[A-Za-z0-9][A-Za-z0-9._-]*$', machine.name))
         lvname = prefix + machine.name + "_" + d.guest_device_name
         if not os.path.exists("/dev/%s/%s" % (vg, lvname)):