]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-shell: Add stat command
authorVarsha Rao <varao@redhat.com>
Wed, 24 Apr 2019 14:18:09 +0000 (19:48 +0530)
committerPatrick Donnelly <pdonnell@redhat.com>
Thu, 20 Jun 2019 22:29:10 +0000 (15:29 -0700)
This patch adds stat command to cephfs-shell.

Fixes: https://tracker.ceph.com/issues/38829
Signed-off-by: Varsha Rao <varao@redhat.com>
(cherry picked from commit 07263fe0f2dbefc936a987eb0379221a28eb42e7)

src/tools/cephfs/cephfs-shell

index a4d792d46023bdc34b21174d67b80419721d3d22..752fbcad9ee7760c0bc74b7dc844a8f82d577712 100644 (file)
@@ -1214,6 +1214,38 @@ sub-directories, files')
         else:
             super().do_help(line)
 
+    def complete_stat(self, text, line, begidx, endidx):
+        """
+        auto complete of file name.
+        """
+        return self.complete_filenames(text, line, begidx, endidx)
+
+    stat_parser = argparse.ArgumentParser(
+                  description='Display file or file system status')
+    stat_parser.add_argument('name', type=str, help='Name of the file', nargs='+')
+
+    @with_argparser(stat_parser)
+    def do_stat(self, args):
+        """
+        Display file or file system status
+        """
+        for files in args.name:
+            try:
+                stat = cephfs.stat(files)
+                atime = stat.st_atime.isoformat(' ')
+                mtime = stat.st_mtime.isoformat(' ')
+                ctime = stat.st_mtime.isoformat(' ')
+
+                self.poutput("File: {}\nSize: {:d}\nBlocks: {:d}\nIO Block: {:d}\n\
+Device: {:d}\tInode: {:d}\tLinks: {:d}\nPermission: {:o}/{}\tUid: {:d}\tGid: {:d}\n\
+Access: {}\nModify: {}\nChange: {}".format(files, stat.st_size, stat.st_blocks,
+                             stat.st_blksize, stat.st_dev, stat.st_ino,
+                             stat.st_nlink, stat.st_mode,
+                             mode_notation(stat.st_mode), stat.st_uid,
+                             stat.st_gid, atime, mtime, ctime))
+            except libcephfs.Error:
+                self.poutput("{}: no such file or directory".format(files))
+
 
 if __name__ == '__main__':
     config_file = ''