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.
15 # we also depend on fuse and python-fuse packages.
28 fuse.fuse_python_api = (0, 2)
34 fin = os.open("/vsys/publickeys.in", os.O_NONBLOCK | os.O_WRONLY)
35 fout = os.open("/vsys/publickeys.out", os.O_NONBLOCK | os.O_RDONLY)
37 in_flags = fcntl.fcntl(fin, fcntl.F_GETFL)
38 out_flags = fcntl.fcntl(fin, fcntl.F_GETFL)
40 res = select.select([fout], [], [])
42 fcntl.fcntl(fin, fcntl.F_SETFL, in_flags & ~os.O_NONBLOCK)
43 fcntl.fcntl(fout, fcntl.F_SETFL, out_flags & ~os.O_NONBLOCK)
45 f = os.fdopen(fout, "r")
53 for line in keys.split('\n'):
61 files["unnamed_key%d" % num] = line
65 class MyStat(fuse.Stat):
80 def __init__(self, *args, **kw):
81 Fuse.__init__(self, *args, **kw)
83 def getattr(self, path):
86 st.st_mode = stat.S_IFDIR | 0755
88 elif os.path.basename(path) == "all":
89 st.st_mode = stat.S_IFREG | 0444
91 st.st_size = len(read_keys())
93 filename = os.path.basename(path)
95 st.st_mode = stat.S_IFREG | 0444
98 st.st_size = len(keys[filename])
103 def readdir(self, path, offset):
104 files = ['.', '..', "all"]
106 files.extend(keys.keys())
108 yield fuse.Direntry(r)
110 def open(self, path, flags):
111 accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
112 if (flags & accmode) != os.O_RDONLY:
115 def read (self, path, size, offset):
116 if os.path.basename(path) == "all":
117 content = read_keys()
119 filename = os.path.basename(path)
121 content = keys[filename]
126 if offset + size > slen:
128 buf = keys[offset:offset+size]
135 if __name__ == '__main__':
138 fs.parse(values=fs, errex=1)
140 if fs.fuse_args.mount_expected():
143 sys.stderr.write("can't enter root of underlying filesystem\n")