Skip to content

Commit

Permalink
monmaptool: add --generate, --filter-initial options
Browse files Browse the repository at this point in the history
Generate a monmap from conf/args, and apply the mon initial hosts to it.

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
Sage Weil committed May 18, 2012
1 parent 1473ef4 commit ece33e5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
16 changes: 16 additions & 0 deletions doc/man/8/monmaptool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 30 additions & 1 deletion src/monmaptool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ece33e5

Please sign in to comment.