summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoden R <bodenvmw@gmail.com>2019-02-07 07:48:57 -0700
committerThomas Morin <tmmorin.orange@gmail.com>2019-02-28 07:15:42 +0000
commit5b43affe39bb68c5c5429d46eccbb4f90bf73361 (patch)
tree5fbcc13f449fab9a3deec3702a79af0e63e6e3a6
parent4ccda6e5ce17d694124ad6fc4bba490d3090cc35 (diff)
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
Notes
Notes (review): Code-Review+2: Thomas Morin <tmmorin.orange@gmail.com> Code-Review+2: Édouard Thuleau <ethuleau@juniper.net> Workflow+1: Thomas Morin <tmmorin.orange@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 28 Feb 2019 15:44:49 +0000 Reviewed-on: https://review.openstack.org/635525 Project: openstack/networking-bgpvpn Branch: refs/heads/master
-rw-r--r--networking_bgpvpn/neutron/db/bgpvpn_db.py48
1 files changed, 27 insertions, 21 deletions
diff --git a/networking_bgpvpn/neutron/db/bgpvpn_db.py b/networking_bgpvpn/neutron/db/bgpvpn_db.py
index ed1f07f..b85b3f1 100644
--- a/networking_bgpvpn/neutron/db/bgpvpn_db.py
+++ b/networking_bgpvpn/neutron/db/bgpvpn_db.py
@@ -20,7 +20,6 @@ import sqlalchemy as sa
20from sqlalchemy import orm 20from sqlalchemy import orm
21from sqlalchemy.orm import exc 21from sqlalchemy.orm import exc
22 22
23from neutron.db import common_db_mixin
24from neutron.db import standard_attr 23from neutron.db import standard_attr
25 24
26from neutron_lib.api.definitions import bgpvpn as bgpvpn_def 25from neutron_lib.api.definitions import bgpvpn as bgpvpn_def
@@ -30,6 +29,7 @@ from neutron_lib.db import api as db_api
30from neutron_lib.db import constants as db_const 29from neutron_lib.db import constants as db_const
31from neutron_lib.db import model_base 30from neutron_lib.db import model_base
32from neutron_lib.db import model_query 31from neutron_lib.db import model_query
32from neutron_lib.db import utils as db_utils
33from neutron_lib.plugins import directory 33from neutron_lib.plugins import directory
34 34
35from networking_bgpvpn.neutron.extensions import bgpvpn as bgpvpn_ext 35from networking_bgpvpn.neutron.extensions import bgpvpn as bgpvpn_ext
@@ -244,7 +244,7 @@ def port_assoc_route_dict_from_db(route_db):
244 return route 244 return route
245 245
246 246
247class BGPVPNPluginDb(common_db_mixin.CommonDbMixin): 247class BGPVPNPluginDb(object):
248 """BGPVPN service plugin database class using SQLAlchemy models.""" 248 """BGPVPN service plugin database class using SQLAlchemy models."""
249 249
250 def __new__(cls, *args, **kwargs): 250 def __new__(cls, *args, **kwargs):
@@ -300,7 +300,7 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
300 res[bgpvpn_rc_def.LOCAL_PREF_KEY] = bgpvpn_db.get( 300 res[bgpvpn_rc_def.LOCAL_PREF_KEY] = bgpvpn_db.get(
301 bgpvpn_rc_def.LOCAL_PREF_KEY) 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 @db_api.CONTEXT_WRITER 305 @db_api.CONTEXT_WRITER
306 def create_bgpvpn(self, context, bgpvpn): 306 def create_bgpvpn(self, context, bgpvpn):
@@ -328,13 +328,14 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
328 328
329 @db_api.CONTEXT_READER 329 @db_api.CONTEXT_READER
330 def get_bgpvpns(self, context, filters=None, fields=None): 330 def get_bgpvpns(self, context, filters=None, fields=None):
331 return self._get_collection(context, BGPVPN, self._make_bgpvpn_dict, 331 return model_query.get_collection(
332 filters=filters, fields=fields) 332 context, BGPVPN, self._make_bgpvpn_dict,
333 filters=filters, fields=fields)
333 334
334 @db_api.CONTEXT_READER 335 @db_api.CONTEXT_READER
335 def _get_bgpvpn(self, context, id): 336 def _get_bgpvpn(self, context, id):
336 try: 337 try:
337 return self._get_by_id(context, BGPVPN, id) 338 return model_query.get_by_id(context, BGPVPN, id)
338 except exc.NoResultFound: 339 except exc.NoResultFound:
339 raise bgpvpn_ext.BGPVPNNotFound(id=id) 340 raise bgpvpn_ext.BGPVPNNotFound(id=id)
340 341
@@ -376,12 +377,12 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
376 'tenant_id': net_assoc_db['tenant_id'], 377 'tenant_id': net_assoc_db['tenant_id'],
377 'bgpvpn_id': net_assoc_db['bgpvpn_id'], 378 'bgpvpn_id': net_assoc_db['bgpvpn_id'],
378 'network_id': net_assoc_db['network_id']} 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 @db_api.CONTEXT_READER 382 @db_api.CONTEXT_READER
382 def _get_net_assoc(self, context, assoc_id, bgpvpn_id): 383 def _get_net_assoc(self, context, assoc_id, bgpvpn_id):
383 try: 384 try:
384 query = self._model_query(context, BGPVPNNetAssociation) 385 query = model_query.query_with_hooks(context, BGPVPNNetAssociation)
385 return query.filter(BGPVPNNetAssociation.id == assoc_id, 386 return query.filter(BGPVPNNetAssociation.id == assoc_id,
386 BGPVPNNetAssociation.bgpvpn_id == bgpvpn_id 387 BGPVPNNetAssociation.bgpvpn_id == bgpvpn_id
387 ).one() 388 ).one()
@@ -417,9 +418,10 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
417 if not filters: 418 if not filters:
418 filters = {} 419 filters = {}
419 filters['bgpvpn_id'] = [bgpvpn_id] 420 filters['bgpvpn_id'] = [bgpvpn_id]
420 return self._get_collection(context, BGPVPNNetAssociation, 421 return model_query.get_collection(
421 self._make_net_assoc_dict, 422 context, BGPVPNNetAssociation,
422 filters, fields) 423 self._make_net_assoc_dict,
424 filters, fields)
423 425
424 @db_api.CONTEXT_WRITER 426 @db_api.CONTEXT_WRITER
425 def delete_net_assoc(self, context, assoc_id, bgpvpn_id): 427 def delete_net_assoc(self, context, assoc_id, bgpvpn_id):
@@ -440,12 +442,13 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
440 'advertise_extra_routes': router_assoc_db[ 442 'advertise_extra_routes': router_assoc_db[
441 'advertise_extra_routes'] 443 'advertise_extra_routes']
442 } 444 }
443 return self._fields(res, fields) 445 return db_utils.resource_fields(res, fields)
444 446
445 @db_api.CONTEXT_READER 447 @db_api.CONTEXT_READER
446 def _get_router_assoc(self, context, assoc_id, bgpvpn_id): 448 def _get_router_assoc(self, context, assoc_id, bgpvpn_id):
447 try: 449 try:
448 query = self._model_query(context, BGPVPNRouterAssociation) 450 query = model_query.query_with_hooks(
451 context, BGPVPNRouterAssociation)
449 return query.filter(BGPVPNRouterAssociation.id == assoc_id, 452 return query.filter(BGPVPNRouterAssociation.id == assoc_id,
450 BGPVPNRouterAssociation.bgpvpn_id == bgpvpn_id 453 BGPVPNRouterAssociation.bgpvpn_id == bgpvpn_id
451 ).one() 454 ).one()
@@ -482,9 +485,10 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
482 if not filters: 485 if not filters:
483 filters = {} 486 filters = {}
484 filters['bgpvpn_id'] = [bgpvpn_id] 487 filters['bgpvpn_id'] = [bgpvpn_id]
485 return self._get_collection(context, BGPVPNRouterAssociation, 488 return model_query.get_collection(
486 self._make_router_assoc_dict, 489 context, BGPVPNRouterAssociation,
487 filters, fields) 490 self._make_router_assoc_dict,
491 filters, fields)
488 492
489 @db_api.CONTEXT_WRITER 493 @db_api.CONTEXT_WRITER
490 def update_router_assoc(self, context, assoc_id, bgpvpn_id, router_assoc): 494 def update_router_assoc(self, context, assoc_id, bgpvpn_id, router_assoc):
@@ -514,12 +518,13 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
514 'port_id': port_assoc_db['port_id'], 518 'port_id': port_assoc_db['port_id'],
515 'advertise_fixed_ips': port_assoc_db['advertise_fixed_ips'], 519 'advertise_fixed_ips': port_assoc_db['advertise_fixed_ips'],
516 'routes': routes} 520 'routes': routes}
517 return self._fields(res, fields) 521 return db_utils.resource_fields(res, fields)
518 522
519 @db_api.CONTEXT_READER 523 @db_api.CONTEXT_READER
520 def _get_port_assoc(self, context, assoc_id, bgpvpn_id): 524 def _get_port_assoc(self, context, assoc_id, bgpvpn_id):
521 try: 525 try:
522 query = self._model_query(context, BGPVPNPortAssociation) 526 query = model_query.query_with_hooks(
527 context, BGPVPNPortAssociation)
523 return query.filter(BGPVPNPortAssociation.id == assoc_id, 528 return query.filter(BGPVPNPortAssociation.id == assoc_id,
524 BGPVPNPortAssociation.bgpvpn_id == bgpvpn_id 529 BGPVPNPortAssociation.bgpvpn_id == bgpvpn_id
525 ).one() 530 ).one()
@@ -563,9 +568,10 @@ class BGPVPNPluginDb(common_db_mixin.CommonDbMixin):
563 if not filters: 568 if not filters:
564 filters = {} 569 filters = {}
565 filters['bgpvpn_id'] = [bgpvpn_id] 570 filters['bgpvpn_id'] = [bgpvpn_id]
566 return self._get_collection(context, BGPVPNPortAssociation, 571 return model_query.get_collection(
567 self._make_port_assoc_dict, 572 context, BGPVPNPortAssociation,
568 filters, fields) 573 self._make_port_assoc_dict,
574 filters, fields)
569 575
570 @db_api.CONTEXT_READER 576 @db_api.CONTEXT_READER
571 def update_port_assoc(self, context, assoc_id, bgpvpn_id, port_assoc): 577 def update_port_assoc(self, context, assoc_id, bgpvpn_id, port_assoc):