summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Spray <john.spray@redhat.com>2017-07-12 13:57:10 +0200
committerJohn Spray <john.spray@redhat.com>2017-07-21 12:27:26 +0200
commit241a547ba1d20311fa8ba594e5a6bea0e45f4dd2 (patch)
treea61fd89fbf2cacc97b6fdb4241a8b103e5cabe63 /src
parentrgw: treat config ints as 64 bit (diff)
downloadceph-241a547ba1d20311fa8ba594e5a6bea0e45f4dd2.tar.xz
ceph-241a547ba1d20311fa8ba594e5a6bea0e45f4dd2.zip
common: implement "config help" to output schema
Signed-off-by: John Spray <john.spray@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/common/ceph_context.cc23
-rw-r--r--src/common/options.cc65
-rw-r--r--src/common/options.h15
3 files changed, 102 insertions, 1 deletions
diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc
index be83c442b87..1d5c6facade 100644
--- a/src/common/ceph_context.cc
+++ b/src/common/ceph_context.cc
@@ -448,6 +448,27 @@ void CephContext::do_command(std::string command, cmdmap_t& cmdmap,
f->dump_string(var.c_str(), buf);
}
}
+ } else if (command == "config help") {
+ std::string var;
+ if (cmd_getval(this, cmdmap, "var", var)) {
+ // Output a single one
+ std::string key = ConfFile::normalize_key_name(var);
+ const auto &i = _conf->schema.find(key);
+ if (i == _conf->schema.end()) {
+ std::ostringstream msg;
+ msg << "Setting not found: '" << key << "'";
+ f->dump_string("error", msg.str());
+ } else {
+ i->second.dump(f);
+ }
+ } else {
+ // Output all
+ f->open_array_section("options");
+ for (const auto &option : ceph_options) {
+ option.dump(f);
+ }
+ f->close_section();
+ }
} else if (command == "config diff") {
md_config_t def_conf;
def_conf.set_val("cluster", _conf->cluster);
@@ -601,6 +622,7 @@ CephContext::CephContext(uint32_t module_type_, int init_flags_)
_admin_socket->register_command("perf histogram schema", "perf histogram schema", _admin_hook, "dump perf histogram schema");
_admin_socket->register_command("perf reset", "perf reset name=var,type=CephString", _admin_hook, "perf reset <name>: perf reset all or one perfcounter name");
_admin_socket->register_command("config show", "config show", _admin_hook, "dump current config settings");
+ _admin_socket->register_command("config help", "config help name=var,type=CephString,req=false", _admin_hook, "get config setting schema and descriptions");
_admin_socket->register_command("config set", "config set name=var,type=CephString name=val,type=CephString,n=N", _admin_hook, "config set <field> <val> [<val> ...]: set a config variable");
_admin_socket->register_command("config get", "config get name=var,type=CephString", _admin_hook, "config get <field>: get the config value");
_admin_socket->register_command("config diff",
@@ -648,6 +670,7 @@ CephContext::~CephContext()
_admin_socket->unregister_command("config show");
_admin_socket->unregister_command("config set");
_admin_socket->unregister_command("config get");
+ _admin_socket->unregister_command("config help");
_admin_socket->unregister_command("config diff");
_admin_socket->unregister_command("config diff get");
_admin_socket->unregister_command("log flush");
diff --git a/src/common/options.cc b/src/common/options.cc
index ad1b231477d..c8c20908843 100644
--- a/src/common/options.cc
+++ b/src/common/options.cc
@@ -3,6 +3,7 @@
#include "acconfig.h"
#include "options.h"
+#include "common/Formatter.h"
// Helpers for validators
#include "include/stringify.h"
@@ -10,6 +11,70 @@
#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>
+
+void Option::dump_value(const char *field_name,
+ const Option::value_t &v, Formatter *f) const
+{
+ if (boost::get<boost::blank>(&v)) {
+ // This should be nil but Formatter doesn't allow it.
+ f->dump_string(field_name, "");
+ } else if (type == TYPE_UINT) {
+ f->dump_unsigned(field_name, boost::get<uint64_t>(v));
+ } else if (type == TYPE_INT) {
+ f->dump_int(field_name, boost::get<int64_t>(v));
+ } else if (type == TYPE_STR) {
+ f->dump_string(field_name, boost::get<std::string>(v));
+ } else if (type == TYPE_FLOAT) {
+ f->dump_float(field_name, boost::get<double>(v));
+ } else if (type == TYPE_BOOL) {
+ f->dump_bool(field_name, boost::get<bool>(v));
+ } else {
+ f->dump_stream(field_name) << v;
+ }
+}
+
+void Option::dump(Formatter *f) const
+{
+ f->open_object_section("option");
+ f->dump_string("name", name);
+
+ f->dump_string("type", type_to_str(type));
+ std::string level_str;
+
+ f->dump_string("level", level_to_str(level));
+
+ f->dump_string("desc", desc);
+ f->dump_string("long_desc", long_desc);
+
+ dump_value("default", value, f);
+ dump_value("daemon_default", daemon_value, f);
+
+ f->open_array_section("tags");
+ for (const auto t : tags) {
+ f->dump_string("tag", t);
+ }
+ f->close_section();
+
+ f->open_array_section("see_also");
+ for (const auto sa : see_also) {
+ f->dump_string("see_also", sa);
+ }
+ f->close_section();
+
+ if (type == TYPE_STR) {
+ f->open_array_section("enum_values");
+ for (const auto &ea : enum_allowed) {
+ f->dump_string("enum_value", ea);
+ }
+ f->close_section();
+ }
+
+ dump_value("min", min, f);
+ dump_value("max", max, f);
+
+ f->close_section();
+}
+
const std::vector<Option> ceph_options = {
// ** global basics **
diff --git a/src/common/options.h b/src/common/options.h
index c8ff3f86ce4..95fc2ad94cf 100644
--- a/src/common/options.h
+++ b/src/common/options.h
@@ -20,7 +20,7 @@ struct Option {
TYPE_UUID,
};
- const char *type_to_str(type_t t) {
+ const char *type_to_str(type_t t) const {
switch (t) {
case TYPE_UINT: return "uint64_t";
case TYPE_INT: return "int64_t";
@@ -39,6 +39,15 @@ struct Option {
LEVEL_DEV,
};
+ const char *level_to_str(level_t l) const {
+ switch(l) {
+ case LEVEL_BASIC: return "basic";
+ case LEVEL_ADVANCED: return "advanced";
+ case LEVEL_DEV: return "developer";
+ default: return "unknown";
+ }
+ }
+
using value_t = boost::variant<
boost::blank,
std::string,
@@ -101,6 +110,8 @@ struct Option {
}
}
+ void dump_value(const char *field_name, const value_t &v, Formatter *f) const;
+
// const char * must be explicit to avoid it being treated as an int
Option& set_value(value_t& v, const char *new_value) {
v = std::string(new_value);
@@ -184,6 +195,8 @@ struct Option {
return *this;
}
+ void dump(Formatter *f) const;
+
/**
* A crude indicator of whether the value may be
* modified safely at runtime -- should be replaced