From d3ef5a26cdaaf3d3a82f9e384adacdb9c90892ea Mon Sep 17 00:00:00 2001 From: Joshua Schmid Date: Tue, 14 Jul 2020 17:01:13 +0200 Subject: [PATCH] mgr/cephadm: allow to map existing daemons to osdspecs Fixes: https://tracker.ceph.com/issues/44888 Signed-off-by: Joshua Schmid (cherry picked from commit 6a374c583c2963a0bfc28fd6b54f5f91b6f8d26f) --- src/pybind/mgr/cephadm/services/osd.py | 7 ++++--- .../deployment/drive_selection/selector.py | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/cephadm/services/osd.py b/src/pybind/mgr/cephadm/services/osd.py index 9f350e82f5856..338bf2899435f 100644 --- a/src/pybind/mgr/cephadm/services/osd.py +++ b/src/pybind/mgr/cephadm/services/osd.py @@ -125,13 +125,14 @@ class OSDService(CephService): for host in matching_hosts: inventory_for_host = _find_inv_for_host(host, self.mgr.cache.devices) logger.debug(f"Found inventory for host {inventory_for_host}") - drive_selection = DriveSelection(drive_group, inventory_for_host) + drive_selection = DriveSelection(drive_group, inventory_for_host, + self.mgr.cache.get_daemons_with_volatile_status()) logger.debug(f"Found drive selection {drive_selection}") host_ds_map.append((host, drive_selection)) return host_ds_map - def driveselection_to_ceph_volume(self, - drive_selection: DriveSelection, + @staticmethod + def driveselection_to_ceph_volume(drive_selection: DriveSelection, osd_id_claims: Optional[List[str]] = None, preview: bool = False) -> Optional[str]: logger.debug(f"Translating DriveGroup <{drive_selection.spec}> to ceph-volume command") diff --git a/src/python-common/ceph/deployment/drive_selection/selector.py b/src/python-common/ceph/deployment/drive_selection/selector.py index 921f125616c25..255d652777cbc 100644 --- a/src/python-common/ceph/deployment/drive_selection/selector.py +++ b/src/python-common/ceph/deployment/drive_selection/selector.py @@ -1,7 +1,7 @@ import logging try: - from typing import List, Optional + from typing import List, Optional, Iterator, Tuple, Dict except ImportError: pass @@ -17,9 +17,12 @@ class DriveSelection(object): def __init__(self, spec, # type: DriveGroupSpec disks, # type: List[Device] + daemons=None, # type: Iterator[Tuple[str, Dict[str, "DaemonDescription"]]] ): self.disks = disks.copy() self.spec = spec + self.daemons = daemons + self.osds_for_spec = self.find_osds_in_spec() if self.spec.data_devices.paths: # type: ignore # re: type: ignore there is *always* a path attribute assigned to DeviceSelection @@ -34,6 +37,17 @@ class DriveSelection(object): self._db = self.assign_devices(self.spec.db_devices) self._journal = self.assign_devices(self.spec.journal_devices) + def find_osds_in_spec(self) -> List["DaemonDescription"]: + osds: List["DaemonDescription"] = [] + if not self.daemons: + return osds + for host, dm in self.daemons: + for name, dd in dm.items(): + if dd.daemon_type == 'osd': + if dd.osdspec_affinity == self.spec.service_id: + osds.append(dd) + return osds + def data_devices(self): # type: () -> List[Device] return self._data @@ -50,8 +64,7 @@ class DriveSelection(object): # type: () -> List[Device] return self._journal - @staticmethod - def _limit_reached(device_filter, len_devices, + def _limit_reached(self, device_filter, len_devices, disk_path): # type: (DeviceSelection, int, str) -> bool """ Check for the property and apply logic -- 2.39.5