]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: add `orch host ok-to-stop` command
authorMichael Fritch <mfritch@suse.com>
Tue, 21 Jul 2020 21:06:19 +0000 (15:06 -0600)
committerSebastian Wagner <sebastian.wagner@suse.com>
Tue, 4 Aug 2020 14:21:44 +0000 (16:21 +0200)
$ ceph orch host ok-to-stop host1
It is presumed safe to stop host host1

Signed-off-by: Michael Fritch <mfritch@suse.com>
(cherry picked from commit d6fa2e23015c405775c89c2f1bd55d10c0d8a710)

src/pybind/mgr/cephadm/module.py
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/orchestrator/module.py

index 6d067d3e0c839817cf941939765d0cc693490cbf..b984d9abac2f72e48f0d88638df97d9096df989b 100644 (file)
@@ -1223,6 +1223,29 @@ you may want to run:
         self.log.info('Removed label %s to host %s' % (label, host))
         return 'Removed label %s from host %s' % (label, host)
 
+    @trivial_completion
+    def host_ok_to_stop(self, hostname: str):
+        if hostname not in self.cache.get_hosts():
+            raise OrchestratorError(f'Cannot find host "{hostname}"')
+
+        daemons = self.cache.get_daemons()
+        daemon_map = defaultdict(lambda: [])
+        for dd in daemons:
+            if dd.hostname == hostname:
+                daemon_map[dd.daemon_type].append(dd.daemon_id)
+
+        for daemon_type,daemon_ids in daemon_map.items():
+            r = self.cephadm_services[daemon_type].ok_to_stop(daemon_ids)
+            if r.retval:
+                self.log.error(f'It is NOT safe to stop host {hostname}')
+                raise orchestrator.OrchestratorError(
+                        r.stderr,
+                        errno=r.retval)
+
+        msg = f'It is presumed safe to stop host {hostname}'
+        self.log.info(msg)
+        return msg
+
     def update_osdspec_previews(self, search_host: str = ''):
         # Set global 'pending' flag for host
         self.cache.loading_osdspec_preview.add(search_host)
index 5b054a6dcbc2a55103505809a652d44cd3ad756b..4a90ad333229a42ace5836c1cb7203d7dbe7636d 100644 (file)
@@ -846,6 +846,14 @@ class Orchestrator(object):
         """
         raise NotImplementedError()
 
+    def host_ok_to_stop(self, hostname:str) -> Completion:
+        """
+        Check if the specified host can be safely stopped without reducing availability
+
+        :param host: hostname
+        """
+        raise NotImplementedError()
+
     def get_inventory(self, host_filter=None, refresh=False):
         # type: (Optional[InventoryFilter], bool) -> Completion[List[InventoryHost]]
         """
index 870a1dd7314983be7f2d10f352f3d8a26aa49704..878f39ef90c3ea63aab0b7a528033c6730c2c6c6 100644 (file)
@@ -350,6 +350,16 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule):
         raise_if_exception(completion)
         return HandleCommandResult(stdout=completion.result_str())
 
+    @_cli_write_command(
+        'orch host ok-to-stop',
+        'name=hostname,type=CephString',
+        desc='Check if the specified host can be safely stopped without reducing availability')
+    def _host_ok_to_stop(self, hostname: str):
+        completion = self.host_ok_to_stop(hostname)
+        self._orchestrator_wait([completion])
+        raise_if_exception(completion)
+        return HandleCommandResult(stdout=completion.result_str())
+
     @_cli_read_command(
         'orch device ls',
         "name=hostname,type=CephString,n=N,req=false "