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.')
-
+
def make_map(self):
m = Mapper()
m.connect('', controller='getMachines')
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"""
- if time() - self.lasttime > 15:
+ def recache(self):
+ """Refresh the local cache of VMs if the cache is more than 15 minutes old
+ """
+ if time() - self.lasttime > 5:
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 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) + [''])