]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orch: ServiceDescription: Make spec a requirement
authorSebastian Wagner <sebastian.wagner@suse.com>
Thu, 19 Mar 2020 11:56:07 +0000 (12:56 +0100)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 26 Mar 2020 10:57:25 +0000 (11:57 +0100)
Because, a ServiceDescription is superset of a spec

Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/rook/module.py
src/pybind/mgr/test_orchestrator/module.py

index 94e30cd4893b3601918fc4362e591e8911e2521e..1a5a6ac050442af98eed550fc14c5994fcd11c23 100644 (file)
@@ -1868,18 +1868,25 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
                     continue
                 if dd.daemon_type == 'osd':
                     continue                # ignore OSDs for now
-                spec = None
                 if dd.service_name() in self.spec_store.specs:
                     spec = self.spec_store.specs[dd.service_name()]
+                else:
+                    spec = ServiceSpec(
+                        unmanaged=True,
+                        service_type=dd.daemon_type,
+                        service_id=dd.service_id(),
+                        placement=PlacementSpec(
+                            hosts=[dd.hostname]
+                        )
+                    )
                 if n not in sm:
                     sm[n] = orchestrator.ServiceDescription(
-                        service_name=n,
                         last_refresh=dd.last_refresh,
                         container_image_id=dd.container_image_id,
                         container_image_name=dd.container_image_name,
                         spec=spec,
                     )
-                if spec:
+                if dd.service_name() in self.spec_store.specs:
                     sm[n].size = self._get_spec_size(spec)
                     sm[n].created = self.spec_store.spec_created[dd.service_name()]
                 else:
@@ -1900,12 +1907,11 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
             if service_name is not None and service_name != n:
                 continue
             sm[n] = orchestrator.ServiceDescription(
-                service_name=n,
                 spec=spec,
                 size=self._get_spec_size(spec),
                 running=0,
             )
-        return [s for n, s in sm.items()]
+        return list(sm.values())
 
     @trivial_completion
     def list_daemons(self, service_name=None, daemon_type=None, daemon_id=None,
index 1adaad628aeb1c035c34a598afb44d1fcd873a81..a50fae7facb1a1ed7c62ba5022d458eb9a119959 100644 (file)
@@ -1274,14 +1274,17 @@ class DaemonDescription(object):
             return self.name().startswith(service_name + '.')
         return False
 
-    def service_name(self):
+    def service_id(self):
         if self.daemon_type == 'rgw':
             v = self.daemon_id.split('.')
-            s_name = '.'.join(v[0:2])
-            return 'rgw.%s' % s_name
+            return '.'.join(v[0:2])
         if self.daemon_type in ['mds', 'nfs']:
-            _s_name = self.daemon_id.split('.')[0]
-            return '%s.%s' % (self.daemon_type, _s_name)
+            return self.daemon_id.split('.')[0]
+        return self.daemon_type
+
+    def service_name(self):
+        if self.daemon_type in ['rgw', 'mds', 'nfs']:
+            return f'{self.daemon_type}.{self.service_id()}'
         return self.daemon_type
 
     def __repr__(self):
@@ -1330,26 +1333,21 @@ class ServiceDescription(object):
     """
 
     def __init__(self,
+                 spec: ServiceSpec,
                  container_image_id=None,
                  container_image_name=None,
-                 service_name=None,
                  rados_config_location=None,
                  service_url=None,
                  last_refresh=None,
                  created=None,
                  size=0,
-                 running=0,
-                 spec=None):
+                 running=0):
         # Not everyone runs in containers, but enough people do to
         # justify having the container_image_id (image hash) and container_image
         # (image name)
         self.container_image_id = container_image_id      # image hash
         self.container_image_name = container_image_name  # image friendly name
 
-        # The service_name is either a bare type (e.g., 'mgr') or
-        # type.id combination (e.g., 'mds.fsname' or 'rgw.realm.zone').
-        self.service_name = service_name
-
         # Location of the service configuration when stored in rados
         # object. Format: "rados://<pool>/[<namespace/>]<object>"
         self.rados_config_location = rados_config_location
index 959a75952a410de6fc6d741609caf253b8871550..75dc2193baa3534b9c266d4236502265cbd9c1d3 100644 (file)
@@ -266,7 +266,6 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
 
         spec = {}
         spec['mon'] = orchestrator.ServiceDescription(
-            service_name='mon',
             spec=ServiceSpec(
                 'mon',
                 placement=PlacementSpec(
@@ -278,7 +277,6 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
             last_refresh=now,
         )
         spec['mgr'] = orchestrator.ServiceDescription(
-            service_name='mgr',
             spec=ServiceSpec(
                 'mgr',
                 placement=PlacementSpec.from_string('count:1'),
@@ -289,7 +287,6 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
         )
         if not cl['spec'].get('crashCollector', {}).get('disable', False):
             spec['crash'] = orchestrator.ServiceDescription(
-                service_name='crash',
                 spec=ServiceSpec(
                     'crash',
                     placement=PlacementSpec.from_string('*'),
@@ -313,9 +310,9 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
             if fs['spec'].get('metadataServer', {}).get('activeStandby', False):
                 total_mds = active * 2
             spec[svc] = orchestrator.ServiceDescription(
-                service_name=svc,
                 spec=ServiceSpec(
-                    svc,
+                    service_type='mds',
+                    service_id=fs['metadata']['name'],
                     placement=PlacementSpec(count=active),
                 ),
                 size=total_mds,
@@ -341,8 +338,8 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
                 ssl = False
                 port = zone['spec']['gateway']['port'] or 80
             spec[svc] = orchestrator.ServiceDescription(
-                service_name=svc,
                 spec=RGWSpec(
+                    service_id=rgw_realm + '.' + rgw_zone,
                     rgw_realm=rgw_realm,
                     rgw_zone=rgw_zone,
                     ssl=ssl,
index c01c80b19ca67dbb50dfa6874ac82dbec6d058c2..f35321a3f05dbe56e4f23b0a385549158e2db1b2 100644 (file)
@@ -210,7 +210,10 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator):
                     continue
                 daemon_size = len(list(daemons))
                 services.append(orchestrator.ServiceDescription(
-                    service_name=daemon_type, size=daemon_size, running=daemon_size))
+                    spec=ServiceSpec(
+                        service_type=service_type,
+                    ),
+                    size=daemon_size, running=daemon_size))
         
         def _filter_func(svc):
             if service_name is not None and service_name != svc.service_name: