3 # A FUSE filesystem implementation to provide a file interface for
4 # vsys_publickeys VSYS script. To be used by OMF Resource Controller.
6 # Usage: ./keys_fs.py /keys
11 # Sliver has to have following ccapabilities set.
25 fuse.fuse_python_api = (0, 2)
28 keys_file = os.path.join(keys_dir, "all")
31 fin = os.open("/vsys/publickeys.in", os.O_NONBLOCK | os.O_WRONLY)
32 fout = os.open("/vsys/publickeys.out", os.O_NONBLOCK | os.O_RDONLY)
34 in_flags = fcntl.fcntl(fin, fcntl.F_GETFL)
35 out_flags = fcntl.fcntl(fin, fcntl.F_GETFL)
37 res = select.select([fout], [], [])
39 fcntl.fcntl(fin, fcntl.F_SETFL, in_flags & ~os.O_NONBLOCK)
40 fcntl.fcntl(fout, fcntl.F_SETFL, out_flags & ~os.O_NONBLOCK)
42 f = os.fdopen(fout, "r")
45 class MyStat(fuse.Stat):
60 def __init__(self, *args, **kw):
61 Fuse.__init__(self, *args, **kw)
63 def getattr(self, path):
66 st.st_mode = stat.S_IFDIR | 0755
69 st.st_mode = stat.S_IFREG | 0444
71 st.st_size = len(read_keys())
74 def readdir(self, path, offset):
75 for r in '.', '..', os.path.basename(keys_file):
76 yield fuse.Direntry(r)
78 def open(self, path, flags):
79 accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
80 if (flags & accmode) != os.O_RDONLY:
83 def read (self, path, size, offset):
88 if offset + size > slen:
90 buf = keys[offset:offset+size]
97 if __name__ == '__main__':
100 fs.parse(values=fs, errex=1)
102 if fs.fuse_args.mount_expected():
105 sys.stderr.write("can't enter root of underlying filesystem\n")