]>
Commit | Line | Data |
---|---|---|
a4b75251 TL |
1 | # -*- coding: utf-8 -*- |
2 | ||
aee94f69 TL |
3 | from typing import Dict, List, Optional |
4 | ||
a4b75251 TL |
5 | from ..security import Scope |
6 | from ..services.cluster import ClusterModel | |
aee94f69 TL |
7 | from ..services.exception import handle_orchestrator_error |
8 | from ..services.orchestrator import OrchClient, OrchFeature | |
9 | from ..tools import str_to_bool | |
10 | from . import APIDoc, APIRouter, CreatePermission, Endpoint, EndpointDoc, \ | |
11 | ReadPermission, RESTController, UpdatePermission, allow_empty_body | |
a4b75251 | 12 | from ._version import APIVersion |
aee94f69 | 13 | from .orchestrator import raise_if_no_orchestrator |
a4b75251 TL |
14 | |
15 | ||
16 | @APIRouter('/cluster', Scope.CONFIG_OPT) | |
17 | @APIDoc("Get Cluster Details", "Cluster") | |
18 | class Cluster(RESTController): | |
19 | @RESTController.MethodMap(version=APIVersion.EXPERIMENTAL) | |
20 | @EndpointDoc("Get the cluster status") | |
21 | def list(self): | |
22 | return ClusterModel.from_db().dict() | |
23 | ||
24 | @RESTController.MethodMap(version=APIVersion.EXPERIMENTAL) | |
25 | @EndpointDoc("Update the cluster status", | |
26 | parameters={'status': (str, 'Cluster Status')}) | |
27 | def singleton_set(self, status: str): | |
aee94f69 TL |
28 | ClusterModel(status).to_db() # -*- coding: utf-8 -*- |
29 | ||
30 | ||
31 | @APIRouter('/cluster/upgrade', Scope.CONFIG_OPT) | |
32 | @APIDoc("Upgrade Management API", "Upgrade") | |
33 | class ClusterUpgrade(RESTController): | |
34 | @RESTController.MethodMap() | |
35 | @raise_if_no_orchestrator([OrchFeature.UPGRADE_LIST]) | |
36 | @handle_orchestrator_error('upgrade') | |
37 | @EndpointDoc("Get the available versions to upgrade", | |
38 | parameters={ | |
39 | 'image': (str, 'Ceph Image'), | |
40 | 'tags': (bool, 'Show all image tags'), | |
41 | 'show_all_versions': (bool, 'Show all available versions') | |
42 | }) | |
43 | @ReadPermission | |
44 | def list(self, tags: bool = False, image: Optional[str] = None, | |
45 | show_all_versions: Optional[bool] = False) -> Dict: | |
46 | orch = OrchClient.instance() | |
47 | available_upgrades = orch.upgrades.list(image, str_to_bool(tags), | |
48 | str_to_bool(show_all_versions)) | |
49 | return available_upgrades | |
50 | ||
51 | @Endpoint() | |
52 | @raise_if_no_orchestrator([OrchFeature.UPGRADE_STATUS]) | |
53 | @handle_orchestrator_error('upgrade') | |
54 | @EndpointDoc("Get the cluster upgrade status") | |
55 | @ReadPermission | |
56 | def status(self) -> Dict: | |
57 | orch = OrchClient.instance() | |
58 | status = orch.upgrades.status().to_json() | |
59 | return status | |
60 | ||
61 | @Endpoint('POST') | |
62 | @raise_if_no_orchestrator([OrchFeature.UPGRADE_START]) | |
63 | @handle_orchestrator_error('upgrade') | |
64 | @EndpointDoc("Start the cluster upgrade") | |
65 | @CreatePermission | |
66 | def start(self, image: Optional[str] = None, version: Optional[str] = None, | |
67 | daemon_types: Optional[List[str]] = None, host_placement: Optional[str] = None, | |
68 | services: Optional[List[str]] = None, limit: Optional[int] = None) -> str: | |
69 | orch = OrchClient.instance() | |
70 | start = orch.upgrades.start(image, version, daemon_types, host_placement, services, limit) | |
71 | return start | |
72 | ||
73 | @Endpoint('PUT') | |
74 | @raise_if_no_orchestrator([OrchFeature.UPGRADE_PAUSE]) | |
75 | @handle_orchestrator_error('upgrade') | |
76 | @EndpointDoc("Pause the cluster upgrade") | |
77 | @UpdatePermission | |
78 | @allow_empty_body | |
79 | def pause(self) -> str: | |
80 | orch = OrchClient.instance() | |
81 | return orch.upgrades.pause() | |
82 | ||
83 | @Endpoint('PUT') | |
84 | @raise_if_no_orchestrator([OrchFeature.UPGRADE_RESUME]) | |
85 | @handle_orchestrator_error('upgrade') | |
86 | @EndpointDoc("Resume the cluster upgrade") | |
87 | @UpdatePermission | |
88 | @allow_empty_body | |
89 | def resume(self) -> str: | |
90 | orch = OrchClient.instance() | |
91 | return orch.upgrades.resume() | |
92 | ||
93 | @Endpoint('PUT') | |
94 | @raise_if_no_orchestrator([OrchFeature.UPGRADE_STOP]) | |
95 | @handle_orchestrator_error('upgrade') | |
96 | @EndpointDoc("Stop the cluster upgrade") | |
97 | @UpdatePermission | |
98 | @allow_empty_body | |
99 | def stop(self) -> str: | |
100 | orch = OrchClient.instance() | |
101 | return orch.upgrades.stop() |