if not osdspecs:
self.log.debug("No OSDSpecs found")
return []
- # TODO: adapt this when we change patter_matches_hosts with https://github.com/ceph/ceph/pull/34860
- return sum([spec.placement.pattern_matches_hosts(self.cache.get_hosts()) for spec in osdspecs], [])
+ return sum([spec.placement.filter_matching_hosts(self._get_hosts) for spec in osdspecs], [])
def resolve_osdspecs_for_host(self, host):
matching_specs = []
self.log.debug(f"Finding OSDSpecs for host: <{host}>")
for spec in self.spec_store.find('osd'):
- if host in spec.placement.pattern_matches_hosts(self.cache.get_hosts()):
+ if host in spec.placement.filter_matching_hosts(self._get_hosts):
self.log.debug(f"Found OSDSpecs for host: <{host}> -> <{spec}>")
matching_specs.append(spec)
return matching_specs
return self._service_add_decorate('RGW', spec,
self.rook_cluster.apply_objectstore)
-
def apply_nfs(self, spec):
# type: (NFSServiceSpec) -> RookCompletion
num = spec.placement.count
)
def create_osds(self, drive_group):
- # type: (DriveGroupSpec) -> orchestrator.Completion
+ # type: (DriveGroupSpec) -> RookCompletion
""" Creates OSDs from a drive group specification.
$: ceph orch osd create -i <dg.file>
if drive_group.data_directories:
targets += drive_group.data_directories
- def execute():
- # type: () -> orchestrator.Completion
- matching_hosts = drive_group.placement.filter_matching_hosts(self.get_hosts)
+ def execute(all_hosts_):
+ # type: (List[orchestrator.HostSpec]) -> orchestrator.Completion
+ all_hosts = [h.hostname for h in all_hosts_]
+ matching_hosts = drive_group.placement.filter_matching_hosts(lambda label=None, as_hostspec=None: all_hosts)
assert len(matching_hosts) == 1
return found is not None
- c = execute()
+ c = self.get_hosts().then(execute)
return c
def blink_device_light(self, ident_fault: str, on: bool, locs: List[orchestrator.DeviceLightLoc]) -> RookCompletion:
def run(all_hosts):
# type: (List[orchestrator.HostSpec]) -> None
drive_group.validate()
- if drive_group.placement.host_pattern:
- if not drive_group.placement.filter_matching_hosts(self.get_hosts):
- raise orchestrator.OrchestratorValidationError('failed to match')
+ if not drive_group.placement.filter_matching_hosts(lambda label=None, as_hostspec=None:
+ [h.hostname for h in all_hosts]):
+ raise orchestrator.OrchestratorValidationError('failed to match')
+
return self.get_hosts().then(run).then(
on_complete=orchestrator.ProgressReference(
message='create_osds',
def run(all_hosts):
# type: (List[orchestrator.HostSpec]) -> None
drive_group.validate()
- if drive_group.placement.host_pattern:
- if not drive_group.placement.filter_matching_hosts(self.get_hosts):
- raise orchestrator.OrchestratorValidationError('failed to match')
+ if not drive_group.placement.filter_matching_hosts(lambda label=None, as_hostspec=None:
+ [h.hostname for h in all_hosts]):
+ raise orchestrator.OrchestratorValidationError('failed to match')
return self.get_hosts().then(run).then(
on_complete=orchestrator.ProgressReference(
message='apply_drivesgroups',
import re
from collections import namedtuple
from functools import wraps
-from typing import Optional, Dict, Any, List, Union
+from typing import Optional, Dict, Any, List, Union, Callable
import six
# in the orchestrator backend.
self.hosts = hosts
- def pattern_matches_hosts(self, all_hosts):
- # type: (List[str]) -> List[str]
- if not self.host_pattern:
+ def filter_matching_hosts(self, _get_hosts_func: Callable) -> List[str]:
+ if self.hosts:
+ all_hosts = _get_hosts_func(label=None, as_hostspec=False)
+ return [h.hostname for h in self.hosts if h.hostname in all_hosts]
+ elif self.label:
+ return _get_hosts_func(label=self.label, as_hostspec=False)
+ elif self.host_pattern:
+ return fnmatch.filter(_get_hosts_func(label=None, as_hostspec=False), self.host_pattern)
+ else:
+ # This should be caught by the validation but needs to be here for
+ # get_host_selection_size
return []
- return fnmatch.filter(all_hosts, self.host_pattern)
+
+ def get_host_selection_size(self, _get_hosts_func):
+ if self.count:
+ return self.count
+ return len(self.filter_matching_hosts(_get_hosts_func))
def pretty_str(self):
kv = []
])
def test_DriveGroup(test_input):
dg = [DriveGroupSpec.from_json(inp) for inp in test_input][0]
- assert dg.placement.pattern_matches_hosts(['hostname']) == ['hostname']
+ assert dg.placement.filter_matching_hosts(lambda label=None, as_hostspec=None: ['hostname']) == ['hostname']
assert dg.service_id == 'testing_drivegroup'
assert all([isinstance(x, Device) for x in dg.data_devices.paths])
assert dg.data_devices.paths[0].path == '/dev/sda'
def test_drivegroup_pattern():
dg = DriveGroupSpec(PlacementSpec(host_pattern='node[1-3]'), data_devices=DeviceSelection(all=True))
- assert dg.placement.pattern_matches_hosts(['node{}'.format(i) for i in range(10)]) == ['node1', 'node2', 'node3']
+ assert dg.placement.filter_matching_hosts(lambda label=None, as_hostspec=None: ['node{}'.format(i) for i in range(10)]) == ['node1', 'node2', 'node3']
def test_drive_selection():