X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/blobdiff_plain/a3265b122f84437fa9f63fd26297b5b616abd16f..f79a27b745530799a75d21a66945e9dc8178e772:/cache_acls.py diff --git a/cache_acls.py b/cache_acls.py index 3b68129..e0094e8 100644 --- a/cache_acls.py +++ b/cache_acls.py @@ -33,17 +33,28 @@ def expandName(name): if __name__ == '__main__': connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen') - machines = Machine.select() - for m in machines: - people = set() - people.update(expandLocker(m.owner)) - people.update(expandName(m.administrator)) - print '%s: %s' % (m.name, ' '.join(people)) - transaction = ctx.current.create_transaction() - for u in m.users: - ctx.current.delete(u) - for p in people: - ma = MachineAccess(machine_id=m.machine_id, user=p) - ctx.current.save(ma) - ctx.current.flush() + transaction = ctx.current.create_transaction() + + print repr(ctx), repr(ctx.current), repr(transaction) + # Remove existing machine access entries + machine_access_table.delete() + ctx.current.flush() + + try: + machines = Machine.select() + for m in machines: + people = set() + people.update(expandLocker(m.owner)) + people.update(expandName(m.administrator)) + print '%s: %s' % (m.name, ' '.join(people)) + for p in people: + ma = MachineAccess(machine_id=m.machine_id, user=p) + ctx.current.save(ma) + ctx.current.flush() + + # Atomically execute our changes transaction.commit() + except: + # Failed! Rollback all the changes. + transaction.rollback() + raise