From a8e8b009801e779b826f8e70e1195f9a0d45dd86 Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Wed, 24 Apr 2019 19:48:09 +0530 Subject: [PATCH] cephfs-shell: Add stat command This patch adds stat command to cephfs-shell. Fixes: https://tracker.ceph.com/issues/38829 Signed-off-by: Varsha Rao (cherry picked from commit 07263fe0f2dbefc936a987eb0379221a28eb42e7) --- src/tools/cephfs/cephfs-shell | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index a4d792d46023b..752fbcad9ee77 100644 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -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 = '' -- 2.39.5