]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/controllers/service.py
import ceph pacific 16.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / service.py
CommitLineData
f67539c2 1from typing import Dict, List, Optional
9f95a23c 2
f67539c2 3import cherrypy
adb31ebb 4from ceph.deployment.service_spec import ServiceSpec
f67539c2 5
adb31ebb 6from ..exceptions import DashboardException
9f95a23c 7from ..security import Scope
adb31ebb 8from ..services.exception import handle_orchestrator_error
f67539c2
TL
9from ..services.orchestrator import OrchClient, OrchFeature
10from . import ApiController, ControllerDoc, CreatePermission, \
11 DeletePermission, Endpoint, ReadPermission, RESTController, Task
12from .orchestrator import raise_if_no_orchestrator
adb31ebb
TL
13
14
15def service_task(name, metadata, wait_for=2.0):
16 return Task("service/{}".format(name), metadata, wait_for)
9f95a23c
TL
17
18
19@ApiController('/service', Scope.HOSTS)
f67539c2 20@ControllerDoc("Service Management API", "Service")
9f95a23c
TL
21class Service(RESTController):
22
adb31ebb
TL
23 @Endpoint()
24 @ReadPermission
25 def known_types(self) -> List[str]:
26 """
27 Get a list of known service types, e.g. 'alertmanager',
28 'node-exporter', 'osd' or 'rgw'.
29 """
30 return ServiceSpec.KNOWN_SERVICE_TYPES
31
f67539c2 32 @raise_if_no_orchestrator([OrchFeature.SERVICE_LIST])
9f95a23c
TL
33 def list(self, service_name: Optional[str] = None) -> List[dict]:
34 orch = OrchClient.instance()
b3b6e05e 35 return [service.to_dict() for service in orch.services.list(service_name=service_name)]
9f95a23c 36
f67539c2 37 @raise_if_no_orchestrator([OrchFeature.SERVICE_LIST])
9f95a23c
TL
38 def get(self, service_name: str) -> List[dict]:
39 orch = OrchClient.instance()
40 services = orch.services.get(service_name)
41 if not services:
42 raise cherrypy.HTTPError(404, 'Service {} not found'.format(service_name))
43 return services[0].to_json()
44
45 @RESTController.Resource('GET')
f67539c2 46 @raise_if_no_orchestrator([OrchFeature.DAEMON_LIST])
9f95a23c
TL
47 def daemons(self, service_name: str) -> List[dict]:
48 orch = OrchClient.instance()
f91f0fd5 49 daemons = orch.services.list_daemons(service_name=service_name)
b3b6e05e 50 return [d.to_dict() for d in daemons]
adb31ebb
TL
51
52 @CreatePermission
f67539c2 53 @raise_if_no_orchestrator([OrchFeature.SERVICE_CREATE])
adb31ebb
TL
54 @handle_orchestrator_error('service')
55 @service_task('create', {'service_name': '{service_name}'})
56 def create(self, service_spec: Dict, service_name: str): # pylint: disable=W0613
57 """
58 :param service_spec: The service specification as JSON.
59 :param service_name: The service name, e.g. 'alertmanager'.
60 :return: None
61 """
62 try:
63 orch = OrchClient.instance()
64 orch.services.apply(service_spec)
65 except (ValueError, TypeError) as e:
66 raise DashboardException(e, component='service')
67
68 @DeletePermission
f67539c2 69 @raise_if_no_orchestrator([OrchFeature.SERVICE_DELETE])
adb31ebb
TL
70 @handle_orchestrator_error('service')
71 @service_task('delete', {'service_name': '{service_name}'})
72 def delete(self, service_name: str):
73 """
74 :param service_name: The service name, e.g. 'mds' or 'crash.foo'.
75 :return: None
76 """
77 orch = OrchClient.instance()
78 orch.services.remove(service_name)