def convert_to_explicit(spec: ServiceSpec) -> None: existing_daemons = self.mgr.cache.get_daemons_by_service(spec.service_name()) placements, to_add, to_remove = HostAssignment( spec=spec, hosts=self.mgr.inventory.all_specs(), unreachable_hosts=self.mgr.cache.get_unreachable_hosts(), daemons=existing_daemons, ).place() # We have to migrate, only if the new scheduler would remove daemons if len(placements) >= len(existing_daemons): return def to_hostname(d: DaemonDescription) -> HostPlacementSpec: if d.hostname in old_hosts: return old_hosts[d.hostname] else: assert d.hostname return HostPlacementSpec(d.hostname, '', '') old_hosts = {h.hostname: h for h in spec.placement.hosts} new_hosts = [to_hostname(d) for d in existing_daemons] new_placement = PlacementSpec( hosts=new_hosts, count=spec.placement.count ) new_spec = ServiceSpec.from_json(spec.to_json()) new_spec.placement = new_placement logger.info(f"Migrating {spec.one_line_str()} to explicit placement") self.mgr.spec_store.save(new_spec)
def convert_to_explicit(spec: ServiceSpec) -> None: placements = HostAssignment(spec=spec, get_hosts_func=self.mgr._get_hosts, get_daemons_func=self.mgr.cache. get_daemons_by_service).place() existing_daemons = self.mgr.cache.get_daemons_by_service( spec.service_name()) # We have to migrate, only if the new scheduler would remove daemons if len(placements) >= len(existing_daemons): return old_hosts = {h.hostname: h for h in spec.placement.hosts} new_hosts = [ old_hosts[d.hostname] if d.hostname in old_hosts else HostPlacementSpec(hostname=d.hostname, network='', name='') for d in existing_daemons ] new_placement = PlacementSpec(hosts=new_hosts, count=spec.placement.count) new_spec = ServiceSpec.from_json(spec.to_json()) new_spec.placement = new_placement logger.info( f"Migrating {spec.one_line_str()} to explicit placement") self.mgr.spec_store.save(new_spec)
def test_daemon_add(self, spec: ServiceSpec, meth, cephadm_module): unmanaged_spec = ServiceSpec.from_json(spec.to_json()) unmanaged_spec.unmanaged = True with with_host(cephadm_module, 'test'): with with_service(cephadm_module, unmanaged_spec): with with_daemon(cephadm_module, spec, meth, 'test'): pass
def save(self, spec: ServiceSpec, update_create: bool = True) -> None: name = spec.service_name() if spec.preview_only: self.spec_preview[name] = spec return None self._specs[name] = spec if update_create: self.spec_created[name] = datetime_now() data = { 'spec': spec.to_json(), 'created': datetime_to_str(self.spec_created[name]), } if name in self.spec_deleted: data['deleted'] = datetime_to_str(self.spec_deleted[name]) self.mgr.set_store( SPEC_STORE_PREFIX + name, json.dumps(data, sort_keys=True), ) self.mgr.events.for_service(spec, OrchestratorEvent.INFO, 'service was created')