summaryrefslogtreecommitdiff
path: root/iotronic/db/api.py
blob: dfdf4d23d32a929b01233c0f7602bfa0f22baf8a (plain)
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# -*- encoding: utf-8 -*-
#
# Copyright 2013 Hewlett-Packard Development Company, L.P.
#
# 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.
"""
Base classes for storage engines
"""

import abc

from oslo_config import cfg
from oslo_db import api as db_api
import six

_BACKEND_MAPPING = {'sqlalchemy': 'iotronic.db.sqlalchemy.api'}
IMPL = db_api.DBAPI.from_config(cfg.CONF,
                                backend_mapping=_BACKEND_MAPPING,
                                lazy=True)


def get_instance():
    """Return a DB API instance."""
    return IMPL


@six.add_metaclass(abc.ABCMeta)
class Connection(object):
    """Base class for storage system connections."""

    @abc.abstractmethod
    def __init__(self):
        """Constructor."""

    @abc.abstractmethod
    def get_boardinfo_list(self, columns=None, filters=None, limit=None,
                           marker=None, sort_key=None, sort_dir=None):
        """Get specific columns for matching boards.

        Return a list of the specified columns for all boards that match the
        specified filters.

        :param columns: List of column names to return.
                        Defaults to 'id' column when columns == None.
        :param filters: Filters to apply. Defaults to None.

                        :associated: True | False
                        :reserved: True | False
                        :maintenance: True | False
                        :provision_state: provision state of board
                        :provisioned_before:
                            boards with provision_updated_at field before this
                            interval in seconds
        :param limit: Maximum number of boards to return.
        :param marker: the last item of the previous page; we return the next
                       result set.
        :param sort_key: Attribute by which results should be sorted.
        :param sort_dir: direction in which results should be sorted.
                         (asc, desc)
        :returns: A list of tuples of the specified columns.
        """

    @abc.abstractmethod
    def get_board_list(self, filters=None, limit=None, marker=None,
                       sort_key=None, sort_dir=None):
        """Return a list of boards.

        :param filters: Filters to apply. Defaults to None.

                        :associated: True | False
                        :reserved: True | False
                        :maintenance: True | False
                        :provision_state: provision state of board
                        :provisioned_before:
                            boards with provision_updated_at field before this
                            interval in seconds
        :param limit: Maximum number of boards to return.
        :param marker: the last item of the previous page; we return the next
                       result set.
        :param sort_key: Attribute by which results should be sorted.
        :param sort_dir: direction in which results should be sorted.
                         (asc, desc)
        """

    @abc.abstractmethod
    def create_board(self, values):
        """Create a new board.

        :param values: A dict containing several items used to identify
                       and track the board, and several dicts which are passed
                       into the Drivers when managing this board. For example:

                       ::

                        {
                         'uuid': uuidutils.generate_uuid(),
                         'instance_uuid': None,
                         'power_state': states.POWER_OFF,
                         'provision_state': states.AVAILABLE,
                         'properties': { ... },
                         'extra': { ... },
                        }
        :returns: A board.
        """

    @abc.abstractmethod
    def get_board_by_id(self, board_id):
        """Return a board.

        :param board_id: The id of a board.
        :returns: A board.
        """

    @abc.abstractmethod
    def get_board_by_uuid(self, board_uuid):
        """Return a board.

        :param board_uuid: The uuid of a board.
        :returns: A board.
        """

    @abc.abstractmethod
    def get_board_id_by_uuid(self, board_uuid):
        """Return a board id.

        :param board_uuid: The uuid of a board.
        # :returns: A board.id.
        """

    @abc.abstractmethod
    def get_board_by_name(self, board_name):
        """Return a board.

        :param board_name: The logical name of a board.
        :returns: A board.
        """

    @abc.abstractmethod
    def get_board_by_code(self, instance):
        """Return a board.

        :param instance: The instance code or uuid to search for.
        :returns: A board.
        """

    @abc.abstractmethod
    def destroy_board(self, board_id):
        """Destroy a board and all associated interfaces.

        :param board_id: The id or uuid of a board.
        """

    @abc.abstractmethod
    def update_board(self, board_id, values):
        """Update properties of a board.

        :param board_id: The id or uuid of a board.
        :param values: Dict of values to update.
        :returns: A board.
        :raises: BoardAssociated
        :raises: BoardNotFound
        """

    @abc.abstractmethod
    def get_conductor(self, hostname):
        """Retrieve a conductor's service record from the database.

        :param hostname: The hostname of the conductor service.
        :returns: A conductor.
        :raises: ConductorNotFound
        """

    @abc.abstractmethod
    def unregister_conductor(self, hostname):
        """Remove this conductor from the service registry immediately.

        :param hostname: The hostname of this conductor service.
        :raises: ConductorNotFound
        """

    @abc.abstractmethod
    def touch_conductor(self, hostname):
        """Mark a conductor as active by updating its 'updated_at' property.

        :param hostname: The hostname of this conductor service.
        :raises: ConductorNotFound
        """

    @abc.abstractmethod
    def create_session(self, values):
        """Create a new location.

        :param values: session_id.
        """

    @abc.abstractmethod
    def update_session(self, session_id, values):
        """Update properties of an session.

        :param session_id: The id of a session.
        :param values: Dict of values to update.
        :returns: A session.
        """

    @abc.abstractmethod
    def get_session_by_board_uuid(self, board_uuid, valid):
        """Return a Wamp session of a Board

        :param board_uuid: Filters to apply. Defaults to None.
        :param valid: is valid
        :returns: A session.
        """

    @abc.abstractmethod
    def get_session_by_id(self, session_id):
        """Return a Wamp session

        :param session_id: The id of a session.
         :returns: A session.
        """

    @abc.abstractmethod
    def create_location(self, values):
        """Create a new location.

        :param values: Dict of values.
        """

    @abc.abstractmethod
    def update_location(self, location_id, values):
        """Update properties of an location.

        :param location_id: The id of a location.
        :param values: Dict of values to update.
        :returns: A location.
        """

    @abc.abstractmethod
    def destroy_location(self, location_id):
        """Destroy an location.

        :param location_id: The id or MAC of a location.
        """

    @abc.abstractmethod
    def get_locations_by_board_id(self, board_id, limit=None, marker=None,
                                  sort_key=None, sort_dir=None):
        """List all the locations for a given board.

        :param board_id: The integer board ID.
        :param limit: Maximum number of locations to return.
        :param marker: the last item of the previous page; we return the next
                       result set.
        :param sort_key: Attribute by which results should be sorted
        :param sort_dir: direction in which results should be sorted
                         (asc, desc)
        :returns: A list of locations.
        """

    @abc.abstractmethod
    def get_valid_wpsessions_list(self):
        """Return a list of wpsession."""

    @abc.abstractmethod
    def get_wampagent(self, hostname):
        """Retrieve a wampagent's service record from the database.

        :param hostname: The hostname of the wampagent service.
        :returns: A wampagent.
        :raises: WampAgentNotFound
        """

    @abc.abstractmethod
    def get_registration_wampagent(self):
        """Retrieve the registration wampagent record from the database.

        :returns: A wampagent.
        :raises: WampAgentNotFound
        """

    @abc.abstractmethod
    def unregister_wampagent(self, hostname):
        """Remove this wampagent from the service registry immediately.

        :param hostname: The hostname of this wampagent service.
        :raises: WampAgentNotFound
        """

    @abc.abstractmethod
    def touch_wampagent(self, hostname):
        """Mark a wampagent as active by updating its 'updated_at' property.

        :param hostname: The hostname of this wampagent service.
        :raises: WampAgentNotFound
        """

    @abc.abstractmethod
    def get_wampagent_list(self, filters=None, limit=None, marker=None,
                           sort_key=None, sort_dir=None):
        """Return a list of wampagents.

        :param filters: Filters to apply. Defaults to None.
        :param limit: Maximum number of wampagents to return.
        :param marker: the last item of the previous page; we return the next
                       result set.
        :param sort_key: Attribute by which results should be sorted.
        :param sort_dir: direction in which results should be sorted.
                         (asc, desc)
        """

    @abc.abstractmethod
    def get_plugin_by_id(self, plugin_id):
        """Return a plugin.

        :param plugin_id: The id of a plugin.
        :returns: A plugin.
        """

    @abc.abstractmethod
    def get_plugin_by_uuid(self, plugin_uuid):
        """Return a plugin.

        :param plugin_uuid: The uuid of a plugin.
        :returns: A plugin.
        """

    @abc.abstractmethod
    def get_plugin_by_name(self, plugin_name):
        """Return a plugin.

        :param plugin_name: The logical name of a plugin.
        :returns: A plugin.
        """

    @abc.abstractmethod
    def create_plugin(self, values):
        """Create a new plugin.

        :param values: A dict containing several items used to identify
                       and track the plugin
        :returns: A plugin.
        """

    @abc.abstractmethod
    def destroy_plugin(self, plugin_id):
        """Destroy a plugin and all associated interfaces.

        :param plugin_id: The id or uuid of a plugin.
        """

    @abc.abstractmethod
    def update_plugin(self, plugin_id, values):
        """Update properties of a plugin.

        :param plugin_id: The id or uuid of a plugin.
        :param values: Dict of values to update.
        :returns: A plugin.
        :raises: PluginAssociated
        :raises: PluginNotFound
        """

    @abc.abstractmethod
    def get_injection_plugin_by_board_uuid(self, board_uuid):
        """get an injection of a plugin using a board_uuid

        :param board_uuid: The id or uuid of a board.
        :returns: An injection_plugin.

        """

    @abc.abstractmethod
    def get_injection_plugin_by_uuids(self, board_uuid, plugin_uuid):
        """get an injection of a plugin using a board_uuid and plugin_uuid

        :param board_uuid: The id or uuid of a board.
        :param plugin_uuid: The id or uuid of a plugin.
        :returns: An injection_plugin.

        """

    @abc.abstractmethod
    def create_injection_plugin(self, values):
        """Create a new injection_plugin.

        :param values: A dict containing several items used to identify
                       and track the plugin
        :returns: An injection plugin.
        """

    @abc.abstractmethod
    def destroy_injection_plugin(self, injection_plugin_id):
        """Destroy an injection plugin and all associated interfaces.

        :param injection_plugin_id: The id or uuid of a plugin.
        """

    @abc.abstractmethod
    def update_injection_plugin(self, plugin_injection_id, values):
        """Update properties of a plugin.

        :param plugin_id: The id or uuid of a plugin.
        :param values: Dict of values to update.
        :returns: A plugin.
        :raises: PluginAssociated
        :raises: PluginNotFound
        """

    @abc.abstractmethod
    def get_injection_plugin_list(self, board_uuid):
        """Return a list of injection_plugins.

        :param board_uuid: The id or uuid of a plugin.
        :returns: A list of InjectionPlugins on the board.
        """

    @abc.abstractmethod
    def get_service_by_id(self, service_id):
        """Return a service.

        :param service_id: The id of a service.
        :returns: A service.
        """

    @abc.abstractmethod
    def get_service_by_uuid(self, service_uuid):
        """Return a service.

        :param service_uuid: The uuid of a service.
        :returns: A service.
        """

    @abc.abstractmethod
    def get_service_by_name(self, service_name):
        """Return a service.

        :param service_name: The logical name of a service.
        :returns: A service.
        """

    @abc.abstractmethod
    def create_service(self, values):
        """Create a new service.

        :param values: A dict containing several items used to identify
                       and track the service
        :returns: A service.
        """

    @abc.abstractmethod
    def destroy_service(self, service_id):
        """Destroy a service and all associated interfaces.

        :param service_id: The id or uuid of a service.
        """

    @abc.abstractmethod
    def update_service(self, service_id, values):
        """Update properties of a service.

        :param service_id: The id or uuid of a service.
        :param values: Dict of values to update.
        :returns: A service.
        :raises: ServiceAssociated
        :raises: ServiceNotFound
        """

    @abc.abstractmethod
    def get_exposed_services_by_board_uuid(self, board_uuid):
        """get an exposed of a service using a board_uuid

        :param board_uuid: The id or uuid of a board.
        :returns: An exposed_service.

        """

    @abc.abstractmethod
    def get_exposed_service_by_uuids(self, board_uuid, service_uuid):
        """get an exposed of a service using a board_uuid and service_uuid

        :param board_uuid: The id or uuid of a board.
        :param service_uuid: The id or uuid of a service.
        :returns: An exposed_service.

        """

    @abc.abstractmethod
    def create_exposed_service(self, values):
        """Create a new exposed_service.

        :param values: A dict containing several items used to identify
                       and track the service
        :returns: An exposed service.
        """

    @abc.abstractmethod
    def destroy_exposed_service(self, exposed_service_id):
        """Destroy an exposed service and all associated interfaces.

        :param exposed_service_id: The id or uuid of a service.
        """

    @abc.abstractmethod
    def update_exposed_service(self, service_exposed_id, values):
        """Update properties of a service.

        :param service_id: The id or uuid of a service.
        :param values: Dict of values to update.
        :returns: A service.
        :raises: ServiceAssociated
        :raises: ServiceNotFound
        """

    @abc.abstractmethod
    def get_exposed_service_list(self, board_uuid):
        """Return a list of exposed_services.

        :param board_uuid: The id or uuid of a service.
        :returns: A list of ExposedServices on the board.
        """