oops
[invirt/packages/invirt-remote.git] / files / usr / sbin / sipb-xen-remconffs
index 03099d6..7d49a95 100755 (executable)
@@ -13,6 +13,7 @@ import errno   # for error number codes (ENOENT, etc)
 from syslog import *
 
 import sipb_xen_database
+from invirt.config import structs as config
 
 fuse.fuse_python_api = (0, 2)
 
@@ -104,19 +105,13 @@ class RemConfFS(Fuse):
                                 + ['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')
+       sipb_xen_database.connect(config.db.uri)
        usage="""
 $0 [mount_path]
 """