]>
Commit | Line | Data |
---|---|---|
9f95a23c | 1 | # -*- coding: utf-8 -*- |
9f95a23c | 2 | |
f67539c2 | 3 | from functools import wraps |
9f95a23c | 4 | |
1e59de90 | 5 | from .. import mgr |
9f95a23c | 6 | from ..exceptions import DashboardException |
9f95a23c | 7 | from ..services.orchestrator import OrchClient |
2a845540 | 8 | from . import APIDoc, Endpoint, EndpointDoc, ReadPermission, RESTController, UIRouter |
f67539c2 TL |
9 | |
10 | STATUS_SCHEMA = { | |
11 | "available": (bool, "Orchestrator status"), | |
12 | "message": (str, "Error message") | |
13 | } | |
14 | ||
15 | ||
16 | def raise_if_no_orchestrator(features=None): | |
17 | def inner(method): | |
18 | @wraps(method) | |
19 | def _inner(self, *args, **kwargs): | |
20 | orch = OrchClient.instance() | |
21 | if not orch.available(): | |
22 | raise DashboardException(code='orchestrator_status_unavailable', # pragma: no cover | |
23 | msg='Orchestrator is unavailable', | |
24 | component='orchestrator', | |
25 | http_status_code=503) | |
26 | if features is not None: | |
27 | missing = orch.get_missing_features(features) | |
28 | if missing: | |
29 | msg = 'Orchestrator feature(s) are unavailable: {}'.format(', '.join(missing)) | |
30 | raise DashboardException(code='orchestrator_features_unavailable', | |
31 | msg=msg, | |
32 | component='orchestrator', | |
33 | http_status_code=503) | |
34 | return method(self, *args, **kwargs) | |
35 | return _inner | |
9f95a23c TL |
36 | return inner |
37 | ||
38 | ||
2a845540 | 39 | @UIRouter('/orchestrator') |
a4b75251 | 40 | @APIDoc("Orchestrator Management API", "Orchestrator") |
9f95a23c TL |
41 | class Orchestrator(RESTController): |
42 | ||
43 | @Endpoint() | |
44 | @ReadPermission | |
f67539c2 TL |
45 | @EndpointDoc("Display Orchestrator Status", |
46 | responses={200: STATUS_SCHEMA}) | |
9f95a23c TL |
47 | def status(self): |
48 | return OrchClient.instance().status() | |
1e59de90 TL |
49 | |
50 | @Endpoint() | |
51 | def get_name(self): | |
52 | return mgr.get_module_option_ex('orchestrator', 'orchestrator') |