]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | from typing import List, Optional |
2 | import cherrypy | |
3 | ||
4 | from . import ApiController, RESTController | |
5 | from .orchestrator import raise_if_no_orchestrator | |
6 | from ..security import Scope | |
7 | from ..services.orchestrator import OrchClient | |
8 | ||
9 | ||
10 | @ApiController('/service', Scope.HOSTS) | |
11 | class Service(RESTController): | |
12 | ||
13 | @raise_if_no_orchestrator | |
14 | def list(self, service_name: Optional[str] = None) -> List[dict]: | |
15 | orch = OrchClient.instance() | |
16 | return [service.to_json() for service in orch.services.list(service_name)] | |
17 | ||
18 | @raise_if_no_orchestrator | |
19 | def get(self, service_name: str) -> List[dict]: | |
20 | orch = OrchClient.instance() | |
21 | services = orch.services.get(service_name) | |
22 | if not services: | |
23 | raise cherrypy.HTTPError(404, 'Service {} not found'.format(service_name)) | |
24 | return services[0].to_json() | |
25 | ||
26 | @RESTController.Resource('GET') | |
27 | @raise_if_no_orchestrator | |
28 | def daemons(self, service_name: str) -> List[dict]: | |
29 | orch = OrchClient.instance() | |
30 | daemons = orch.services.list_daemons(service_name) | |
31 | return [d.to_json() for d in daemons] |