From: Pavani Rajula Date: Sun, 12 Aug 2018 14:55:54 +0000 (+0530) Subject: tools/cephfs-shell: added support for batch file processing and to execute commands... X-Git-Tag: v14.0.1~604^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=ab70dffdb248d11e63359db53238bf33a732c7a6;p=ceph.git tools/cephfs-shell: added support for batch file processing and to execute commands from arguments. Fixes:http://tracker.ceph.com/issues/26853 Fixes:http://tracker.ceph.com/issues/26855 Signed-off-by: Pavani Rajula --- diff --git a/doc/cephfs/cephfs-shell.rst b/doc/cephfs/cephfs-shell.rst index 5474b4ffb013c..48cfc104f06fa 100644 --- a/doc/cephfs/cephfs-shell.rst +++ b/doc/cephfs/cephfs-shell.rst @@ -5,6 +5,15 @@ Ceph FS Shell The File System (FS) shell includes various shell-like commands that directly interact with the Ceph File System. +Usage : + + cephfs-shell [-options] -- [command, command,...] + +Options : + -c, --config FILE Set Configuration file. + -b, --batch FILE Process a batch file. + -t, --test FILE Test against transcript(s) in FILE + Commands ======== diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index c553aa2f4f4cb..bb23263f73819 100644 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -911,9 +911,23 @@ sub-directories, files') if __name__ == '__main__': config_file = '' - if sys.argv[1] == '-c': - config_file = sys.argv[2] + exe = sys.argv[0] + main_parser = argparse.ArgumentParser(description = '') + main_parser.add_argument('-c', '--config', action = 'store', help = 'Configuration file_path', type = str) + main_parser.add_argument('-b', '--batch', action = 'store', help = 'Batch File path.', type = str) + main_parser.add_argument('-t', '--test', action='store', help='Test against transcript(s) in FILE', nargs = '+') + main_parser.add_argument('commands', nargs='*', help='comma delimited commands') + args = main_parser.parse_args() + if args.config: + config_file = args.config + sys.argv = [sys.argv[0]] + sys.argv[3:] + if args.batch: + sys.argv[1] = 'load ' + args.batch + sys.argv[2] = 'quit' + sys.argv = sys.argv[:3] + sys.argv.clear() + sys.argv.append(exe) + sys.argv.extend(' '.join(args.commands).split(',')) setup_cephfs(config_file) - sys.argv = [sys.argv[0]] c = CephFSShell() c.cmdloop()