Merge "[sqlalchemy-20] Add missing DB context decorators"
This commit is contained in:
commit
f2a827ec0c
|
@ -203,6 +203,8 @@ class BgpDrAgentSchedulerDbMixin(bgp_dras_ext.BgpDrSchedulerPluginBase,
|
|||
|
||||
def get_dragents_hosting_bgp_speakers(self, context, bgp_speaker_ids,
|
||||
active=None, admin_state_up=None):
|
||||
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
query = context.session.query(BgpSpeakerDrAgentBinding)
|
||||
query = query.options(orm.contains_eager(
|
||||
BgpSpeakerDrAgentBinding.dragent))
|
||||
|
@ -225,6 +227,7 @@ class BgpDrAgentSchedulerDbMixin(bgp_dras_ext.BgpDrSchedulerPluginBase,
|
|||
active, binding.dragent)]
|
||||
|
||||
def get_dragent_bgp_speaker_bindings(self, context):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
return context.session.query(BgpSpeakerDrAgentBinding).all()
|
||||
|
||||
def list_dragent_hosting_bgp_speaker(self, context, speaker_id):
|
||||
|
@ -236,14 +239,17 @@ class BgpDrAgentSchedulerDbMixin(bgp_dras_ext.BgpDrSchedulerPluginBase,
|
|||
return {'agents': self.get_agents(context, filters={'id': agent_ids})}
|
||||
|
||||
def list_bgp_speaker_on_dragent(self, context, agent_id):
|
||||
query = context.session.query(BgpSpeakerDrAgentBinding.bgp_speaker_id)
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
query = context.session.query(
|
||||
BgpSpeakerDrAgentBinding.bgp_speaker_id)
|
||||
query = query.filter_by(agent_id=agent_id)
|
||||
|
||||
bgp_speaker_ids = [item[0] for item in query]
|
||||
if not bgp_speaker_ids:
|
||||
# Exception will be thrown if the requested agent does not exist.
|
||||
# Raise exception if the requested agent does not exist.
|
||||
self._get_agent(context, agent_id)
|
||||
return {'bgp_speakers': []}
|
||||
|
||||
return {'bgp_speakers':
|
||||
self.get_bgp_speakers(context,
|
||||
filters={'id': bgp_speaker_ids})}
|
||||
|
@ -254,6 +260,7 @@ class BgpDrAgentSchedulerDbMixin(bgp_dras_ext.BgpDrSchedulerPluginBase,
|
|||
if not agent.admin_state_up:
|
||||
return {}
|
||||
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
query = context.session.query(BgpSpeakerDrAgentBinding)
|
||||
query = query.filter(BgpSpeakerDrAgentBinding.agent_id == agent.id)
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue