-
Notifications
You must be signed in to change notification settings - Fork 5
/
api.py
284 lines (189 loc) · 10 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
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2013 TrilioData, Inc.
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# 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 raksha.db namespace. Call these
functions from raksha.db namespace, not the raksha.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**
:db_backend: string to lookup in the list of LazyPluggable backends.
`sqlalchemy` is the only supported backend right now.
:sql_connection: string specifying the sqlalchemy connection to use, like:
`sqlite:///var/lib/raksha/raksha.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 raksha import exception
from raksha import flags
from raksha import utils
db_opts = [
cfg.StrOpt('db_backend',
default='sqlalchemy',
help='The backend to use for db'),
cfg.BoolOpt('enable_new_services',
default=True,
help='Services to be added to the available pool on create'),
cfg.StrOpt('backupjob_name_template',
default='backupjob-%s',
help='Template string to be used to generate backup job names'), ]
FLAGS = flags.FLAGS
FLAGS.register_opts(db_opts)
IMPL = utils.LazyPluggable('db_backend',
sqlalchemy='raksha.db.sqlalchemy.api')
class NoMoreTargets(exception.RakshaException):
"""No more available targets"""
pass
###################
def service_destroy(context, service_id):
"""Destroy the service or raise if it does not exist."""
return IMPL.service_destroy(context, service_id)
def service_get(context, service_id):
"""Get a service or raise if it does not exist."""
return IMPL.service_get(context, service_id)
def service_get_by_host_and_topic(context, host, topic):
"""Get a service by host it's on and topic it listens to."""
return IMPL.service_get_by_host_and_topic(context, host, topic)
def service_get_all(context, disabled=None):
"""Get all services."""
return IMPL.service_get_all(context, disabled)
def service_get_all_by_topic(context, topic):
"""Get all services for a given topic."""
return IMPL.service_get_all_by_topic(context, topic)
def service_get_all_by_host(context, host):
"""Get all services for a given host."""
return IMPL.service_get_all_by_host(context, host)
def service_get_all_volume_sorted(context):
"""Get all volume services sorted by volume count.
:returns: a list of (Service, volume_count) tuples.
"""
return IMPL.service_get_all_volume_sorted(context)
def service_get_by_args(context, host, binary):
"""Get the state of an service by node name and binary."""
return IMPL.service_get_by_args(context, host, binary)
def service_create(context, values):
"""Create a service from the values dictionary."""
return IMPL.service_create(context, values)
def service_update(context, service_id, values):
"""Set the given properties on an service and update it.
Raises NotFound if service does not exist.
"""
return IMPL.service_update(context, service_id, values)
###################
def backupjob_get(context, backupjob_id):
"""Get a backupjob or raise if it does not exist."""
return IMPL.backupjob_get(context, backupjob_id)
def backupjob_show(context, backupjob_id):
"""Get more details of the backupjob or raise if it does not exist."""
return IMPL.backupjob_show(context, backupjob_id)
def backupjob_get_all(context):
"""Get all backup jobs."""
return IMPL.backupjob_get_all(context)
def backupjob_get_all_by_host(context, host):
"""Get all backupjobs belonging to a host."""
return IMPL.backupjob_get_all_by_host(context, host)
def backupjob_create(context, values):
"""Create a backup job from the values dictionary."""
return IMPL.backupjob_create(context, values)
def backupjob_get_all_by_project(context, project_id):
"""Get all backups belonging to a project."""
return IMPL.backupjob_get_all_by_project(context, project_id)
def backupjob_update(context, backupjob_id, values):
"""
Set the given properties on a backupjob and update it.
Raises NotFound if backupjob does not exist.
"""
return IMPL.backupjob_update(context, backupjob_id, values)
def backupjob_destroy(context, backupjob_id):
"""Destroy the backup job or raise if it does not exist."""
return IMPL.backupjob_destroy(context, backupjob_id)
def backupjob_vms_create(context, values):
return IMPL.backupjob_vms_create(context, values)
def backupjob_vms_get(context, backupjob_id, session=None):
return IMPL.backupjob_vms_get(context, backupjob_id, session)
def backupjob_vms_destroy(context, vm_id, backupjob_id):
return IMPL.backupjob_vms_destroy(context, vm_id, backupjob_id)
def scheduledjob_create(context, scheduledjob):
return IMPL.scheduledjob_create(context, scheduledjob)
def scheduledjob_delete(context, scheduledjob):
return IMPL.scheduledjob_delete(context, scheduledjob)
def scheduledjob_get(context):
return IMPL.scheduledjob_get(context)
def scheduledjob_update(context, scheduledjob):
return IMPL.scheduledjob_update(context, scheduledjob)
def backupjobrun_create(context, values):
return IMPL.backupjobrun_create(context, values)
def backupjobrun_get(context, backupjobrun_id, session=None):
return IMPL.backupjobrun_get(context, backupjobrun_id, session)
def backupjobrun_get_all(context, backupjob_id=None):
return IMPL.backupjobrun_get_all(context, backupjob_id)
def backupjobrun_get_all_by_project(context, project_id):
"""Get all backups belonging to a project."""
return IMPL.backupjobrun_get_all_by_project(context, project_id)
def backupjobrun_get_all_by_project_backupjob(context, project_id, backupjob_id):
"""Get all backups belonging to a project and backupjob"""
return IMPL.backupjobrun_get_all_by_project_backupjob(context, project_id, backupjob_id)
def backupjobrun_show(context, backupjobrun_id):
"""Get more details of the backupjobrun or raise if it does not exist."""
return IMPL.backupjobrun_show(context, backupjobrun_id)
def backupjobrun_update(context, backupjobrun_id, values):
return IMPL.backupjobrun_update(context, backupjobrun_id, values)
def backupjobrun_vm_create(context, values):
return IMPL.backupjobrun_vm_create(context, values)
def backupjobrun_vm_get(context, backupjobrun_id, session=None):
return IMPL.backupjobrun_vm_get(context, backupjobrun_id, session)
def backupjobrun_vm_destroy(context, vm_id, backupjobrun_id):
return IMPL.backupjobrun_vm_destroy(context, vm_id, backupjobrun_id)
def vm_recent_backupjobrun_create(context, values):
return IMPL.vm_recent_backupjobrun_create(context, values)
def vm_recent_backupjobrun_get(context, vm_id, session=None):
return IMPL.vm_recent_backupjobrun_get(context, vm_id, session)
def vm_recent_backupjobrun_update(context, vm_id, values):
return IMPL.vm_recent_backupjobrun_update(context, vm_id, values)
def vm_recent_backupjobrun_destroy(context, vm_id):
return IMPL.vm_recent_backupjobrun_destroy(context, vm_id)
def backupjobrun_vm_resource_create(context, values):
return IMPL.backupjobrun_vm_resource_create(context, values)
def backupjobrun_vm_resources_get(context, vm_id, backupjobrun_id, session=None):
return IMPL.backupjobrun_vm_resources_get(context, vm_id, backupjobrun_id, session)
def backupjobrun_vm_resource_get(context, vm_id, backupjobrun_id, resource_name, session=None):
return IMPL.backupjobrun_vm_resource_get(context, vm_id, backupjobrun_id, resource_name, session)
def backupjobrun_vm_resource_get2(context, id, session=None):
return IMPL.backupjobrun_vm_resource_get2(context, id, session)
def backupjobrun_vm_resource_destroy(context, id, vm_id, backupjobrun_id):
return IMPL.backupjobrun_vm_resource_destroy(context, id, vm_id, backupjobrun_id)
def vm_resource_backup_create(context, values):
return IMPL.vm_resource_backup_create(context, values)
def vm_resource_backups_get(context, backupjobrun_vm_resource_id, session=None):
return IMPL.vm_resource_backups_get(context, backupjobrun_vm_resource_id, session)
def vm_resource_backup_get_top(context, backupjobrun_vm_resource_id, session=None):
return IMPL.vm_resource_backup_get_top(context, backupjobrun_vm_resource_id, session)
def vm_resource_backup_get(context, vm_resource_backup_id, session=None):
return IMPL.vm_resource_backup_get(context, vm_resource_backup_id, session)
def vm_resource_backups_destroy(context, backupjobrun_vm_resource_id):
return IMPL.vm_resource_backups_destroy(context, backupjobrun_vm_resource_id)
def vault_service_create(context, values):
return IMPL.vault_service_create(context, values)
def vault_service_get(context, id, session=None):
return IMPL.vault_service_get(context, id, session)
def vault_service_destroy(context, id):
return IMPL.vault_service_destroy(context, id)