X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-remote.git/blobdiff_plain/4f84d6e9bdc80384ba10ac535870b724c0cf1cf9..c2ef438b4260463f5294e5236d9b66bb9f4f5592:/files/usr/sbin/invirt-remconffs diff --git a/files/usr/sbin/invirt-remconffs b/files/usr/sbin/invirt-remconffs index f4d88b8..6389391 100755 --- a/files/usr/sbin/invirt-remconffs +++ b/files/usr/sbin/invirt-remconffs @@ -5,6 +5,7 @@ from routes import Mapper from syslog import * from time import time +import sqlalchemy as sa from invirt import database from invirt.config import structs as config @@ -27,7 +28,6 @@ class RemConfFS(routefs.RouteFS): the user who mounts the filesystem (i.e. root) """ super(RemConfFS, self).__init__(*args, **kw) - self.lasttime = 0 self.fuse_args.add("allow_other", True) openlog('invirt-remconffs ', LOG_PID, LOG_DAEMON) @@ -42,22 +42,20 @@ class RemConfFS(routefs.RouteFS): m.connect('conf', controller='getconf') return m - def recache(self): - if time() - self.lasttime > 5: - self.lasttime = time() - database.clear_cache() - self.machines = dict((machine.name, machine) for machine in database.session.query(database.Machine).all()) - def getroot(self, **kw): return ['acl', 'conf'] def getacl(self, machine, **kw): """Build the ACL file for a machine """ - self.recache() - machine = self.machines[machine] - users = [acl.user for acl in machine.acl] - return "\n".join(map(self.userToPrinc, users) + s = sa.sql.select([database.machine_access_table.c.user], # Field to select from + sa.sql.and_( # where clause + database.machine_table.c.machine_id==database.machine_access_table.c.machine_id, # join field + database.machine_table.c.name == machine), # filter field + from_obj=[database.machine_access_table, database.machine_table]) # from tables + users = [self.userToPrinc(acl[0]) for acl in + database.session.execute(s)] + return "\n".join(users + ['include /etc/remctl/acl/web', '']) @@ -70,10 +68,8 @@ class RemConfFS(routefs.RouteFS): for machine_name in self.getmachines())+'\n' def getmachines(self, **kw): - """Get the list of VMs in the database, clearing the cache if it's - older than 15 seconds""" - self.recache() - return self.machines.keys() + """Get the list of VMs in the database. Does not cache to prevent race conditions.""" + return list(row[0] for row in database.session.execute(sa.sql.select([database.Machine.c.name]))) def userToPrinc(self, user): """Convert Kerberos v4-style names to v5-style and append a default