Ignore VMs that have administrator set to a deactivated user, even though that causes...
[invirt/scripts/outage.git] / invirt-deactivate
index 2bfcb79..529d081 100644 (file)
@@ -69,7 +69,8 @@ def main():
     database.session.commit()
 
     database.session.begin()
-    machines_no_access = database.session.query(database.Machine).filter(~database.Machine.acl.any()).all()
+    acl_locker_no_err = database.session.query(database.MachineAccess.machine_id).outerjoin(Locker, database.MachineAccess.user == Locker.name).filter((Locker.type == None) | (Locker.type != "ERR")).group_by(database.MachineAccess.machine_id).subquery()
+    machines_no_access = database.session.query(database.Machine).outerjoin(acl_locker_no_err).filter(acl_locker_no_err.c.machine_id == None).all()
 
     machines_no_locker = database.session.query(database.Machine).join(Locker, database.Machine.owner == Locker.name).filter(Locker.type == None).all()
     machines_err_locker = database.session.query(database.Machine, Locker.message).join(Locker, database.Machine.owner == Locker.name).filter(Locker.type == 'ERR').all()