Merge PR #33851 into master

* refs/pull/33851/head:
	mgr/orch: allow list daemons by service_name

Reviewed-by: Sebastian Wagner <swagner@suse.com>
This commit is contained in:
Sage Weil 2020-03-24 17:26:49 -05:00
commit 8eb550c8dd
5 changed files with 18 additions and 11 deletions

View File

@ -1908,7 +1908,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
return [s for n, s in sm.items()] return [s for n, s in sm.items()]
@trivial_completion @trivial_completion
def list_daemons(self, daemon_type=None, daemon_id=None, def list_daemons(self, service_name=None, daemon_type=None, daemon_id=None,
host=None, refresh=False): host=None, refresh=False):
if refresh: if refresh:
# ugly sync path, FIXME someday perhaps? # ugly sync path, FIXME someday perhaps?
@ -1922,9 +1922,11 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
if host and h != host: if host and h != host:
continue continue
for name, dd in dm.items(): for name, dd in dm.items():
if daemon_type and daemon_type != dd.daemon_type: if daemon_type is not None and daemon_type != dd.daemon_type:
continue continue
if daemon_id and daemon_id != dd.daemon_id: if daemon_id is not None and daemon_id != dd.daemon_id:
continue
if service_name is not None and service_name != dd.service_name():
continue continue
result.append(dd) result.append(dd)
return result return result

View File

@ -837,8 +837,8 @@ class Orchestrator(object):
""" """
raise NotImplementedError() raise NotImplementedError()
def list_daemons(self, daemon_type=None, daemon_id=None, host=None, refresh=False): def list_daemons(self, service_name=None, daemon_type=None, daemon_id=None, host=None, refresh=False):
# type: (Optional[str], Optional[str], Optional[str], bool) -> Completion # type: (Optional[str], Optional[str], Optional[str], Optional[str], bool) -> Completion
""" """
Describe a daemon (of any kind) that is already configured in Describe a daemon (of any kind) that is already configured in
the orchestrator. the orchestrator.

View File

@ -377,13 +377,15 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule):
@_cli_read_command( @_cli_read_command(
'orch ps', 'orch ps',
"name=hostname,type=CephString,req=false " "name=hostname,type=CephString,req=false "
"name=service_name,type=CephString,req=false "
"name=daemon_type,type=CephString,req=false " "name=daemon_type,type=CephString,req=false "
"name=daemon_id,type=CephString,req=false " "name=daemon_id,type=CephString,req=false "
"name=format,type=CephChoices,strings=json|plain,req=false " "name=format,type=CephChoices,strings=json|plain,req=false "
"name=refresh,type=CephBool,req=false", "name=refresh,type=CephBool,req=false",
'List daemons known to orchestrator') 'List daemons known to orchestrator')
def _list_daemons(self, hostname=None, daemon_type=None, daemon_id=None, format='plain', refresh=False): def _list_daemons(self, hostname=None, service_name=None, daemon_type=None, daemon_id=None, format='plain', refresh=False):
completion = self.list_daemons(daemon_type, completion = self.list_daemons(service_name,
daemon_type,
daemon_id=daemon_id, daemon_id=daemon_id,
host=hostname, host=hostname,
refresh=refresh) refresh=refresh)

View File

@ -358,11 +358,11 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
return [v for k, v in spec.items()] return [v for k, v in spec.items()]
@deferred_read @deferred_read
def list_daemons(self, daemon_type=None, daemon_id=None, host=None, def list_daemons(self, service_name=None, daemon_type=None, daemon_id=None, host=None,
refresh=False): refresh=False):
return self._list_daemons(daemon_type, daemon_id, host, refresh) return self._list_daemons(daemon_type, daemon_id, host, refresh)
def _list_daemons(self, daemon_type=None, daemon_id=None, host=None, def _list_daemons(self, service_name=None, daemon_type=None, daemon_id=None, host=None,
refresh=False): refresh=False):
pods = self.rook_cluster.describe_pods(daemon_type, daemon_id, host) pods = self.rook_cluster.describe_pods(daemon_type, daemon_id, host)
self.log.debug('pods %s' % pods) self.log.debug('pods %s' % pods)
@ -390,8 +390,9 @@ class RookOrchestrator(MgrModule, orchestrator.Orchestrator):
# Unknown type -- skip it # Unknown type -- skip it
continue continue
if service_name is not None and service_name != sd.service_name():
continue
sd.container_image_name = p['container_image_name'] sd.container_image_name = p['container_image_name']
sd.created = p['created'] sd.created = p['created']
sd.last_configured = p['created'] sd.last_configured = p['created']
sd.last_deployed = p['created'] sd.last_deployed = p['created']

View File

@ -220,7 +220,7 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator):
return list(filter(_filter_func, services)) return list(filter(_filter_func, services))
@deferred_read @deferred_read
def list_daemons(self, daemon_type=None, daemon_id=None, host=None, refresh=False): def list_daemons(self, service_name=None, daemon_type=None, daemon_id=None, host=None, refresh=False):
""" """
There is no guarantee which daemons are returned by describe_service, except that There is no guarantee which daemons are returned by describe_service, except that
it returns the mgr we're running in. it returns the mgr we're running in.
@ -232,6 +232,8 @@ class TestOrchestrator(MgrModule, orchestrator.Orchestrator):
daemons = self._daemons if self._daemons else self._get_ceph_daemons() daemons = self._daemons if self._daemons else self._get_ceph_daemons()
def _filter_func(d): def _filter_func(d):
if service_name is not None and service_name != d.service_name():
return False
if daemon_type is not None and daemon_type != d.daemon_type: if daemon_type is not None and daemon_type != d.daemon_type:
return False return False
if daemon_id is not None and daemon_id != d.daemon_id: if daemon_id is not None and daemon_id != d.daemon_id: