From 951434f3a40fd697e5eae8fbcbf779abceb3ba34 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Piotr=20Da=C5=82ek?= Date: Tue, 17 Oct 2017 09:48:15 +0200 Subject: [PATCH] tools/ceph-conf: dump parsed config in plain text or as json MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is useful for finding differences between ceph.conf on disk and in osd/mon memory. Signed-off-by: Piotr Dałek --- src/test/cli/ceph-conf/help.t | 4 ++++ src/tools/ceph_conf.cc | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/test/cli/ceph-conf/help.t b/src/test/cli/ceph-conf/help.t index f10d801d5f7..83b3c9f53d8 100644 --- a/src/test/cli/ceph-conf/help.t +++ b/src/test/cli/ceph-conf/help.t @@ -17,10 +17,14 @@ -r|--resolve-search search for the first file that exists and can be opened in the resulted comma delimited search list. + -D|--dump-all dump all variables. FLAGS --name name Set type.id [-s
] Add to list of sections to search + [--format plain|json|json-pretty] + dump variables in plain text, json or pretty + json If there is no action given, the action will default to --lookup. diff --git a/src/tools/ceph_conf.cc b/src/tools/ceph_conf.cc index 94db5934175..40cbf946d4b 100644 --- a/src/tools/ceph_conf.cc +++ b/src/tools/ceph_conf.cc @@ -17,6 +17,7 @@ #include "common/ceph_argparse.h" #include "global/global_init.h" #include "mon/AuthMonitor.h" +#include "common/Formatter.h" using std::deque; using std::string; @@ -42,10 +43,14 @@ ACTIONS\n\ -r|--resolve-search search for the first file that exists and\n\ can be opened in the resulted comma\n\ delimited search list.\n\ + -D|--dump-all dump all variables.\n\ \n\ FLAGS\n\ --name name Set type.id\n\ [-s
] Add to list of sections to search\n\ + [--format plain|json|json-pretty]\n\ + dump variables in plain text, json or pretty\n\ + json\n\ \n\ If there is no action given, the action will default to --lookup.\n\ \n\ @@ -136,6 +141,26 @@ static int lookup(const std::deque §ions, } } +static int dump_all(const string& format) +{ + if (format == "" || format == "plain") { + g_conf->show_config(std::cout); + return 0; + } else { + unique_ptr f(Formatter::create(format)); + if (f) { + f->open_object_section("ceph-conf"); + g_conf->show_config(f.get()); + f->close_section(); + f->flush(std::cout); + return 0; + } + cerr << "format '" << format << "' not recognized." << std::endl; + usage(); + return 1; + } +} + int main(int argc, const char **argv) { vector args; @@ -146,6 +171,7 @@ int main(int argc, const char **argv) std::string section_list_prefix; std::list filter_key; std::map filter_key_value; + std::string dump_format; argv_to_vec(argc, argv, args); env_to_vec(args); @@ -198,6 +224,10 @@ int main(int argc, const char **argv) string key(val, 0, pos); string value(val, pos+1); filter_key_value[key] = value; + } else if (ceph_argparse_flag(args, i, "-D", "--dump_all", (char*)NULL)) { + action = "dumpall"; + } else if (ceph_argparse_witharg(args, i, &val, "--format", (char*)NULL)) { + dump_format = val; } else { if (((action == "lookup") || (action == "")) && (lookup_key.empty())) { action = "lookup"; @@ -223,6 +253,8 @@ int main(int argc, const char **argv) return list_sections(section_list_prefix, filter_key, filter_key_value); } else if (action == "lookup") { return lookup(sections, lookup_key, resolve_search); + } else if (action == "dumpall") { + return dump_all(dump_format); } else { cerr << "You must give an action, such as --lookup or --list-all-sections." << std::endl; cerr << "Pass --help for more help." << std::endl; -- 2.39.5