Browse Source

stop using common db mixin

All of the methods of common db mixin are available via neutron-lib
and the mixin will be removed before long.
This patch switches the code over to use neutron-lib's APIs rather
than those of the mixin as well as top using the mixin as a parent
class.

Change-Id: I0cd42b3bb1b9b365ef9770ead006b54a2828453f
tags/10.0.0.0b1
Boden R 4 months ago
parent
commit
5b43affe39
1 changed files with 27 additions and 21 deletions
  1. 27
    21
      networking_bgpvpn/neutron/db/bgpvpn_db.py

+ 27
- 21
networking_bgpvpn/neutron/db/bgpvpn_db.py View File

@@ -20,7 +20,6 @@ import sqlalchemy as sa
20 20
 from sqlalchemy import orm
21 21
 from sqlalchemy.orm import exc
22 22
 
23
-from neutron.db import common_db_mixin
24 23
 from neutron.db import standard_attr
25 24
 
26 25
 from neutron_lib.api.definitions import bgpvpn as bgpvpn_def
@@ -30,6 +29,7 @@ from neutron_lib.db import api as db_api
30 29
 from neutron_lib.db import constants as db_const
31 30
 from neutron_lib.db import model_base
32 31
 from neutron_lib.db import model_query
32
+from neutron_lib.db import utils as db_utils
33 33
 from neutron_lib.plugins import directory
34 34
 
35 35
 from networking_bgpvpn.neutron.extensions import bgpvpn as bgpvpn_ext
@@ -244,7 +244,7 @@ def port_assoc_route_dict_from_db(route_db):
244 244
     return route
245 245
 
246 246
 
247
-class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
247
+class BGPVPNPluginDb(object):
248 248
     """BGPVPN service plugin database class using SQLAlchemy models."""
249 249
 
250 250
     def __new__(cls, *args, **kwargs):
@@ -300,7 +300,7 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
300 300
             res[bgpvpn_rc_def.LOCAL_PREF_KEY] = bgpvpn_db.get(
301 301
                 bgpvpn_rc_def.LOCAL_PREF_KEY)
302 302
 
303
-        return self._fields(res, fields)
303
+        return db_utils.resource_fields(res, fields)
304 304
 
305 305
     @db_api.CONTEXT_WRITER
306 306
     def create_bgpvpn(self, context, bgpvpn):
@@ -328,13 +328,14 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
328 328
 
329 329
     @db_api.CONTEXT_READER
330 330
     def get_bgpvpns(self, context, filters=None, fields=None):
331
-        return self._get_collection(context, BGPVPN, self._make_bgpvpn_dict,
332
-                                    filters=filters, fields=fields)
331
+        return model_query.get_collection(
332
+            context, BGPVPN, self._make_bgpvpn_dict,
333
+            filters=filters, fields=fields)
333 334
 
334 335
     @db_api.CONTEXT_READER
335 336
     def _get_bgpvpn(self, context, id):
336 337
         try:
337
-            return self._get_by_id(context, BGPVPN, id)
338
+            return model_query.get_by_id(context, BGPVPN, id)
338 339
         except exc.NoResultFound:
339 340
             raise bgpvpn_ext.BGPVPNNotFound(id=id)
340 341
 
@@ -376,12 +377,12 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
376 377
                'tenant_id': net_assoc_db['tenant_id'],
377 378
                'bgpvpn_id': net_assoc_db['bgpvpn_id'],
378 379
                'network_id': net_assoc_db['network_id']}
379
-        return self._fields(res, fields)
380
+        return db_utils.resource_fields(res, fields)
380 381
 
381 382
     @db_api.CONTEXT_READER
382 383
     def _get_net_assoc(self, context, assoc_id, bgpvpn_id):
383 384
         try:
384
-            query = self._model_query(context, BGPVPNNetAssociation)
385
+            query = model_query.query_with_hooks(context, BGPVPNNetAssociation)
385 386
             return query.filter(BGPVPNNetAssociation.id == assoc_id,
386 387
                                 BGPVPNNetAssociation.bgpvpn_id == bgpvpn_id
387 388
                                 ).one()
@@ -417,9 +418,10 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
417 418
         if not filters:
418 419
             filters = {}
419 420
         filters['bgpvpn_id'] = [bgpvpn_id]
420
-        return self._get_collection(context, BGPVPNNetAssociation,
421
-                                    self._make_net_assoc_dict,
422
-                                    filters, fields)
421
+        return model_query.get_collection(
422
+            context, BGPVPNNetAssociation,
423
+            self._make_net_assoc_dict,
424
+            filters, fields)
423 425
 
424 426
     @db_api.CONTEXT_WRITER
425 427
     def delete_net_assoc(self, context, assoc_id, bgpvpn_id):
@@ -440,12 +442,13 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
440 442
                'advertise_extra_routes': router_assoc_db[
441 443
                    'advertise_extra_routes']
442 444
                }
443
-        return self._fields(res, fields)
445
+        return db_utils.resource_fields(res, fields)
444 446
 
445 447
     @db_api.CONTEXT_READER
446 448
     def _get_router_assoc(self, context, assoc_id, bgpvpn_id):
447 449
         try:
448
-            query = self._model_query(context, BGPVPNRouterAssociation)
450
+            query = model_query.query_with_hooks(
451
+                context, BGPVPNRouterAssociation)
449 452
             return query.filter(BGPVPNRouterAssociation.id == assoc_id,
450 453
                                 BGPVPNRouterAssociation.bgpvpn_id == bgpvpn_id
451 454
                                 ).one()
@@ -482,9 +485,10 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
482 485
         if not filters:
483 486
             filters = {}
484 487
         filters['bgpvpn_id'] = [bgpvpn_id]
485
-        return self._get_collection(context, BGPVPNRouterAssociation,
486
-                                    self._make_router_assoc_dict,
487
-                                    filters, fields)
488
+        return model_query.get_collection(
489
+            context, BGPVPNRouterAssociation,
490
+            self._make_router_assoc_dict,
491
+            filters, fields)
488 492
 
489 493
     @db_api.CONTEXT_WRITER
490 494
     def update_router_assoc(self, context, assoc_id, bgpvpn_id, router_assoc):
@@ -514,12 +518,13 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
514 518
                'port_id': port_assoc_db['port_id'],
515 519
                'advertise_fixed_ips': port_assoc_db['advertise_fixed_ips'],
516 520
                'routes': routes}
517
-        return self._fields(res, fields)
521
+        return db_utils.resource_fields(res, fields)
518 522
 
519 523
     @db_api.CONTEXT_READER
520 524
     def _get_port_assoc(self, context, assoc_id, bgpvpn_id):
521 525
         try:
522
-            query = self._model_query(context, BGPVPNPortAssociation)
526
+            query = model_query.query_with_hooks(
527
+                context, BGPVPNPortAssociation)
523 528
             return query.filter(BGPVPNPortAssociation.id == assoc_id,
524 529
                                 BGPVPNPortAssociation.bgpvpn_id == bgpvpn_id
525 530
                                 ).one()
@@ -563,9 +568,10 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
563 568
         if not filters:
564 569
             filters = {}
565 570
         filters['bgpvpn_id'] = [bgpvpn_id]
566
-        return self._get_collection(context, BGPVPNPortAssociation,
567
-                                    self._make_port_assoc_dict,
568
-                                    filters, fields)
571
+        return model_query.get_collection(
572
+            context, BGPVPNPortAssociation,
573
+            self._make_port_assoc_dict,
574
+            filters, fields)
569 575
 
570 576
     @db_api.CONTEXT_READER
571 577
     def update_port_assoc(self, context, assoc_id, bgpvpn_id, port_assoc):

Loading…
Cancel
Save