]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/cephadm: move DaemonDescription construction into helper
authorSage Weil <sage@redhat.com>
Wed, 12 Feb 2020 22:30:41 +0000 (16:30 -0600)
committerSage Weil <sage@redhat.com>
Tue, 18 Feb 2020 21:43:02 +0000 (15:43 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/cephadm/module.py

index a64d046315e4dea67a16bc1498fa09ab2b47c257..410187bf893f7b93e88025d5f96b646bbe95b405 100644 (file)
@@ -1287,6 +1287,45 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
         self.daemon_cache[host] = orchestrator.OutdatableData(data)
         return host, data
 
+    def _proc_ls(self, host, ls):
+        # type: (str, List[Dict[str,str]]) -> List[orchestrator.DaemonDescription]
+        result = []
+        for d in ls:
+            if not d['style'].startswith('cephadm'):
+                self.log.debug('ignoring non-cephadm on %s: %s' % (host, d))
+                continue
+            if d['fsid'] != self._cluster_fsid:
+                self.log.debug('ignoring foreign daemon on %s: %s' % (host, d))
+                continue
+            self.log.debug('including %s %s' % (host, d))
+            sd = orchestrator.DaemonDescription()
+            if 'last_refresh' in d:
+                sd.last_refresh = datetime.datetime.strptime(
+                    d['last_refresh'], DATEFMT)
+            if '.' not in d['name']:
+                self.log.debug('ignoring dot-less daemon on %s: %s' % (host, d))
+                continue
+            sd.daemon_type = d['name'].split('.')[0]
+            sd.daemon_id = '.'.join(d['name'].split('.')[1:])
+            sd.nodename = host
+            sd.container_id = d.get('container_id')
+            sd.container_image_name = d.get('container_image_name')
+            sd.container_image_id = d.get('container_image_id')
+            sd.version = d.get('version')
+            if 'state' in d:
+                sd.status_desc = d['state']
+                sd.status = {
+                    'running': 1,
+                    'stopped': 0,
+                    'error': -1,
+                    'unknown': -1,
+                }[d['state']]
+            else:
+                sd.status_desc = 'unknown'
+                sd.status = None
+            result.append(sd)
+        return result
+
     def _get_daemons(self,
                      daemon_type=None,
                      daemon_id=None,
@@ -1327,46 +1366,14 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
 
             result = []
             for host, ls in daemons.items():
-                for d in ls:
-                    if not d['style'].startswith('cephadm'):
-                        self.log.debug('ignoring non-cephadm on %s: %s' % (host, d))
-                        continue
-                    if d['fsid'] != self._cluster_fsid:
-                        self.log.debug('ignoring foreign daemon on %s: %s' % (host, d))
-                        continue
-                    self.log.debug('including %s %s' % (host, d))
-                    sd = orchestrator.DaemonDescription()
-                    if 'last_refresh' in d:
-                        sd.last_refresh = datetime.datetime.strptime(
-                            d['last_refresh'], DATEFMT)
-                    if '.' not in d['name']:
-                        self.log.debug('ignoring dot-less daemon on %s: %s' % (host, d))
+                for d in self._proc_ls(host, ls):
+                    if daemon_type and daemon_type != d.daemon_type:
                         continue
-                    sd.daemon_type = d['name'].split('.')[0]
-                    if daemon_type and daemon_type != sd.daemon_type:
+                    if daemon_id and daemon_id != d.daemon_id:
                         continue
-                    sd.daemon_id = '.'.join(d['name'].split('.')[1:])
-                    if daemon_id and daemon_id != sd.daemon_id:
+                    if service_name and not d.daemon_id.startswith(service_name + '.'):
                         continue
-                    if service_name and not sd.daemon_id.startswith(service_name + '.'):
-                        continue
-                    sd.nodename = host
-                    sd.container_id = d.get('container_id')
-                    sd.container_image_name = d.get('container_image_name')
-                    sd.container_image_id = d.get('container_image_id')
-                    sd.version = d.get('version')
-                    if 'state' in d:
-                        sd.status_desc = d['state']
-                        sd.status = {
-                            'running': 1,
-                            'stopped': 0,
-                            'error': -1,
-                            'unknown': -1,
-                        }[d['state']]
-                    else:
-                        sd.status_desc = 'unknown'
-                        sd.status = None
-                    result.append(sd)
+                    result.append(d)
             return result
 
         if wait_for_args: