X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-remote.git/blobdiff_plain/58921ff93c77f71a30aba863dea5a9a89b403585..7a893acaab41404dd60009ca538d3bce95178be2:/files/usr/sbin/sipb-xen-remconffs?ds=sidebyside diff --git a/files/usr/sbin/sipb-xen-remconffs b/files/usr/sbin/sipb-xen-remconffs index 03099d6..0f94a94 100755 --- a/files/usr/sbin/sipb-xen-remconffs +++ b/files/usr/sbin/sipb-xen-remconffs @@ -12,7 +12,8 @@ import errno # for error number codes (ENOENT, etc) from syslog import * -import sipb_xen_database +from invirt import database +from invirt.config import structs as config fuse.fuse_python_api = (0, 2) @@ -92,31 +93,25 @@ class RemConfFS(Fuse): older than 15 seconds""" if time() - self.lasttime > 15: self.lasttime = time() - sipb_xen_database.clear_cache() - return [machine.name for machine in sipb_xen_database.Machine.select()] + database.clear_cache() + return [machine.name for machine in database.Machine.select()] def getacl(self, machine_name): """Build the ACL file for a machine """ - machine = sipb_xen_database.Machine.get_by(name=machine_name) + machine = database.Machine.get_by(name=machine_name) users = [acl.user for acl in machine.acl] return "\n".join(map(self.userToPrinc, users) + ['include /etc/remctl/acl/web', '']) - def getconf(self, machine_name): - """Build the command file for a machine + def getconf(self): + """Build the master conf file, with all machines """ - return ("control %s /usr/sbin/sipb-xen-remote-proxy-control" - " /etc/remctl/sipb-xen-auto/acl/%s\n" - % (machine_name, machine_name)) - - def getfile(self, dir, machine_name): - """Build the ACL or command file for a machine - """ - if dir == 'acl': return self.getacl(machine_name) - if dir == 'conf.d': return self.getconf(machine_name) - raise "this shouldn't happen" + return '\n'.join("control %s /usr/sbin/sipb-xen-remote-proxy-control" + " /etc/remctl/remconffs/acl/%s" + % (machine_name, machine_name) + for machine_name in self.getMachines())+'\n' def userToPrinc(self, user): """Convert Kerberos v4-style names to v5-style and append a default @@ -126,7 +121,7 @@ class RemConfFS(Fuse): (princ, realm) = user.split('@') else: princ = user - realm = "ATHENA.MIT.EDU" + realm = config.authn[0].realm return princ.replace('.', '/') + '@' + realm @@ -155,18 +150,23 @@ class RemConfFS(Fuse): st.st_mode = stat.S_IFDIR | 0755 st.st_nlink = 2 elif depth == 1: - if parts[0] not in ('acl', 'conf.d'): + if parts[0] == 'acl': + st.st_mode = stat.S_IFDIR | 0755 + st.st_nlink = 2 + elif parts[0] == 'conf': + st.st_mode = stat.S_IFREG | 0444 + st.st_nlink = 1 + st.st_size = len(self.getconf()) + else: return -errno.ENOENT - st.st_mode = stat.S_IFDIR | 0755 - st.st_nlink = 2 elif depth == 2: - if parts[0] not in ('acl', 'conf.d'): + if parts[0] != 'acl': return -errno.ENOENT if parts[1] not in self.getMachines(): return -errno.ENOENT st.st_mode = stat.S_IFREG | 0444 st.st_nlink = 1 - st.st_size = len(self.getfile(parts[0], parts[1])) + st.st_size = len(self.getacl(parts[1])) return st.toTuple() @@ -190,9 +190,9 @@ class RemConfFS(Fuse): parts, depth = parse(path) if depth == 0: - contents = ('acl', 'conf.d') + contents = ('acl', 'conf') elif depth == 1: - if parts[0] in ('acl', 'conf.d'): + if parts[0] == 'acl': contents = self.getMachines() else: return -errno.ENOENT @@ -211,16 +211,15 @@ class RemConfFS(Fuse): parts, depth = parse(path) - # If the depth is not 2, then either it's a directory or the file - # doesn't exist - # (realistically this doesn't appear to ever happen) - if getDepth(path) != 2: - return -errno.ENOENT - elif parts[1] in self.getMachines(): - if parts[0] == 'acl': + if depth == 0: + return -errno.EISDIR + elif parts[0] == 'conf': + return self.getconf()[offset:offset+length] + elif parts[0] == 'acl': + if depth == 1: + return -errno.EISDIR + if parts[1] in self.getMachines(): return self.getacl(parts[1])[offset:offset+length] - if parts[0] == 'conf.d': - return self.getconf(parts[1])[offset:offset+length] return -errno.ENOENT def readlink(self, path): @@ -229,7 +228,7 @@ class RemConfFS(Fuse): if __name__ == '__main__': - sipb_xen_database.connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen') + database.connect() usage=""" $0 [mount_path] """