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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 from cmframework.server import cmwsgicallbacks
17 from cmframework.apis import cmerror
18 from cmframework.server.cmhttperrors import CMHTTPErrors
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
28 self.minimum_version = minimum_version
29 self.processor = processor
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)
40 rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
41 rpc.rep_status += ', only GET/POST/DELETE are possible to this resource'
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)
52 rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
53 rpc.rep_status += ', only GET/POST/DELETE are possible to this resource'
55 def handle_snapshots(self, rpc):
56 logging.debug('handle_snapshots called')
57 if rpc.req_method == 'GET':
58 self.list_snapshots(rpc)
60 rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
61 rpc.rep_status += ', only GET is possible to this resource'
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)
72 rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
73 rpc.rep_status += ', only GET/POST/DELETE are possible to this resource'
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)
80 rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
81 rpc.rep_status += ', only GET is possible to this resource'
83 def handle_activate(self, rpc):
84 logging.debug('handle_activate called')
85 if rpc.req_method == 'POST':
88 rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
89 rpc.rep_status += ', only POST is possible to this resource'
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)
96 rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
97 rpc.rep_status += ', only POST is possible to this resource'
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)
104 rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
105 rpc.rep_status += ', only POST is possible to this resource'
107 def handle_reboot(self, rpc):
108 logging.debug('handle_reboot called')
109 if rpc.req_method == 'GET':
110 self.reboot_node(rpc)
112 rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
113 rpc.rep_status += ', only GET is possible to this resource'
115 def handle_changes(self, rpc):
116 logging.debug('handle_changes called')
117 if rpc.req_method == 'GET':
118 self.get_changes_states(rpc)
120 rpc.rep_status = CMHTTPErrors.get_request_not_ok_status()
121 rpc.rep_status += ', only GET is possible to this resource'
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')
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')
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')
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')
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')
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')
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')
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')
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')
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')
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')
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')
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')
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')
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')
199 def get_version(self):
202 def get_status(self):
205 def get_minimum_version(self):
206 return self.minimum_version