daemons = self.cache.get_daemons()
grafanas = [] # type: List[orchestrator.DaemonDescription]
+ iscsi_daemons = []
for dd in daemons:
# orphan?
spec = self.spec_store.specs.get(dd.service_name(), None)
if dd.daemon_type == 'grafana':
# put running instances at the front of the list
grafanas.insert(0, dd)
+ elif dd.daemon_type == 'iscsi':
+ iscsi_daemons.append(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())
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 = f'https://{self.inventory.get_addr(host)}:3000'
- 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)
+ if grafanas:
+ self.grafana_service.daemon_check_post(grafanas)
+ if iscsi_daemons:
+ self.iscsi_service.daemon_check_post(iscsi_daemons)
def _add_daemon(self, daemon_type, spec,
create_func: Callable[..., T], config_func=None) -> List[T]:
import logging
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, List
from ceph.deployment.service_spec import ServiceSpec, RGWSpec
-from orchestrator import OrchestratorError
+from orchestrator import OrchestratorError, DaemonDescription
from cephadm import utils
if TYPE_CHECKING:
def __init__(self, mgr: "CephadmOrchestrator"):
self.mgr: "CephadmOrchestrator" = mgr
+ def daemon_check_post(self, daemon_descrs: List[DaemonDescription]):
+ """The post actions needed to be done after daemons are checked"""
+ raise NotImplementedError()
+
class MonService(CephadmService):
def create(self, name, host, network):
import json
import logging
+from typing import List, cast
+from mgr_module import MonCommandFailed
from ceph.deployment.service_spec import IscsiServiceSpec
+from orchestrator import DaemonDescription
from .cephadmservice import CephadmService
from .. import utils
extra_config = {'iscsi-gateway.cfg': igw_conf}
return self.mgr._create_daemon('iscsi', igw_id, host, keyring=keyring,
extra_config=extra_config)
+
+ def daemon_check_post(self, daemon_descrs: List[DaemonDescription]):
+ try:
+ _, out, _ = self.mgr.check_mon_command({
+ 'prefix': 'dashboard iscsi-gateway-list'
+ })
+ except MonCommandFailed as e:
+ logger.warning('Failed to get existing iSCSI gateways from the Dashboard: %s', e)
+ return
+
+ gateways = json.loads(out)['gateways']
+ for dd in daemon_descrs:
+ spec = cast(IscsiServiceSpec,
+ self.mgr.spec_store.specs.get(dd.service_name(), None))
+ if not spec:
+ logger.warning('No ServiceSpec found for %s', dd)
+ continue
+ if not all([spec.api_user, spec.api_password]):
+ reason = 'api_user or api_password is not specified in ServiceSpec'
+ logger.warning(
+ 'Unable to add iSCSI gateway to the Dashboard for %s: %s', dd, reason)
+ continue
+ host = self.mgr.inventory.get_addr(dd.hostname)
+ service_url = 'http://{}:{}@{}:{}'.format(
+ spec.api_user, spec.api_password, host, spec.api_port or '5000')
+ gw = gateways.get(dd.hostname)
+ if not gw or gw['service_url'] != service_url:
+ try:
+ logger.info('Adding iSCSI gateway %s to Dashboard', service_url)
+ _, out, _ = self.mgr.check_mon_command({
+ 'prefix': 'dashboard iscsi-gateway-add',
+ 'service_url': service_url,
+ 'name': dd.hostname
+ })
+ except MonCommandFailed as e:
+ logger.warning(
+ 'Failed to add iSCSI gateway %s to the Dashboard: %s', service_url, e)
import os
from typing import List, Any, Tuple, Dict
+from orchestrator import DaemonDescription
from cephadm.services.cephadmservice import CephadmService
from mgr_util import verify_tls, ServerConfigException, create_self_signed_cert
}
return config_file, sorted(deps)
+ def daemon_check_post(self, daemon_descrs: List[DaemonDescription]):
+ # make sure the dashboard [does not] references grafana
+ try:
+ current_url = self.mgr.get_module_option_ex('dashboard', 'GRAFANA_API_URL')
+ host = daemon_descrs[0].hostname
+ url = f'https://{self.mgr.inventory.get_addr(host)}:3000'
+ if current_url != url:
+ logger.info('Setting dashboard grafana config to %s' % url)
+ self.mgr.set_module_option_ex('dashboard', 'GRAFANA_API_URL', url)
+ # FIXME: is it a signed cert??
+ except Exception as e:
+ logger.debug('got exception fetching dashboard grafana state: %s', e)
+
class AlertmanagerService(CephadmService):
def create(self, daemon_id, host) -> str: