From: Sage Weil Date: Tue, 23 Nov 2021 17:32:40 +0000 (-0500) Subject: pybind/mgr/mgr_module: cache mgr_ip X-Git-Tag: v17.1.0~366^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=994832e8e50c3566e21928f6be61e45a4411e556;p=ceph-ci.git pybind/mgr/mgr_module: cache mgr_ip This does not change for the lifetime of an active mgr module. No need to keep calling back into Mgr to re-fetch it. Signed-off-by: Sage Weil --- diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 73839000cd5..0f6a19263d2 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -935,6 +935,9 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): # Keep a librados instance for those that need it. self._rados: Optional[rados.Rados] = None + # this does not change over the lifetime of an active mgr + self._mgr_ips: Optional[str] = None + self._db_lock = threading.Lock() def __del__(self) -> None: @@ -1656,10 +1659,13 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): return self._ceph_get_ceph_conf_path() def get_mgr_ip(self) -> str: - ips = self.get("mgr_ips").get('ips', []) - if not ips: - return socket.gethostname() - return ips[0] + if not self._mgr_ips: + ips = self.get("mgr_ips").get('ips', []) + if not ips: + return socket.gethostname() + self._mgr_ips = ips[0] + assert self._mgr_ips is not None + return self._mgr_ips def get_ceph_option(self, key: str) -> OptionValue: return self._ceph_get_option(key)