forked from openstack/rally
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
390 lines (273 loc) · 11.7 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# Copyright 2013: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Defines interface for DB access.
The underlying driver is loaded as a :class:`LazyPluggable`.
Functions in this module are imported into the rally.common.db namespace.
Call these functions from rally.common.db namespace, not the
rally.common.db.api namespace.
All functions in this module return objects that implement a dictionary-like
interface. Currently, many of these objects are sqlalchemy objects that
implement a dictionary interface. However, a future goal is to have all of
these objects be simple dictionaries.
**Related Flags**
:backend: string to lookup in the list of LazyPluggable backends.
`sqlalchemy` is the only supported backend right now.
:connection: string specifying the sqlalchemy connection to use, like:
`sqlite:///var/lib/cinder/cinder.sqlite`.
:enable_new_services: when adding a new service to the database, is it in the
pool of available hardware (Default: True)
"""
from oslo_config import cfg
from oslo_db import api as db_api
from oslo_db import options as db_options
CONF = cfg.CONF
db_options.set_defaults(CONF, connection="sqlite:////tmp/rally.sqlite",
sqlite_db="rally.sqlite")
IMPL = None
def get_impl():
global IMPL
if not IMPL:
_BACKEND_MAPPING = {"sqlalchemy": "rally.common.db.sqlalchemy.api"}
IMPL = db_api.DBAPI.from_config(CONF, backend_mapping=_BACKEND_MAPPING)
return IMPL
def db_cleanup():
"""Recreate engine."""
get_impl().db_cleanup()
def db_create():
"""Initialize DB. This method will drop existing database."""
get_impl().db_create()
def db_drop():
"""Drop DB. This method drop existing database."""
get_impl().db_drop()
def task_get(uuid):
"""Returns task by uuid.
:param uuid: UUID of the task.
:raises TaskNotFound: if the task does not exist.
:returns: task dict with data on the task.
"""
return get_impl().task_get(uuid)
def task_get_status(uuid):
"""Returns task by uuid.
:param uuid: UUID of the task.
:raises TaskNotFound: if the task does not exist.
:returns: task dict with data on the task.
"""
return get_impl().task_get_status(uuid)
def task_get_detailed_last():
"""Returns the most recently created task."""
return get_impl().task_get_detailed_last()
def task_get_detailed(uuid):
"""Returns task with results by uuid.
:param uuid: UUID of the task.
:returns: task dict with data on the task and its results.
"""
return get_impl().task_get_detailed(uuid)
def task_create(values):
"""Create task record in DB.
:param values: dict with record values.
:returns: task dict with data on the task.
"""
return get_impl().task_create(values)
def task_update(uuid, values):
"""Update task by values.
:param uuid: UUID of the task.
:param values: dict with record values.
:raises TaskNotFound: if the task does not exist.
:returns: new updated task dict with data on the task.
"""
return get_impl().task_update(uuid, values)
def task_update_status(task_uuid, status, allowed_statuses):
"""Update task status with specified value.
:param task_uuid: string with UUID of Task instance.
:param status: new value to wrote into db instead of status.
:param allowed_statuses: list of expected statuses to update in db.
:raises RallyException: if task not found with specified status.
:returns: the count of rows match as returned by the database's
"row count" feature
"""
return get_impl().task_update_status(task_uuid, allowed_statuses,
status)
def task_list(status=None, deployment=None):
"""Get a list of tasks.
:param status: Task status to filter the returned list on. If set to
None, all the tasks will be returned.
:param deployment_id: deployment UUID to filter the returned list on.
if set to None tasks from all deployments well be
returned.
:returns: A list of dicts with data on the tasks.
"""
return get_impl().task_list(status=status, deployment=deployment)
def task_delete(uuid, status=None):
"""Delete a task.
This method removes the task by the uuid, but if the status
argument is specified, then the task is removed only when these
statuses are equal otherwise an exception is raised.
:param uuid: UUID of the task.
:raises TaskNotFound: if the task does not exist.
:raises TaskInvalidStatus: if the status of the task does not
equal to the status argument.
"""
return get_impl().task_delete(uuid, status=status)
def task_result_get_all_by_uuid(task_uuid):
"""Get list of task results.
:param task_uuid: string with UUID of Task instance.
:returns: list instances of TaskResult.
"""
return get_impl().task_result_get_all_by_uuid(task_uuid)
def task_result_create(task_uuid, key, data):
"""Append result record to task.
:param task_uuid: string with UUID of Task instance.
:param key: key expected to update in task result.
:param data: data expected to update in task result.
:returns: TaskResult instance appended.
"""
return get_impl().task_result_create(task_uuid, key, data)
def deployment_create(values):
"""Create a deployment from the values dictionary.
:param values: dict with record values on the deployment.
:returns: a dict with data on the deployment.
"""
return get_impl().deployment_create(values)
def deployment_delete(uuid):
"""Delete a deployment by UUID.
:param uuid: UUID of the deployment.
:raises DeploymentNotFound: if the deployment does not exist.
:raises DeploymentIsBusy: if the resource is not enough.
"""
return get_impl().deployment_delete(uuid)
def deployment_get(deployment):
"""Get a deployment by UUID.
:param deployment: UUID or name of the deployment.
:raises DeploymentNotFound: if the deployment does not exist.
:returns: a dict with data on the deployment.
"""
return get_impl().deployment_get(deployment)
def deployment_update(uuid, values):
"""Update a deployment by values.
:param uuid: UUID of the deployment.
:param values: dict with items to update.
:raises DeploymentNotFound: if the deployment does not exist.
:returns: a dict with data on the deployment.
"""
return get_impl().deployment_update(uuid, values)
def deployment_list(status=None, parent_uuid=None, name=None):
"""Get list of deployments.
:param status: if None returns any deployments with any status.
:param parent_uuid: filter by parent. If None, return only "root"
deployments.
:param name: Name of deployment
:returns: a list of dicts with data on the deployments.
"""
return get_impl().deployment_list(status=status, parent_uuid=parent_uuid,
name=name)
def resource_create(values):
"""Create a resource from the values dictionary.
:param values: a dict with data on the resource.
:returns: a dict with updated data on the resource.
"""
return get_impl().resource_create(values)
def resource_get_all(deployment_uuid, provider_name=None, type=None):
"""Return resources of a deployment.
:param deployment_uuid: filter by uuid of a deployment
:param provider_name: filter by provider_name, if is None, then
return all prorivders
:param type: filter by type, if is None, then return all types
:returns: a list of dicts with data on a resource
"""
return get_impl().resource_get_all(deployment_uuid,
provider_name=provider_name,
type=type)
def resource_delete(id):
"""Delete a resource.
:param id: ID of a resource.
:raises ResourceNotFound: if the resource does not exist.
"""
return get_impl().resource_delete(id)
def verification_create(deployment_uuid):
"""Create Verification record in DB.
:param deployment_uuid: UUID of the deployment.
:returns: a dict with verification data.
"""
return get_impl().verification_create(deployment_uuid)
def verification_get(verification_uuid):
"""Returns verification by UUID.
:param id: UUID of the verification.
:raises NotFoundException: if verification does not exist.
:returns: a dict with verification data.
"""
return get_impl().verification_get(verification_uuid)
def verification_delete(verification_uuid):
"""Delete verification.
:param verification_uuid: UUID of the verification.
:raises NotFoundException: if verification does not exist.
"""
return get_impl().verification_delete(verification_uuid)
def verification_update(uuid, values):
"""Update verification by values.
:param uuid: UUID of the verification.
:param values: dict with record values.
:raises NotFoundException: if verification does not exist.
:returns: new updated task dict with data on the task.
"""
return get_impl().verification_update(uuid, values)
def verification_list(status=None):
"""Get a list of verifications.
:param status: Verification status to filter the returned list on.
:returns: A list of dicts with data on the verifications.
"""
return get_impl().verification_list(status=status)
def verification_result_get(verification_uuid):
"""Get dict of verification results.
:param verification_uuid: string with UUID of Verification instance.
:returns: dict instance of VerificationResult.
"""
return get_impl().verification_result_get(verification_uuid)
def verification_result_create(verification_uuid, values):
"""Append result record to verification.
:param verification_uuid: string with UUID of Verification instance.
:param values: dict with record values.
:returns: TaskResult instance appended.
"""
return get_impl().verification_result_create(verification_uuid, values)
def register_worker(values):
"""Register a new worker service at the specified hostname.
:param values: A dict of values which must contain the following:
{
"hostname": the unique hostname which identifies
this worker service.
}
:returns: A worker.
:raises WorkerAlreadyRegistered: if worker already registered
"""
return get_impl().register_worker(values)
def get_worker(hostname):
"""Retrieve a worker service record from the database.
:param hostname: The hostname of the worker service.
:returns: A worker.
:raises WorkerNotFound: if worker not found
"""
return get_impl().get_worker(hostname)
def unregister_worker(hostname):
"""Unregister this worker with the service registry.
:param hostname: The hostname of the worker service.
:raises WorkerNotFound: if worker not found
"""
get_impl().unregister_worker(hostname)
def update_worker(hostname):
"""Mark a worker as active by updating its "updated_at" property.
:param hostname: The hostname of this worker service.
:raises WorkerNotFound: if worker not found
"""
get_impl().update_worker(hostname)