add omf_keys directory to start working on vsys script/fs support to export users...
Barış Metin [Wed, 23 Jun 2010 14:22:27 +0000 (16:22 +0200)]
omf_keys/key_fs.py [new file with mode: 0644]

diff --git a/omf_keys/key_fs.py b/omf_keys/key_fs.py
new file mode 100644 (file)
index 0000000..80cdc42
--- /dev/null
@@ -0,0 +1,85 @@
+#!/usr/bin/python
+
+# A FUSE filesystem implementation to provide a file interface for
+# vsys_publickeys VSYS script. To be used by OMF Resource Controller.
+
+import os
+import stat
+import errno
+import fuse
+import sys
+from fuse import Fuse
+
+fuse.fuse_python_api = (0, 2)
+
+keys_dir = "/keys"
+keys_file = os.path.join(keys_dir, "all")
+
+# TODO: for Giovanni
+def read_keys():
+    return "reading PLC users' public keys\n"
+
+class MyStat(fuse.Stat):
+    def __init__(self):
+        self.st_mode = 0
+        self.st_ino = 0
+        self.st_dev = 0
+        self.st_nlink = 0
+        self.st_uid = 0
+        self.st_gid = 0
+        self.st_size = 0
+        self.st_atime = 0
+        self.st_mtime = 0
+        self.st_ctime = 0
+
+class KeyFS(Fuse):
+
+    def __init__(self, *args, **kw):
+        Fuse.__init__(self, *args, **kw)
+
+    def getattr(self, path):
+        st = MyStat()
+        if path == '/':
+            st.st_mode = stat.S_IFDIR | 0755
+            st.st_nlink = 2
+        else:
+            st.st_mode = stat.S_IFREG | 0444
+            st.st_nlink = 1
+            st.st_size = len(read_keys())
+        return st
+
+    def readdir(self, path, offset):
+        for r in  '.', '..', os.path.basename(keys_file):
+            yield fuse.Direntry(r)
+
+    def open(self, path, flags):
+        accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
+        if (flags & accmode) != os.O_RDONLY:
+            return -errno.EACCES
+
+    def read (self, path, size, offset):
+        keys = read_keys()
+        slen = len(keys)
+
+        if offset < slen:
+            if offset + size > slen:
+                size = slen - offset
+            buf = keys[offset:offset+size]
+        else:
+            buf = ''
+        return buf
+
+
+
+if __name__ == '__main__':
+    fs = KeyFS()
+    fs.multithreaded = 0
+    fs.parse(values=fs, errex=1)
+    try:
+        if fs.fuse_args.mount_expected():
+            os.chdir("/")
+    except OSError:
+        sys.stderr.write("can't enter root of underlying filesystem\n")
+        sys.exit(1)
+
+    fs.main()