From: Sage Weil Date: Sun, 23 Feb 2020 15:09:38 +0000 (-0600) Subject: mgr/cephadm: implement placement by label X-Git-Tag: v15.1.1~282^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=da66c662386841b86d0c200d92091ebddb083cfd;p=ceph.git mgr/cephadm: implement placement by label Signed-off-by: Sage Weil --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index d1708bb381e92..10f489b00d4c1 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1350,9 +1350,13 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): self.log.exception(ex) raise - def _get_hosts(self): - # type: () -> List[str] - return [a for a in self.inventory.keys()] + def _get_hosts(self, label=None): + # type: (Optional[str]) -> List[str] + r = [] + for h, hostspec in self.inventory.items(): + if not label or label in hostspec.get('labels', []): + r.append(h) + return r @async_completion def add_host(self, spec): @@ -2534,7 +2538,7 @@ class HostAssignment(object): def __init__(self, spec=None, # type: Optional[orchestrator.ServiceSpec] scheduler=None, # type: Optional[BaseScheduler] - get_hosts_func=None, # type: Optional[Callable[[],List[str]]] + get_hosts_func=None, # type: Optional[Callable[[Optional[str]],List[str]]] service_type=None, # type: Optional[str] ): assert spec and get_hosts_func and service_type @@ -2557,13 +2561,13 @@ class HostAssignment(object): """ Assign hosts based on their label """ - # Querying for labeled hosts doesn't work currently. - # Leaving this open for the next iteration - # NOTE: This currently queries for all hosts without label restriction if self.spec.placement.label: - logger.info("Found labels. Assigning hosts that match the label") - candidates = [HostPlacementSpec(x, '', '') for x in self.get_hosts_func()] # TODO: query for labels - logger.info('Assigning hosts to spec: {}'.format(candidates)) + logger.info("Matching label '%s'" % self.spec.placement.label) + candidates = [ + HostPlacementSpec(x, '', '') + for x in self.get_hosts_func(self.spec.placement.label) + ] + logger.info('Assigning hostss to spec: {}'.format(candidates)) self.spec.placement.set_hosts(candidates) def assign_hosts(self): @@ -2576,7 +2580,7 @@ class HostAssignment(object): if not self.spec.placement.label and not self.spec.placement.hosts and self.spec.placement.count: logger.info("Found num spec. Looking for labeled hosts.") # TODO: actually query for labels (self.daemon_type) - candidates = self.scheduler.place([x for x in self.get_hosts_func()], + candidates = self.scheduler.place([x for x in self.get_hosts_func(None)], count=self.spec.placement.count) # Not enough hosts to deploy on if len(candidates) != self.spec.placement.count: @@ -2588,7 +2592,7 @@ class HostAssignment(object): self.spec.placement.set_hosts(candidates) return None - candidates = self.scheduler.place([x for x in self.get_hosts_func()], count=self.spec.placement.count) + candidates = self.scheduler.place([x for x in self.get_hosts_func(None)], count=self.spec.placement.count) # Not enough hosts to deploy on if len(candidates) != self.spec.placement.count: raise OrchestratorValidationError("Cannot place {} daemons on {} hosts.".