]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
monmaptool: add --generate, --filter-initial options
authorSage Weil <sage@inktank.com>
Fri, 18 May 2012 17:52:04 +0000 (10:52 -0700)
committerSage Weil <sage@inktank.com>
Fri, 18 May 2012 23:23:59 +0000 (16:23 -0700)
Generate a monmap from conf/args, and apply the mon initial hosts to it.

Signed-off-by: Sage Weil <sage@inktank.com>
doc/man/8/monmaptool.rst
src/monmaptool.cc

index 52ec475cc047436d3b5409404f55140536243545..95b4610a7498d3e0027000fee5ed7f4ce250ce2b 100644 (file)
@@ -44,6 +44,22 @@ Options
    will create a new monitor map with a new UUID (and with it, a new,
    empty Ceph file system).
 
+.. option:: --generate
+
+   generate a new monmap based on the values on the command line or specified
+   in the ceph configuration.  This is, in order of preference,
+
+      #. ``--monmap filename`` to specify a monmap to load
+      #. ``--mon-host 'host1,ip2'`` to specify a list of hosts or ip addresses
+      #. ``[mon.foo]`` sections containing ``mon addr`` settings in the config
+
+.. option:: --filter-initial-members
+
+   filter the initial monmap by applying the ``mon initial members``
+   setting.  Monitors not present in that list will be removed, and
+   initial members not present in the map will be added with dummy
+   addresses.
+
 .. option:: --add name ip:port
 
    will add a monitor with the specified ip:port to the map.
index 2c80d47260c56497863e8426efabed626a923419..6dffd61f6e9173e0fec10faee98271dcce11d4cf 100644 (file)
@@ -26,10 +26,11 @@ using namespace std;
 #include "common/ceph_argparse.h"
 #include "global/global_init.h"
 #include "mon/MonMap.h"
+#include "include/str_list.h"
 
 void usage()
 {
-  cout << " usage: [--print] [--create [--clobber][--fsid uuid]] [--add name 1.2.3.4:567] [--rm name] <mapfilename>" << std::endl;
+  cout << " usage: [--print] [--create [--clobber][--fsid uuid]] [--generate] [--filter-initial-members] [--add name 1.2.3.4:567] [--rm name] <mapfilename>" << std::endl;
   exit(1);
 }
 
@@ -45,6 +46,8 @@ int main(int argc, const char **argv)
   bool create = false;
   bool clobber = false;
   bool modified = false;
+  bool generate = false;
+  bool filter = false;
   map<string,entity_addr_t> add;
   list<string> rm;
 
@@ -63,6 +66,10 @@ int main(int argc, const char **argv)
       create = true;
     } else if (ceph_argparse_flag(args, i, "--clobber", (char*)NULL)) {
       clobber = true;
+    } else if (ceph_argparse_flag(args, i, "--generate", (char*)NULL)) {
+      generate = true;
+    } else if (ceph_argparse_flag(args, i, "--filter-initial-members", (char*)NULL)) {
+      filter = true;
     } else if (ceph_argparse_flag(args, i, "--add", (char*)NULL)) {
       string name = *i;
       i = args.erase(i);
@@ -130,6 +137,28 @@ int main(int argc, const char **argv)
     }
     modified = true;
   }
+
+  if (generate) {
+    int r = monmap.build_initial(g_ceph_context, cerr);
+    if (r < 0)
+      return r;
+  }
+
+  if (filter) {
+    // apply initial members
+    list<string> initial_members;
+    get_str_list(g_conf->mon_initial_members, initial_members);
+    if (initial_members.size()) {
+      cout << "initial_members " << initial_members << ", filtering seed monmap" << std::endl;
+      set<entity_addr_t> removed;
+      monmap.filter_initial_members(g_ceph_context, initial_members,
+                                   string(), entity_addr_t(),
+                                   &removed);
+      cout << "removed " << removed << std::endl;
+    }
+    modified = true;
+  }
+
   if (!g_conf->fsid.is_zero()) {
     monmap.fsid = g_conf->fsid;
     cout << me << ": set fsid to " << monmap.fsid << std::endl;