Merge "Add tenant_networks to user_config"
[ta/config-manager.git] / cmframework / src / cmframework / server / cmrestapi.py
1 # Copyright 2019 Nokia
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 import logging
15
16 from cmframework.server import cmwsgicallbacks
17 from cmframework.apis import cmerror
18 from cmframework.server.cmhttperrors import CMHTTPErrors
19
20
21 class CMRestAPI(cmwsgicallbacks.CMWSGICallbacks):
22     def __init__(self, version, status, minimum_version, processor):
23         logging.debug('CMRestAPI constructor called with '
24                       '{version, status, min_version}{%s, %s, %s}',
25                       version, status, minimum_version)
26         self.version = version
27         self.status = status
28         self.minimum_version = minimum_version
29         self.processor = processor
30
31     def handle_property(self, rpc):
32         logging.debug('handle_property called')
33         if rpc.req_method == 'GET':
34             self.get_property(rpc)
35         elif rpc.req_method == 'POST':
36             self.set_property(rpc)
37         elif rpc.req_method == 'DELETE':
38             self.delete_property(rpc)
39         else:
40             rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
41             rpc.rep_status += ', only GET/POST/DELETE are possible to this resource'
42
43     def handle_properties(self, rpc):
44         logging.debug('handle_properties called')
45         if rpc.req_method == 'GET':
46             self.get_properties(rpc)
47         elif rpc.req_method == 'POST':
48             self.set_properties(rpc)
49         elif rpc.req_method == 'DELETE':
50             self.delete_properties(rpc)
51         else:
52             rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
53             rpc.rep_status += ', only GET/POST/DELETE are possible to this resource'
54
55     def handle_snapshots(self, rpc):
56         logging.debug('handle_snapshots called')
57         if rpc.req_method == 'GET':
58             self.list_snapshots(rpc)
59         else:
60             rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
61             rpc.rep_status += ', only GET is possible to this resource'
62
63     def handle_snapshot(self, rpc):
64         logging.debug('handle_snapshot called')
65         if rpc.req_method == 'GET':
66             self.create_snapshot(rpc)
67         elif rpc.req_method == 'POST':
68             self.restore_snapshot(rpc)
69         elif rpc.req_method == 'DELETE':
70             self.delete_snapshot(rpc)
71         else:
72             rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
73             rpc.rep_status += ', only GET/POST/DELETE are possible to this resource'
74
75     def handle_agent_activate(self, rpc):
76         logging.debug('handle_agent_activate called')
77         if rpc.req_method == 'GET':
78             self.activate_node(rpc)
79         else:
80             rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
81             rpc.rep_status += ', only GET is possible to this resource'
82
83     def handle_activate(self, rpc):
84         logging.debug('handle_activate called')
85         if rpc.req_method == 'POST':
86             self.activate(rpc)
87         else:
88             rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
89             rpc.rep_status += ', only POST is possible to this resource'
90
91     def handle_activator_disable(self, rpc):
92         logging.debug('handle_activator_disable called')
93         if rpc.req_method == 'POST':
94             self.set_automatic_activation_state(rpc, False)
95         else:
96             rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
97             rpc.rep_status += ', only POST is possible to this resource'
98
99     def handle_activator_enable(self, rpc):
100         logging.debug('handle_activator_enable called')
101         if rpc.req_method == 'POST':
102             self.set_automatic_activation_state(rpc, True)
103         else:
104             rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
105             rpc.rep_status += ', only POST is possible to this resource'
106
107     def handle_reboot(self, rpc):
108         logging.debug('handle_reboot called')
109         if rpc.req_method == 'GET':
110             self.reboot_node(rpc)
111         else:
112             rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
113             rpc.rep_status += ', only GET is possible to this resource'
114
115     def handle_changes(self, rpc):
116         logging.debug('handle_changes called')
117         if rpc.req_method == 'GET':
118             self.get_changes_states(rpc)
119         else:
120             rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
121             rpc.rep_status += ', only GET is possible to this resource'
122
123     # pylint: disable=no-self-use
124     def get_property(self, rpc):
125         logging.error('get_property not implemented')
126         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
127         raise cmerror.CMError('Not implemented')
128
129     def get_properties(self, rpc):
130         logging.error('get_properties not implemented')
131         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
132         raise cmerror.CMError('Not implemented')
133
134     def set_property(self, rpc):
135         logging.error('set_property not implemented')
136         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
137         raise cmerror.CMError('Not implemented')
138
139     def set_properties(self, rpc):
140         logging.error('set_properties not implemented')
141         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
142         raise cmerror.CMError('Not implemented')
143
144     def delete_property(self, rpc):
145         logging.error('delete_property not implemented')
146         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
147         raise cmerror.CMError('Not implemented')
148
149     def delete_properties(self, rpc):
150         logging.error('delete_properties not implemented')
151         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
152         raise cmerror.CMError('Not implemented')
153
154     def create_snapshot(self, rpc):
155         logging.error('create_snapshot not implemented')
156         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
157         raise cmerror.CMError('Not implemented')
158
159     def restore_snapshot(self, rpc):
160         logging.error('restore_snapshot not implemented')
161         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
162         raise cmerror.CMError('Not implemented')
163
164     def delete_snapshot(self, rpc):
165         logging.error('delete_snapshot not implemented')
166         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
167         raise cmerror.CMError('Not implemented')
168
169     def list_snapshots(self, rpc):
170         logging.error('list_snapshots not implemented')
171         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
172         raise cmerror.CMError('Not implemented')
173
174     def activate(self, rpc):
175         logging.error('activate not implemented')
176         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
177         raise cmerror.CMError('Not implemented')
178
179     def activate_node(self, rpc):
180         logging.error('activate_node not implemented')
181         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
182         raise cmerror.CMError('Not implemented')
183
184     def reboot_node(self, rpc):
185         logging.error('reboot_node not implemented')
186         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
187         raise cmerror.CMError('Not implemented')
188
189     def get_changes_states(self, rpc):
190         logging.error('get_changes_states not implemented')
191         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
192         raise cmerror.CMError('Not implemented')
193
194     def set_automatic_activation_state(self, rpc, state):
195         logging.error('set_automatic_activation_state not implemented')
196         rpc.rep_status = CMHTTPErrors.get_resource_not_found_status()
197         raise cmerror.CMError('Not implemented')
198
199     def get_version(self):
200         return self.version
201
202     def get_status(self):
203         return self.status
204
205     def get_minimum_version(self):
206         return self.minimum_version