]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/controllers/daemon.py
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / daemon.py
CommitLineData
20effc67
TL
1# -*- coding: utf-8 -*-
2
aee94f69 3from typing import List, Optional
20effc67
TL
4
5from ..exceptions import DashboardException
6from ..security import Scope
7from ..services.exception import handle_orchestrator_error
8from ..services.orchestrator import OrchClient, OrchFeature
9from . import APIDoc, APIRouter, RESTController
10from ._version import APIVersion
11from .orchestrator import raise_if_no_orchestrator
12
13
14@APIRouter('/daemon', Scope.HOSTS)
15@APIDoc("Perform actions on daemons", "Daemon")
16class Daemon(RESTController):
17 @raise_if_no_orchestrator([OrchFeature.DAEMON_ACTION])
18 @handle_orchestrator_error('daemon')
19 @RESTController.MethodMap(version=APIVersion.EXPERIMENTAL)
20 def set(self, daemon_name: str, action: str = '',
21 container_image: Optional[str] = None):
22
23 if action not in ['start', 'stop', 'restart', 'redeploy']:
24 raise DashboardException(
25 code='invalid_daemon_action',
26 msg=f'Daemon action "{action}" is either not valid or not supported.')
27 # non 'None' container_images change need a redeploy
28 if container_image == '' and action != 'redeploy':
29 container_image = None
30
31 orch = OrchClient.instance()
32 res = orch.daemons.action(action=action, daemon_name=daemon_name, image=container_image)
33 return res
aee94f69
TL
34
35 @raise_if_no_orchestrator([OrchFeature.DAEMON_LIST])
36 @handle_orchestrator_error('daemon')
37 @RESTController.MethodMap(version=APIVersion.DEFAULT)
38 def list(self, daemon_types: Optional[List[str]] = None):
39 """List all daemons in the cluster. Also filter by the daemon types specified
40
41 :param daemon_types: List of daemon types to filter by.
42 :return: Returns list of daemons.
43 :rtype: list
44 """
45 orch = OrchClient.instance()
46 daemons = [d.to_dict() for d in orch.services.list_daemons()]
47 if daemon_types:
48 daemons = [d for d in daemons if d['daemon_type'] in daemon_types]
49 return daemons