summaryrefslogtreecommitdiff
path: root/watcher_tempest_plugin/services/infra_optim/v1/json/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'watcher_tempest_plugin/services/infra_optim/v1/json/client.py')
-rw-r--r--watcher_tempest_plugin/services/infra_optim/v1/json/client.py331
1 files changed, 0 insertions, 331 deletions
diff --git a/watcher_tempest_plugin/services/infra_optim/v1/json/client.py b/watcher_tempest_plugin/services/infra_optim/v1/json/client.py
deleted file mode 100644
index 2ee27f5..0000000
--- a/watcher_tempest_plugin/services/infra_optim/v1/json/client.py
+++ /dev/null
@@ -1,331 +0,0 @@
1# -*- encoding: utf-8 -*-
2# Copyright (c) 2016 b<>com
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17from oslo_serialization import jsonutils
18from watcher.common import utils
19from watcher_tempest_plugin.services.infra_optim import base
20
21
22class InfraOptimClientJSON(base.BaseInfraOptimClient):
23 """Base Tempest REST client for Watcher API v1."""
24
25 URI_PREFIX = 'v1'
26
27 def serialize(self, object_dict):
28 """Serialize an Watcher object."""
29 return jsonutils.dumps(object_dict)
30
31 def deserialize(self, object_str):
32 """Deserialize an Watcher object."""
33 return jsonutils.loads(object_str.decode('utf-8'))
34
35 # ### AUDIT TEMPLATES ### #
36
37 @base.handle_errors
38 def list_audit_templates(self, **kwargs):
39 """List all existing audit templates."""
40 return self._list_request('audit_templates', **kwargs)
41
42 @base.handle_errors
43 def list_audit_templates_detail(self, **kwargs):
44 """Lists details of all existing audit templates."""
45 return self._list_request('/audit_templates/detail', **kwargs)
46
47 @base.handle_errors
48 def show_audit_template(self, audit_template_uuid):
49 """Gets a specific audit template.
50
51 :param audit_template_uuid: Unique identifier of the audit template
52 :return: Serialized audit template as a dictionary.
53 """
54 return self._show_request('audit_templates', audit_template_uuid)
55
56 @base.handle_errors
57 def create_audit_template(self, **kwargs):
58 """Creates an audit template with the specified parameters.
59
60 :param name: The name of the audit template.
61 :param description: The description of the audit template.
62 :param goal_uuid: The related Goal UUID associated.
63 :param strategy_uuid: The related Strategy UUID associated.
64 :param audit_scope: Scope the audit should apply to.
65 :return: A tuple with the server response and the created audit
66 template.
67 """
68
69 parameters = {k: v for k, v in kwargs.items() if v is not None}
70 # This name is unique to avoid the DB unique constraint on names
71 unique_name = 'Tempest Audit Template %s' % utils.generate_uuid()
72
73 audit_template = {
74 'name': parameters.get('name', unique_name),
75 'description': parameters.get('description'),
76 'goal': parameters.get('goal'),
77 'strategy': parameters.get('strategy'),
78 'scope': parameters.get('scope', []),
79 }
80
81 return self._create_request('audit_templates', audit_template)
82
83 @base.handle_errors
84 def delete_audit_template(self, audit_template_uuid):
85 """Deletes an audit template having the specified UUID.
86
87 :param audit_template_uuid: The unique identifier of the audit template
88 :return: A tuple with the server response and the response body.
89 """
90
91 return self._delete_request('audit_templates', audit_template_uuid)
92
93 @base.handle_errors
94 def update_audit_template(self, audit_template_uuid, patch):
95 """Update the specified audit template.
96
97 :param audit_template_uuid: The unique identifier of the audit template
98 :param patch: List of dicts representing json patches.
99 :return: A tuple with the server response and the updated audit
100 template.
101 """
102
103 return self._patch_request('audit_templates',
104 audit_template_uuid, patch)
105
106 # ### AUDITS ### #
107
108 @base.handle_errors
109 def list_audits(self, **kwargs):
110 """List all existing audit templates."""
111 return self._list_request('audits', **kwargs)
112
113 @base.handle_errors
114 def list_audits_detail(self, **kwargs):
115 """Lists details of all existing audit templates."""
116 return self._list_request('/audits/detail', **kwargs)
117
118 @base.handle_errors
119 def show_audit(self, audit_uuid):
120 """Gets a specific audit template.
121
122 :param audit_uuid: Unique identifier of the audit template
123 :return: Serialized audit template as a dictionary
124 """
125 return self._show_request('audits', audit_uuid)
126
127 @base.handle_errors
128 def create_audit(self, audit_template_uuid, **kwargs):
129 """Create an audit with the specified parameters
130
131 :param audit_template_uuid: Audit template ID used by the audit
132 :return: A tuple with the server response and the created audit
133 """
134 audit = {'audit_template_uuid': audit_template_uuid}
135 audit.update(kwargs)
136 if not audit['state']:
137 del audit['state']
138
139 return self._create_request('audits', audit)
140
141 @base.handle_errors
142 def delete_audit(self, audit_uuid):
143 """Deletes an audit having the specified UUID
144
145 :param audit_uuid: The unique identifier of the audit
146 :return: A tuple with the server response and the response body
147 """
148
149 return self._delete_request('audits', audit_uuid)
150
151 @base.handle_errors
152 def update_audit(self, audit_uuid, patch):
153 """Update the specified audit.
154
155 :param audit_uuid: The unique identifier of the audit
156 :param patch: List of dicts representing json patches.
157 :return: Tuple with the server response and the updated audit
158 """
159
160 return self._patch_request('audits', audit_uuid, patch)
161
162 # ### ACTION PLANS ### #
163
164 @base.handle_errors
165 def list_action_plans(self, **kwargs):
166 """List all existing action plan"""
167 return self._list_request('action_plans', **kwargs)
168
169 @base.handle_errors
170 def list_action_plans_detail(self, **kwargs):
171 """Lists details of all existing action plan"""
172 return self._list_request('/action_plans/detail', **kwargs)
173
174 @base.handle_errors
175 def show_action_plan(self, action_plan_uuid):
176 """Gets a specific action plan
177
178 :param action_plan_uuid: Unique identifier of the action plan
179 :return: Serialized action plan as a dictionary
180 """
181 return self._show_request('/action_plans', action_plan_uuid)
182
183 @base.handle_errors
184 def delete_action_plan(self, action_plan_uuid):
185 """Deletes an action plan having the specified UUID
186
187 :param action_plan_uuid: The unique identifier of the action_plan
188 :return: A tuple with the server response and the response body
189 """
190
191 return self._delete_request('/action_plans', action_plan_uuid)
192
193 @base.handle_errors
194 def delete_action_plans_by_audit(self, audit_uuid):
195 """Deletes an action plan having the specified UUID
196
197 :param audit_uuid: The unique identifier of the related Audit
198 """
199
200 action_plans = self.list_action_plans(audit_uuid=audit_uuid)[1]
201
202 for action_plan in action_plans:
203 self.delete_action_plan(action_plan['uuid'])
204
205 @base.handle_errors
206 def update_action_plan(self, action_plan_uuid, patch):
207 """Update the specified action plan
208
209 :param action_plan_uuid: The unique identifier of the action_plan
210 :param patch: List of dicts representing json patches.
211 :return: Tuple with the server response and the updated action_plan
212 """
213
214 return self._patch_request('/action_plans', action_plan_uuid, patch)
215
216 @base.handle_errors
217 def start_action_plan(self, action_plan_uuid):
218 """Start the specified action plan
219
220 :param action_plan_uuid: The unique identifier of the action_plan
221 :return: Tuple with the server response and the updated action_plan
222 """
223
224 return self._patch_request(
225 '/action_plans', action_plan_uuid,
226 [{'path': '/state', 'op': 'replace', 'value': 'PENDING'}])
227
228 # ### GOALS ### #
229
230 @base.handle_errors
231 def list_goals(self, **kwargs):
232 """List all existing goals"""
233 return self._list_request('/goals', **kwargs)
234
235 @base.handle_errors
236 def list_goals_detail(self, **kwargs):
237 """Lists details of all existing goals"""
238 return self._list_request('/goals/detail', **kwargs)
239
240 @base.handle_errors
241 def show_goal(self, goal):
242 """Gets a specific goal
243
244 :param goal: UUID or Name of the goal
245 :return: Serialized goal as a dictionary
246 """
247 return self._show_request('/goals', goal)
248
249 # ### ACTIONS ### #
250
251 @base.handle_errors
252 def list_actions(self, **kwargs):
253 """List all existing actions"""
254 return self._list_request('/actions', **kwargs)
255
256 @base.handle_errors
257 def list_actions_detail(self, **kwargs):
258 """Lists details of all existing actions"""
259 return self._list_request('/actions/detail', **kwargs)
260
261 @base.handle_errors
262 def show_action(self, action_uuid):
263 """Gets a specific action
264
265 :param action_uuid: Unique identifier of the action
266 :return: Serialized action as a dictionary
267 """
268 return self._show_request('/actions', action_uuid)
269
270 # ### STRATEGIES ### #
271
272 @base.handle_errors
273 def list_strategies(self, **kwargs):
274 """List all existing strategies"""
275 return self._list_request('/strategies', **kwargs)
276
277 @base.handle_errors
278 def list_strategies_detail(self, **kwargs):
279 """Lists details of all existing strategies"""
280 return self._list_request('/strategies/detail', **kwargs)
281
282 @base.handle_errors
283 def show_strategy(self, strategy):
284 """Gets a specific strategy
285
286 :param strategy_id: Name of the strategy
287 :return: Serialized strategy as a dictionary
288 """
289 return self._show_request('/strategies', strategy)
290
291 # ### SCORING ENGINE ### #
292
293 @base.handle_errors
294 def list_scoring_engines(self, **kwargs):
295 """List all existing scoring_engines"""
296 return self._list_request('/scoring_engines', **kwargs)
297
298 @base.handle_errors
299 def list_scoring_engines_detail(self, **kwargs):
300 """Lists details of all existing scoring_engines"""
301 return self._list_request('/scoring_engines/detail', **kwargs)
302
303 @base.handle_errors
304 def show_scoring_engine(self, scoring_engine):
305 """Gets a specific scoring_engine
306
307 :param scoring_engine: UUID or Name of the scoring_engine
308 :return: Serialized scoring_engine as a dictionary
309 """
310 return self._show_request('/scoring_engines', scoring_engine)
311
312 # ### SERVICES ### #
313
314 @base.handle_errors
315 def list_services(self, **kwargs):
316 """List all existing services"""
317 return self._list_request('/services', **kwargs)
318
319 @base.handle_errors
320 def list_services_detail(self, **kwargs):
321 """Lists details of all existing services"""
322 return self._list_request('/services/detail', **kwargs)
323
324 @base.handle_errors
325 def show_service(self, service):
326 """Gets a specific service
327
328 :param service: Name of the strategy
329 :return: Serialized strategy as a dictionary
330 """
331 return self._show_request('/services', service)