From d037c7a20f2cd095a9ebe5b592305850d6a7a3fb Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 11 Jan 2019 09:13:58 -0600 Subject: [PATCH] mon/ConfigMonitor: add 'config generate-minimal-conf' command Generate a minimal ceph.conf that should be sufficient for any client or server-side node. Signed-off-by: Sage Weil --- src/mon/ConfigMap.cc | 18 ++++++++++++++++++ src/mon/ConfigMap.h | 7 +++++++ src/mon/ConfigMonitor.cc | 28 ++++++++++++++++++++++++++++ src/mon/MonCommands.h | 3 +++ 4 files changed, 56 insertions(+) diff --git a/src/mon/ConfigMap.cc b/src/mon/ConfigMap.cc index 0bb9a21e2a0e..89be317697b3 100644 --- a/src/mon/ConfigMap.cc +++ b/src/mon/ConfigMap.cc @@ -66,6 +66,24 @@ void Section::dump(Formatter *f) const } } +std::string Section::get_minimal_conf() const +{ + std::string r; + for (auto& i : options) { + if (i.second.opt->has_flag(Option::FLAG_NO_MON_UPDATE) || + i.second.opt->has_flag(Option::FLAG_MINIMAL_CONF)) { + if (i.second.mask.empty()) { + r += "\t"s + i.first + " = " + i.second.raw_value + "\n"; + } else { + r += "\t# masked option excluded: " + i.first + " = " + + i.second.raw_value + "\n"; + } + } + } + return r; +} + + // ------------ void ConfigMap::dump(Formatter *f) const diff --git a/src/mon/ConfigMap.h b/src/mon/ConfigMap.h index c4b1abf7f7a3..220715256fd5 100644 --- a/src/mon/ConfigMap.h +++ b/src/mon/ConfigMap.h @@ -35,6 +35,12 @@ struct OptionMask { std::string location_type, location_value; ///< matches crush_location std::string device_class; ///< matches device class + bool empty() const { + return location_type.size() == 0 + && location_value.size() == 0 + && device_class.size() == 0; + } + std::string to_str() const { std::string r; if (location_type.size()) { @@ -86,6 +92,7 @@ struct Section { options.clear(); } void dump(Formatter *f) const; + std::string get_minimal_conf() const; }; struct ConfigMap { diff --git a/src/mon/ConfigMonitor.cc b/src/mon/ConfigMonitor.cc index f730cffaa53d..3e83d499a20e 100644 --- a/src/mon/ConfigMonitor.cc +++ b/src/mon/ConfigMonitor.cc @@ -349,6 +349,34 @@ bool ConfigMonitor::preprocess_command(MonOpRequestRef op) } else { odata.append(ds.str()); } + } else if (prefix == "config generate-minimal-conf") { + ostringstream conf; + conf << "# minimal ceph.conf for " << mon->monmap->get_fsid() << "\n"; + + // the basics + conf << "[global]\n"; + conf << "\tfsid = " << mon->monmap->get_fsid() << "\n"; + conf << "\tmon_host = "; + for (auto i = mon->monmap->mon_info.begin(); + i != mon->monmap->mon_info.end(); + ++i) { + if (i != mon->monmap->mon_info.begin()) { + conf << " "; + } + conf << i->second.public_addrs; + } + conf << "\n"; + conf << config_map.global.get_minimal_conf(); + for (auto m : { &config_map.by_type, &config_map.by_id }) { + for (auto& i : *m) { + auto s = i.second.get_minimal_conf(); + if (s.size()) { + conf << "\n[" << i.first << "]\n" << s; + } + } + } + odata.append(conf.str()); + err = 0; } else { return false; } diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index e73f2176d4ab..f5ce691fe2c8 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -1165,6 +1165,9 @@ COMMAND("config reset" \ " name=num,type=CephInt", "Revert configuration to previous state", "config", "rw") +COMMAND("config generate-minimal-conf", + "Generate a minimal ceph.conf file", + "config", "r") COMMAND_WITH_FLAG("smart name=devid,type=CephString,req=false", "Query health metrics for underlying device", -- 2.47.3