]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/ConfigMonitor: add 'config generate-minimal-conf' command 25915/head
authorSage Weil <sage@redhat.com>
Fri, 11 Jan 2019 15:13:58 +0000 (09:13 -0600)
committerSage Weil <sage@redhat.com>
Fri, 11 Jan 2019 15:13:58 +0000 (09:13 -0600)
Generate a minimal ceph.conf that should be sufficient for any client
or server-side node.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/ConfigMap.cc
src/mon/ConfigMap.h
src/mon/ConfigMonitor.cc
src/mon/MonCommands.h

index 0bb9a21e2a0ecb2b71d13be42effb6f5d37c0f49..89be317697b33c398dabb0f288bfc5881f54d92f 100644 (file)
@@ -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
index c4b1abf7f7a367bf09105a07fc49af21e27e0b52..220715256fd502630deae328d6f0a3f37300be2b 100644 (file)
@@ -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 {
index f730cffaa53de2a372843e4f6c346e70d86d305d..3e83d499a20ef7d7e6c7b45697f8c09ee7ca7004 100644 (file)
@@ -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;
   }
index e73f2176d4ab09f2d27b605c64bfb8fa05b5c127..f5ce691fe2c8ef9a6f192b262bd816a0eb849ce8 100644 (file)
@@ -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",