4 from routes import Mapper
9 from invirt import database
10 from invirt.config import structs as config
12 class RemConfFS(routefs.RouteFS):
14 RemConfFS creates a filesytem for configuring remctl, like this:
22 The machine list and the acls are drawn from a database.
24 This filesystem only implements the getattr, getdir, read, and readlink
25 calls, because this is a read-only filesystem.
28 def __init__(self, *args, **kw):
29 """Initialize the filesystem and set it to allow_other access besides
30 the user who mounts the filesystem (i.e. root)
32 super(RemConfFS, self).__init__(*args, **kw)
33 self.lasttime = time()
34 self.fuse_args.add("allow_other", True)
36 openlog('sipb-xen-remconffs ', LOG_PID, LOG_DAEMON)
38 syslog(LOG_DEBUG, 'Init complete.')
42 m.connect('', controller='getroot')
43 m.connect('acl/:machine', controller='getacl')
44 m.connect('conf', controller='getconf')
47 def getroot(self, **kw):
48 return ['acl', 'conf']
50 def getacl(self, machine, **kw):
51 """Build the ACL file for a machine
53 machine = database.Machine.get_by(name=machine)
54 users = [acl.user for acl in machine.acl]
55 return "\n".join(map(self.userToPrinc, users)
56 + ['include /etc/remctl/acl/web',
59 def getconf(self, **kw):
60 """Build the master conf file, with all machines
62 return '\n'.join("control %s /usr/sbin/sipb-xen-remote-proxy-control"
63 " /etc/remctl/remconffs/acl/%s"
64 % (machine_name, machine_name)
65 for machine_name in self.getMachines())+'\n'
67 def getMachines(self):
68 """Get the list of VMs in the database, clearing the cache if it's
69 older than 15 seconds"""
70 if time() - self.lasttime > 15:
71 self.lasttime = time()
72 database.clear_cache()
73 return [machine.name for machine in database.Machine.select()]
75 def userToPrinc(self, user):
76 """Convert Kerberos v4-style names to v5-style and append a default
77 realm if none is specified
80 (princ, realm) = user.split('@')
83 realm = config.authn[0].realm
85 return princ.replace('.', '/') + '@' + realm
87 if __name__ == '__main__':
89 routefs.main(RemConfFS)