from syslog import *
-import sipb_xen_database
+from invirt import database
+from invirt.config import structs as config
fuse.fuse_python_api = (0, 2)
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
(princ, realm) = user.split('@')
else:
princ = user
- realm = "ATHENA.MIT.EDU"
+ realm = config.authn[0].realm
return princ.replace('.', '/') + '@' + realm
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()
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
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):
if __name__ == '__main__':
- sipb_xen_database.connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
+ database.connect()
usage="""
$0 [mount_path]
"""