From 69479a773c18e5ebdaaf46546d277e43e1a9f567 Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Mon, 15 Feb 2016 11:40:45 +0000 Subject: [PATCH] mon: MonMap: support lookup monitor hosts from DNS SRV records. When no monitors can be found from the config options, we now also query DNS to check for monitor hosts. Signed-off-by: Ricardo Dias Fixes: #14527 --- src/mon/MonMap.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc index 0efcc59e6fc05..273a4f4550239 100644 --- a/src/mon/MonMap.cc +++ b/src/mon/MonMap.cc @@ -11,6 +11,7 @@ #include "include/ceph_features.h" #include "include/addr_parsing.h" #include "common/ceph_argparse.h" +#include "common/dns_resolve.h" #include "common/errno.h" #include "common/dout.h" @@ -331,6 +332,31 @@ int MonMap::build_initial(CephContext *cct, ostream& errout) add(m->c_str(), addr); } + if (size() == 0) { + // no info found from conf options lets try use DNS SRV records + string srv_name = conf->mon_dns_srv_name; + string domain; + // check if domain is also provided and extract it from srv_name + size_t idx = srv_name.find("_"); + if (idx != string::npos) { + domain = srv_name.substr(idx + 1); + srv_name = srv_name.substr(0, idx); + } + + map addrs; + if (DNSResolver::get_instance()->resolve_srv_hosts(cct, srv_name, + DNSResolver::SRV_Protocol::TCP, domain, &addrs) != 0) { + + errout << "unable to get monitor info from DNS SRV with service name: " << + "ceph-mon" << std::endl; + } + else { + for (const auto& addr : addrs) { + add(addr.first, addr.second); + } + } + } + if (size() == 0) { errout << "no monitors specified to connect to." << std::endl; return -ENOENT; -- 2.39.5