From 9f2e5c24182a9c78d71de044fdc5cb483cfb21d5 Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Thu, 27 Apr 2017 19:41:11 -0700 Subject: [PATCH] mon/ConfigKeyService: add 'config-key dump' to show keys and vals Signed-off-by: Dan Mick --- doc/man/8/ceph.rst | 10 ++++++++-- src/mon/ConfigKeyService.cc | 21 +++++++++++++++++++++ src/mon/ConfigKeyService.h | 1 + src/mon/MonCommands.h | 1 + src/test/pybind/test_ceph_argparse.py | 3 +++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/doc/man/8/ceph.rst b/doc/man/8/ceph.rst index b248912684810..04beea6421eb3 100644 --- a/doc/man/8/ceph.rst +++ b/doc/man/8/ceph.rst @@ -13,7 +13,7 @@ Synopsis | **ceph** **compact** -| **ceph** **config-key** [ *del* | *exists* | *get* | *list* | *put* ] ... +| **ceph** **config-key** [ *del* | *exists* | *get* | *list* | *dump* | *put* ] ... | **ceph** **daemon** ** \| ** ** ... @@ -201,7 +201,13 @@ Usage:: ceph config-key list -Subcommand ``put`` puts configuration key and values. +Subcommand ``dump`` dumps configuration keys and values. + +Usage:: + + ceph config-key dump + +Subcommand ``put`` puts configuration key and value. Usage:: diff --git a/src/mon/ConfigKeyService.cc b/src/mon/ConfigKeyService.cc index 8d083199331ed..f685daa05a66a 100644 --- a/src/mon/ConfigKeyService.cc +++ b/src/mon/ConfigKeyService.cc @@ -83,6 +83,21 @@ void ConfigKeyService::store_list(stringstream &ss) f.flush(ss); } +void ConfigKeyService::store_dump(stringstream &ss) +{ + KeyValueDB::Iterator iter = + mon->store->get_iterator(STORE_PREFIX); + + JSONFormatter f(true); + f.open_object_section("config-key store"); + + while (iter->valid()) { + f.dump_string(iter->key().c_str(), iter->value().to_str()); + iter->next(); + } + f.close_section(); + f.flush(ss); +} bool ConfigKeyService::service_dispatch(MonOpRequestRef op) { @@ -187,6 +202,12 @@ bool ConfigKeyService::service_dispatch(MonOpRequestRef op) store_list(tmp_ss); rdata.append(tmp_ss); ret = 0; + + } else if (prefix == "config-key dump") { + stringstream tmp_ss; + store_dump(tmp_ss); + rdata.append(tmp_ss); + ret = 0; } out: diff --git a/src/mon/ConfigKeyService.h b/src/mon/ConfigKeyService.h index 523bafbdf31c1..34c70342a981c 100644 --- a/src/mon/ConfigKeyService.h +++ b/src/mon/ConfigKeyService.h @@ -30,6 +30,7 @@ class ConfigKeyService : public QuorumService void store_put(const string &key, bufferlist &bl, Context *cb = NULL); void store_delete(const string &key, Context *cb = NULL); void store_list(stringstream &ss); + void store_dump(stringstream &ss); bool store_exists(const string &key); static const string STORE_PREFIX; diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index b64ba8d5ff1cf..5857db47a4a87 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -824,6 +824,7 @@ COMMAND("config-key exists " \ "name=key,type=CephString", \ "check for 's existence", "config-key", "r", "cli,rest") COMMAND("config-key list ", "list keys", "config-key", "r", "cli,rest") +COMMAND("config-key dump", "dump keys and values", "config-key", "r", "cli,rest") /* diff --git a/src/test/pybind/test_ceph_argparse.py b/src/test/pybind/test_ceph_argparse.py index 0c9cc7524c57a..33de0b3a4f5c0 100755 --- a/src/test/pybind/test_ceph_argparse.py +++ b/src/test/pybind/test_ceph_argparse.py @@ -1178,6 +1178,9 @@ class TestConfigKey(TestArgparse): def test_exists(self): self.check_1_string_arg('config-key', 'exists') + def test_dump(self): + self.check_no_arg('config-key', 'dump') + def test_list(self): self.check_no_arg('config-key', 'list') # Local Variables: -- 2.39.5