]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-shell: read shell variables from ceph.conf
authorRishabh Dave <ridave@redhat.com>
Wed, 28 Aug 2019 13:57:29 +0000 (19:27 +0530)
committerRishabh Dave <ridave@redhat.com>
Fri, 6 Dec 2019 03:22:59 +0000 (08:52 +0530)
Read ceph.conf and initialize shell variables by reading options set
under section cephfs-shell. If there are sections/options that are
duplicated in ceph.conf, CephFS shell overrides the options with the
values last.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/common/options.cc
src/tools/cephfs/cephfs-shell

index 6a3b9b2432bacffb3a0732e8005c88472e8b6371..384df54dc5fbc527facd2b1d533e830a671c9f69 100644 (file)
@@ -8281,6 +8281,57 @@ std::vector<Option> get_mds_client_options() {
 }
 
 
+std::vector<Option> get_cephfs_shell_options() {
+  return std::vector<Option>({
+    Option("allow_ansi", Option::TYPE_STR, Option::LEVEL_BASIC)
+    .set_default("Terminal")
+    .set_description("Allow ANSI escape sequences in output. Values: "
+                    "Terminal, Always, Never"),
+
+    Option("colors", Option::TYPE_STR, Option::LEVEL_BASIC)
+    .set_default("Terminal")
+    .set_description("Colouring CephFS shell input and output. Values: "
+                    "Terminal, Always, Never"),
+
+    Option("continuation_prompt", Option::TYPE_STR, Option::LEVEL_BASIC)
+    .set_default(">")
+    .set_description("Prompt string when a command continue to second line"),
+
+    Option("debug_shell", Option::TYPE_BOOL, Option::LEVEL_BASIC)
+    .set_default(false)
+    .set_description("Allow tracebacks on error for CephFS Shell"),
+
+    Option("echo", Option::TYPE_BOOL, Option::LEVEL_BASIC)
+    .set_default(false)
+    .set_description("Allow tracebacks on error for CephFS Shell"),
+
+    Option("editor", Option::TYPE_STR, Option::LEVEL_BASIC)
+    .set_default("vim")
+    .set_description("Default text editor for shell"),
+
+    Option("feedback_to_output", Option::TYPE_BOOL, Option::LEVEL_BASIC)
+    .set_default(false)
+    .set_description("include '|' and '>' in result"),
+
+    Option("max_completion_items", Option::TYPE_INT, Option::LEVEL_BASIC)
+    .set_default(50)
+    .set_description("Maximum number of items to be displayed by tab "
+                    "completion"),
+
+    Option("prompt", Option::TYPE_STR, Option::LEVEL_BASIC)
+    .set_default("\x1b[01;33mCephFS:~\x1b[96m/\x1b[0m\x1b[01;33m>>>\x1b[00m ")
+    .set_description("Whether non-essential feedback should be printed."),
+
+    Option("quiet", Option::TYPE_BOOL, Option::LEVEL_BASIC)
+    .set_default(false)
+    .set_description("Whether non-essential feedback should be printed."),
+
+    Option("timing", Option::TYPE_BOOL, Option::LEVEL_BASIC)
+    .set_default(false)
+    .set_description("Whether execution time should be reported"),
+  });
+}
+
 static std::vector<Option> build_options()
 {
   std::vector<Option> result = get_global_options();
@@ -8298,6 +8349,7 @@ static std::vector<Option> build_options()
   ingest(get_immutable_object_cache_options(), "immutable-objet-cache");
   ingest(get_mds_options(), "mds");
   ingest(get_mds_client_options(), "mds_client");
+  ingest(get_cephfs_shell_options(), "cephfs-shell");
 
   return result;
 }
index 1e3d5bca91fd33e503b51748a751628c1b26c7b3..8cb6afbff4a91b0778ecf16a9b85291ddb1f7eca 100755 (executable)
@@ -1379,6 +1379,42 @@ Access: {}\nModify: {}\nChange: {}".format(path.decode('utf-8'), stat.st_size,
             except libcephfs.Error as e:
                 perror(e)
 
+def get_bool_vals_for_boolopts(val):
+    if val.lower() in ['true', 'yes']:
+        return True
+    elif val.lower() in ['false', 'no']:
+        return False
+    else:
+        return val
+
+def read_ceph_conf(shell, config_file):
+    try:
+        shell.debug = get_bool_vals_for_boolopts(cephfs.\
+            conf_get('debug_shell').strip('\n'))
+        shell.allow_ansi = get_bool_vals_for_boolopts(cephfs.\
+            conf_get('allow_ansi').strip('\n'))
+        shell.echo = get_bool_vals_for_boolopts(cephfs.\
+            conf_get('echo').strip('\n'))
+        shell.continuation_prompt = get_bool_vals_for_boolopts(cephfs.\
+            conf_get('continuation_prompt').strip('\n'))
+        shell.colors = get_bool_vals_for_boolopts(cephfs.\
+            conf_get('colors').strip('\n'))
+        shell.editor = get_bool_vals_for_boolopts(cephfs.\
+            conf_get('editor').strip('\n'))
+        shell.feedback_to_output = get_bool_vals_for_boolopts(cephfs.\
+            conf_get('feedback_to_output').strip('\n'))
+        shell.max_completion_items = get_bool_vals_for_boolopts(cephfs.\
+            conf_get('max_completion_items').strip('\n'))
+        shell.prompt = get_bool_vals_for_boolopts(cephfs.\
+            conf_get('prompt').strip('\n'))
+        shell.quiet = get_bool_vals_for_boolopts(cephfs.\
+            conf_get('quiet').strip('\n'))
+        shell.timing = get_bool_vals_for_boolopts(cephfs.\
+            conf_get('timing').strip('\n'))
+    except OSError as e:
+        perror(e)
+    except cephfs.Error as e:
+        perror(e)
 
 if __name__ == '__main__':
     config_file = ''
@@ -1406,6 +1442,8 @@ if __name__ == '__main__':
     sys.argv.clear()
     sys.argv.append(exe)
     sys.argv.extend([i.strip() for i in ' '.join(args.commands).split(',')])
+
     setup_cephfs(config_file)
     shell = CephFSShell()
+    read_ceph_conf(shell, config_file)
     sys.exit(shell.cmdloop())