]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
monmap: move monmap generation from ip/host list into MonMap
authorSage Weil <sage@inktank.com>
Thu, 17 May 2012 22:12:23 +0000 (15:12 -0700)
committerSage Weil <sage@inktank.com>
Fri, 18 May 2012 23:23:57 +0000 (16:23 -0700)
Also generalize the prefix so it's explicit in the caller and a bit less
magic.

Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/MonClient.cc
src/mon/MonMap.cc
src/mon/MonMap.h

index e0aebb82fb457dd7c25aeb5ab5404d77cc842032..0a0cc515239bf0b2c24aec82b5c4644ec20c0893 100644 (file)
@@ -103,41 +103,9 @@ int MonClient::build_initial_monmap(CephContext *cct, MonMap &monmap)
 
   // -m foo?
   if (!conf->mon_host.empty()) {
-    vector<entity_addr_t> addrs;
-    if (parse_ip_port_vec(conf->mon_host.c_str(), addrs)) {
-      for (unsigned i=0; i<addrs.size(); i++) {
-       char n[2];
-       n[0] = 'a' + i;
-       n[1] = 0;
-       if (addrs[i].get_port() == 0)
-         addrs[i].set_port(CEPH_MON_PORT);
-       string name = "noname-";
-       name += n;
-       monmap.add(name, addrs[i]);
-      }
-      return 0;
-    } else { //maybe they passed us a DNS-resolvable name
-      char *hosts = NULL;
-      hosts = resolve_addrs(conf->mon_host.c_str());
-      if (!hosts)
-        return -EINVAL;
-      bool success = parse_ip_port_vec(hosts, addrs);
-      free(hosts);
-      if (success) {
-        for (unsigned i=0; i<addrs.size(); i++) {
-          char n[2];
-          n[0] = 'a' + i;
-          n[1] = 0;
-          if (addrs[i].get_port() == 0)
-            addrs[i].set_port(CEPH_MON_PORT);
-         string name = "noname-";
-         name += n;
-          monmap.add(name, addrs[i]);
-        }
-        return 0;
-      } else cerr << "couldn't parse_ip_port_vec on " << hosts << std::endl;
-    }
-    cerr << "unable to parse addrs in '" << conf->mon_host << "'" << std::endl;
+    int r = monmap.build_from_host_list(conf->mon_host, "noname-");
+    if (r < 0)
+      cerr << "unable to parse addrs in '" << conf->mon_host << "'" << std::endl;
   }
 
   // What monitors are in the config file?
index 33c04213707b48321d73166b93cee47b0b0a1516..a1f6a0bf1bc0da4aa9639dbea14b0197601b3ac2 100644 (file)
@@ -8,6 +8,8 @@
 #include "common/Formatter.h"
 
 #include "include/ceph_features.h"
+#include "include/addr_parsing.h"
+#include "common/ceph_argparse.h"
 
 using ceph::Formatter;
 
@@ -141,3 +143,44 @@ void MonMap::dump(Formatter *f) const
   }
   f->close_section();
 }
+
+
+int MonMap::build_from_host_list(std::string hostlist, std::string prefix)
+{
+  vector<entity_addr_t> addrs;
+  if (parse_ip_port_vec(hostlist.c_str(), addrs)) {
+    for (unsigned i=0; i<addrs.size(); i++) {
+      char n[2];
+      n[0] = 'a' + i;
+      n[1] = 0;
+      if (addrs[i].get_port() == 0)
+       addrs[i].set_port(CEPH_MON_PORT);
+      string name = prefix;
+      name += n;
+      add(name, addrs[i]);
+    }
+    return 0;
+  }
+
+  // maybe they passed us a DNS-resolvable name
+  char *hosts = NULL;
+  hosts = resolve_addrs(hostlist.c_str());
+  if (!hosts)
+    return -EINVAL;
+  bool success = parse_ip_port_vec(hosts, addrs);
+  free(hosts);
+  if (!success)
+    return -EINVAL;
+
+  for (unsigned i=0; i<addrs.size(); i++) {
+    char n[2];
+    n[0] = 'a' + i;
+    n[1] = 0;
+    if (addrs[i].get_port() == 0)
+      addrs[i].set_port(CEPH_MON_PORT);
+    string name = prefix;
+    name += n;
+    add(name, addrs[i]);
+  }
+  return 0;
+}
index f9706fd665b5156da20832a51e5287f06aaddc8b..7daf8e79e62c3a8bcb7bab06196cd643b3a9c75f 100644 (file)
@@ -193,6 +193,8 @@ class MonMap {
   int write(const char *fn);
   int read(const char *fn);
 
+  int build_from_host_list(std::string hosts, std::string prefix);
+
   void print(ostream& out) const;
   void print_summary(ostream& out) const;
   void dump(ceph::Formatter *f) const;