mgr_map.dump(&f);
return f.get();
});
+ } else if (what == "mgr_ips") {
+ return cluster_state.with_mgrmap([&](const MgrMap &mgr_map) {
+ with_gil_t with_gil{no_gil};
+ f.open_array_section("ips");
+ std::set<std::string> did;
+ for (auto& i : server.get_myaddrs().v) {
+ std::string ip = i.ip_only_to_str();
+ if (did.count(ip)) {
+ continue;
+ }
+ did.insert(ip);
+ f.dump_string("ip", ip);
+ }
+ f.close_section();
+ return f.get();
+ });
+
} else if (what == "have_local_config_map") {
with_gil_t with_gil{no_gil};
f.dump_bool("have_local_config_map", have_local_config_map);
return self._ceph_get_active_uri()
def get_mgr_ip(self) -> str:
- hostname = socket.gethostname()
- try:
- r = socket.getaddrinfo(hostname, None, flags=socket.AI_CANONNAME,
- type=socket.SOCK_STREAM)
- # pick first v4 IP, if present, as long as it is not 127.0.{0,1}.1
- for a in r:
- if a[4][0] in ['127.0.1.1', '127.0.0.1']:
- continue
- if a[0] == socket.AF_INET:
- return a[4][0]
- except socket.gaierror as e:
- pass
- return hostname
+ # we don't have get() for standby modules; make do with the hostname
+ return socket.gethostname()
def get_localized_module_option(self, key: str, default: OptionValue = None) -> OptionValue:
r = self._ceph_get_module_option(key, self.get_mgr_id())
return self._ceph_get_ceph_conf_path()
def get_mgr_ip(self) -> str:
- hostname = socket.gethostname()
- try:
- r = socket.getaddrinfo(hostname, None, flags=socket.AI_CANONNAME,
- type=socket.SOCK_STREAM)
- # pick first v4 IP, if present, as long as it is not 127.0.{0,1}.1
- for a in r:
- if a[4][0] in ['127.0.1.1', '127.0.0.1']:
- continue
- if a[0] == socket.AF_INET:
- return a[4][0]
- except socket.gaierror as e:
- pass
- return hostname
+ ips = self.get("mgr_ips").get('ips', [])
+ if not ips:
+ return socket.gethostname()
+ return ips[0]
def get_ceph_option(self, key: str) -> OptionValue:
return self._ceph_get_option(key)