Changeset 344 for trunk/packages/sipb-xen-console/files/usr
- Timestamp:
- Mar 30, 2008, 5:09:46 AM (17 years ago)
- Location:
- trunk/packages/sipb-xen-console/files/usr/bin
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-console/files/usr/bin/sipb-xen-consolefs
r335 r344 11 11 # - note: these must be returned as negatives 12 12 13 import sipb_xen_database 14 13 15 fuse.fuse_python_api = (0, 2) 14 16 15 machines = ['moo17', 'remus']16 17 realpath = "/home/machines/" 17 uid = 100018 18 19 19 def dirFromList(list): … … 48 48 self.st_dev = 0 49 49 self.st_nlink = 0 50 self.st_uid = uid50 self.st_uid = 0 51 51 self.st_gid = 0 52 52 self.st_size = 0 … … 64 64 def __init__(self, *args, **kw): 65 65 Fuse.__init__(self, *args, **kw) 66 self.lasttime = time() 67 self.allow_other = 1 66 68 print 'Init complete.' 67 69 68 70 def mirrorPath(self, path): 69 71 return realpath + "/".join(getParts(path)[1:]) 72 73 def getMachines(self): 74 if time() - self.lasttime > 15: 75 self.lasttime = time() 76 sipb_xen_database.clear_cache() 77 return [machine.name for machine in sipb_xen_database.Machine.select()] 78 79 def getUid(self, machine_name): 80 return sipb_xen_database.Machine.get_by(name=machine_name).machine_id + 1000 81 82 def getK5login(self, machine_name): 83 machine = sipb_xen_database.Machine.get_by(name=machine_name) 84 users = [acl.user for acl in machine.acl] 85 return "\n".join(map(self.userToPrinc, users) + ['']) 86 87 def userToPrinc(self, user): 88 if '@' in user: 89 (princ, realm) = user.split('@') 90 else: 91 princ = user 92 realm = "ATHENA.MIT.EDU" 93 94 return princ.replace('.', '/') + realm 70 95 71 96 def getattr(self, path): … … 94 119 st.st_nlink = 2 95 120 elif depth == 1: 96 if parts[-1] in machines:121 if parts[-1] in self.getMachines(): 97 122 st.st_mode = stat.S_IFDIR | 0755 98 123 st.st_nlink = 2 124 st.st_uid = st.st_gid = self.getUid(parts[0]) 99 125 else: 100 126 return -errno.ENOENT … … 102 128 st.st_mode = stat.S_IFREG | 0444 103 129 st.st_nlink = 1 104 st.st_size = 17 130 st.st_size = len(self.getK5login(parts[0])) 131 st.st_uid = st.st_gid = self.getUid(parts[0]) 105 132 else: 106 st = os.lstat(self.mirrorPath(path)) 133 stats = list(os.lstat(self.mirrorPath(path))) 134 stats[4:6] = [self.getUid(parts[0])] * 2 135 return tuple(stats) 107 136 return st.toTuple() 108 137 109 138 def readdir(self, path, offset): 110 139 print '*** readdir', path, offset 140 for (value, zero) in self.getdir(path): 141 yield fuse.Direntry(value) 142 143 def getdir(self, path): 144 print '*** getdir', path 111 145 if path == '/': 112 for r in ['.', '..']+machines: 113 yield fuse.Direntry(r) 146 contents = ['.', '..']+self.getMachines() 114 147 elif getDepth(path) == 1: 115 for r in set(os.listdir(self.mirrorPath(path)) + ['.k5login']): 116 yield fuse.Direntry(r) 148 contents = set(os.listdir(self.mirrorPath(path)) + ['.k5login', '.', '..']) 117 149 else: 118 for r in os.listdir(self.mirrorPath(path)):119 yield fuse.Direntry(r)150 contents = os.listdir(self.mirrorPath(path)) + ['.', '..'] 151 return [(i, 0) for i in contents] 120 152 121 153 def read ( self, path, length, offset ): 122 154 print '*** read', path, length, offset 123 155 156 parts = getParts(path) 157 124 158 if getDepth(path) < 2: 125 159 return -errno.ENOENT 126 elif getParts(path)[1:] == ['.k5login']: 127 pass 160 elif parts[1:] == ['.k5login']: 161 if parts[0] not in self.getMachines(): 162 return -errno.ENOENT 163 else: 164 return self.getK5login(parts[0])[offset:length + offset] 128 165 else: 129 166 fname = self.mirrorPath(path) … … 136 173 137 174 if __name__ == '__main__': 175 sipb_xen_database.connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen') 138 176 usage=""" 139 177 ConsoleFS [mount_path]
Note: See TracChangeset
for help on using the changeset viewer.