]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tasks/cephfs: add CephFSMount.stat
authorJohn Spray <jspray@redhat.com>
Wed, 13 May 2015 12:39:46 +0000 (13:39 +0100)
committerJohn Spray <jspray@redhat.com>
Wed, 17 Jun 2015 13:06:22 +0000 (14:06 +0100)
Signed-off-by: John Spray <john.spray@redhat.com>
tasks/cephfs/mount.py

index cb8c0cc3d3f6507c49104f21b8d5fc180f70074c..55f79be512b361611817aed4813aa4fa433ee487 100644 (file)
@@ -1,4 +1,5 @@
 from contextlib import contextmanager
+import json
 import logging
 import datetime
 import time
@@ -371,6 +372,41 @@ class CephFSMount(object):
     def get_osd_epoch(self):
         raise NotImplementedError()
 
+    def stat(self, fs_path):
+        """
+        stat a file, and return the result as a dictionary like this:
+        {
+          "st_ctime": 1414161137.0,
+          "st_mtime": 1414161137.0,
+          "st_nlink": 33,
+          "st_gid": 0,
+          "st_dev": 16777218,
+          "st_size": 1190,
+          "st_ino": 2,
+          "st_uid": 0,
+          "st_mode": 16877,
+          "st_atime": 1431520593.0
+        }
+
+        Raises exception on absent file.
+        """
+        abs_path = os.path.join(self.mountpoint, fs_path)
+
+        pyscript = dedent("""
+            import os
+            import stat
+            import json
+
+            s = os.stat("{path}")
+            attrs = ["st_mode", "st_ino", "st_dev", "st_nlink", "st_uid", "st_gid", "st_size", "st_atime", "st_mtime", "st_ctime"]
+            print json.dumps(
+                dict([(a, getattr(s, a)) for a in attrs]),
+                indent=2)
+            """).format(path=abs_path)
+        proc = self._run_python(pyscript)
+        proc.wait()
+        return json.loads(proc.stdout.getvalue().strip())
+
     def path_to_ino(self, fs_path):
         abs_path = os.path.join(self.mountpoint, fs_path)