From 8ee0e3d4e4277a7d85f0d7470e798f76ff54d8be Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Mon, 17 Nov 2008 13:05:51 -0500 Subject: [PATCH] Add real caching to remconffs svn path=/trunk/packages/invirt-remote-server/; revision=1697 --- debian/changelog | 6 +++++ files/usr/sbin/invirt-remconffs | 51 +++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/debian/changelog b/debian/changelog index 5529c39..ef2016a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +invirt-remote-server (0.1.0) unstable; urgency=low + + * Add real caching to remconffs + + -- Evan Broder Mon, 17 Nov 2008 13:05:32 -0500 + invirt-remote-server (0.0.18) unstable; urgency=low * Add a "help" command for the control remctl diff --git a/files/usr/sbin/invirt-remconffs b/files/usr/sbin/invirt-remconffs index 384c791..d023749 100755 --- a/files/usr/sbin/invirt-remconffs +++ b/files/usr/sbin/invirt-remconffs @@ -18,7 +18,7 @@ class RemConfFS(routefs.RouteFS): | ... | `-- machinen `-- conf - + The machine list and the acls are drawn from a database. """ @@ -27,33 +27,40 @@ class RemConfFS(routefs.RouteFS): the user who mounts the filesystem (i.e. root) """ super(RemConfFS, self).__init__(*args, **kw) - self.lasttime = time() + self.lasttime = 0 self.fuse_args.add("allow_other", True) openlog('invirt-remconffs ', LOG_PID, LOG_DAEMON) syslog(LOG_DEBUG, 'Init complete.') - - def make_map(self): - m = Mapper() - m.connect('', controller='getroot') - m.connect('acl', controller='getmachines') - m.connect('acl/:machine', controller='getacl') - m.connect('conf', controller='getconf') - return m - - def getroot(self, **kw): - return ['acl', 'conf'] - + + def make_map(self): + m = Mapper() + m.connect('', controller='getroot') + m.connect('acl', controller='getmachines') + m.connect('acl/:machine', controller='getacl') + m.connect('conf', controller='getconf') + return m + + def recache(self): + if time() - self.lasttime > 15: + 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 """ - machine = database.Machine.query().filter_by(name=machine).one() + self.recache() + machine = self.machines[machine] users = [acl.user for acl in machine.acl] return "\n".join(map(self.userToPrinc, users) + ['include /etc/remctl/acl/web', - '']) - + '']) + def getconf(self, **kw): """Build the master conf file, with all machines """ @@ -65,11 +72,9 @@ class RemConfFS(routefs.RouteFS): def getmachines(self, **kw): """Get the list of VMs in the database, clearing the cache if it's older than 15 seconds""" - if time() - self.lasttime > 15: - self.lasttime = time() - database.clear_cache() - return [machine.name for machine in database.session.query(database.Machine).all()] - + self.recache() + return self.machines.keys() + def userToPrinc(self, user): """Convert Kerberos v4-style names to v5-style and append a default realm if none is specified @@ -84,4 +89,4 @@ class RemConfFS(routefs.RouteFS): if __name__ == '__main__': database.connect() - routefs.main(RemConfFS) + routefs.main(RemConfFS) -- 1.7.9.5