Add real caching to consolefs, too
authorEvan Broder <broder@mit.edu>
Mon, 17 Nov 2008 18:20:02 +0000 (13:20 -0500)
committerEvan Broder <broder@mit.edu>
Mon, 17 Nov 2008 18:20:02 +0000 (13:20 -0500)
svn path=/trunk/packages/invirt-console-server/; revision=1699

debian/changelog
files/usr/bin/invirt-consolefs

index 9ccb877..27e67bf 100644 (file)
@@ -1,3 +1,9 @@
+invirt-console-server (0.1.0) unstable; urgency=low
+
+  * Add real caching to consolefs
+
+ -- Evan Broder <broder@mit.edu>  Mon, 17 Nov 2008 13:16:09 -0500
+
 invirt-console-server (0.0.13) unstable; urgency=low
 
   * Actually get the password fields right for libnss-pgsql
 invirt-console-server (0.0.13) unstable; urgency=low
 
   * Actually get the password fields right for libnss-pgsql
index 53c37d5..e092c21 100755 (executable)
@@ -26,13 +26,14 @@ class ConsoleFS(routefs.RouteFS):
                the user who mounts the filesystem (i.e. root)
                """
                super(ConsoleFS, self).__init__(*args, **kw)
                the user who mounts the filesystem (i.e. root)
                """
                super(ConsoleFS, self).__init__(*args, **kw)
-               self.lasttime = time()
+               self.lasttime = 0
+               self.machines = []
                self.fuse_args.add("allow_other", True)
                
                openlog('invirt-consolefs ', LOG_PID, LOG_DAEMON)
                
                syslog(LOG_DEBUG, 'Init complete.')
                self.fuse_args.add("allow_other", True)
                
                openlog('invirt-consolefs ', LOG_PID, LOG_DAEMON)
                
                syslog(LOG_DEBUG, 'Init complete.')
-
+       
        def make_map(self):
                m = Mapper()
                m.connect('', controller='getMachines')
        def make_map(self):
                m = Mapper()
                m.connect('', controller='getMachines')
@@ -41,13 +42,18 @@ class ConsoleFS(routefs.RouteFS):
                m.connect(':machine/*(path)', controller='getMirror')
                return m
        
                m.connect(':machine/*(path)', controller='getMirror')
                return m
        
-       def getMachines(self, **kw):
-               """Get the list of VMs in the database, clearing the cache if it's 
-               older than 15 seconds"""
+       def recache(self):
+               """Refresh the local cache of VMs if the cache is more than 15 minutes old
+               """
                if time() - self.lasttime > 15:
                        self.lasttime = time()
                        database.clear_cache()
                if time() - self.lasttime > 15:
                        self.lasttime = time()
                        database.clear_cache()
-               return [machine.name for machine in database.Machine.query()]
+                       self.machines = dict((machine.name, machine) for machine in database.session.query(database.Machine).all())
+
+       def getMachines(self, **kw):
+               """Get the list of VMs in the database"""
+               self.recache()
+               return self.machines.keys()
        
        def getMirror(self, machine, path='', **kw):
                """Translate the path into its realpath equivalent, and return that
        
        def getMirror(self, machine, path='', **kw):
                """Translate the path into its realpath equivalent, and return that
@@ -67,7 +73,8 @@ class ConsoleFS(routefs.RouteFS):
        def getK5login(self, machine, **kw):
                """Build the ACL for a machine and turn it into a .k5login file
                """
        def getK5login(self, machine, **kw):
                """Build the ACL for a machine and turn it into a .k5login file
                """
-               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) + [''])
        
                users = [acl.user for acl in machine.acl]
                return "\n".join(map(self.userToPrinc, users) + [''])