From b2384e029136673004c937d6b502665ead2c97a5 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 3 Mar 2020 10:15:28 -0600 Subject: [PATCH] mgr/cephadm: point dashboard at grafana automatically Signed-off-by: Sage Weil --- src/pybind/mgr/cephadm/module.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 8c43daff2af..3fe55d0ac88 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2241,7 +2241,11 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): def _refresh_configs(self): daemons = self.cache.get_daemons() + grafanas = [] # type: List[orchestrator.DaemonDescription] for dd in daemons: + if dd.daemon_type == 'grafana': + # put running instances at the front of the list + grafanas.insert(0, dd) deps = self._calc_daemon_deps(dd.daemon_type, dd.daemon_id) last_deps, last_config = self.cache.get_daemon_last_config_deps( dd.hostname, dd.name()) @@ -2255,6 +2259,23 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): self._create_daemon(dd.daemon_type, dd.daemon_id, dd.hostname, reconfig=True) + # make sure the dashboard [does not] references grafana + try: + current_url = self.get_module_option_ex('dashboard', + 'GRAFANA_API_URL') + if grafanas: + host = grafanas[0].hostname + url = 'https://%s:3000' % (self.inventory[host].get('addr', + host)) + if current_url != url: + self.log.info('Setting dashboard grafana config to %s' % url) + self.set_module_option_ex('dashboard', 'GRAFANA_API_URL', + url) + # FIXME: is it a signed cert?? + except Exception as e: + self.log.debug('got exception fetching dashboard grafana state: %s', + e) + def _add_daemon(self, daemon_type, spec, create_func, config_func=None): """ -- 2.39.5