From a2c7bf8dbacdebc97736b6e84da72ca5405f0aaf Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Mon, 17 Dec 2018 09:30:33 +0000 Subject: [PATCH] mgr/dashboard: Orchestrator client service Signed-off-by: Ricardo Dias --- .../mgr/dashboard/services/orchestrator.py | 55 +++++++++++++++++++ src/pybind/mgr/dashboard/settings.py | 3 + 2 files changed, 58 insertions(+) create mode 100644 src/pybind/mgr/dashboard/services/orchestrator.py diff --git a/src/pybind/mgr/dashboard/services/orchestrator.py b/src/pybind/mgr/dashboard/services/orchestrator.py new file mode 100644 index 000000000000..bfcec2bcbc66 --- /dev/null +++ b/src/pybind/mgr/dashboard/services/orchestrator.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import + +import time + +from .. import mgr, logger +from ..settings import Settings + + +class NoOrchesrtatorConfiguredException(Exception): + pass + + +class OrchClient(object): + _instance = None + + @classmethod + def instance(cls): + if cls._instance is None: + cls._instance = OrchClient() + return cls._instance + + def _call(self, method, *args, **kwargs): + if not Settings.ORCHESTRATOR_BACKEND: + raise NoOrchesrtatorConfiguredException() + return mgr.remote(Settings.ORCHESTRATOR_BACKEND, method, *args, + **kwargs) + + def _wait(self, completions): + while not self._call("wait", completions): + if any(c.should_wait for c in completions): + time.sleep(5) + else: + break + + def list_service_info(self, service_type): + completion = self._call("describe_service", service_type, None, None) + self._wait([completion]) + return completion.result + + def available(self): + if not Settings.ORCHESTRATOR_BACKEND: + return False + status, desc = self._call("available") + logger.info("[ORCH] is orchestrator available: %s, %s", status, desc) + return status + + def reload_service(self, service_type, service_ids): + if not isinstance(service_ids, list): + service_ids = [service_ids] + + completion_list = [self._call("update_stateless_service", service_type, + service_id, None) + for service_id in service_ids] + self._wait(completion_list) diff --git a/src/pybind/mgr/dashboard/settings.py b/src/pybind/mgr/dashboard/settings.py index 7c0ea15411af..73c490297e72 100644 --- a/src/pybind/mgr/dashboard/settings.py +++ b/src/pybind/mgr/dashboard/settings.py @@ -40,6 +40,9 @@ class Options(object): GRAFANA_API_USERNAME = ('admin', str) GRAFANA_API_PASSWORD = ('admin', str) + # Orchestrator settings + ORCHESTRATOR_BACKEND = ('', str) + @staticmethod def has_default_value(name): return getattr(Settings, name, None) is None or \ -- 2.47.3