Merge "Remove code duplication from loadbalancer db plugin"

This commit is contained in:
Jenkins 2013-06-16 06:11:47 +00:00 committed by Gerrit Code Review
commit af91f1b41a

View File

@ -545,12 +545,8 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase,
def stats(self, context, pool_id): def stats(self, context, pool_id):
with context.session.begin(subtransactions=True): with context.session.begin(subtransactions=True):
pool_qry = context.session.query(Pool) pool = self._get_resource(context, Pool, pool_id)
try: stats = pool['stats']
pool = pool_qry.filter_by(id=pool_id).one()
stats = pool['stats']
except exc.NoResultFound:
raise loadbalancer.PoolStatsNotFound(pool_id=pool_id)
res = {'bytes_in': stats['bytes_in'], res = {'bytes_in': stats['bytes_in'],
'bytes_out': stats['bytes_out'], 'bytes_out': stats['bytes_out'],
@ -561,11 +557,7 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase,
def create_pool_health_monitor(self, context, health_monitor, pool_id): def create_pool_health_monitor(self, context, health_monitor, pool_id):
monitor_id = health_monitor['health_monitor']['id'] monitor_id = health_monitor['health_monitor']['id']
with context.session.begin(subtransactions=True): with context.session.begin(subtransactions=True):
try: pool = self._get_resource(context, Pool, pool_id)
qry = context.session.query(Pool)
pool = qry.filter_by(id=pool_id).one()
except exc.NoResultFound:
raise loadbalancer.PoolNotFound(pool_id=pool_id)
assoc = PoolMonitorAssociation(pool_id=pool_id, assoc = PoolMonitorAssociation(pool_id=pool_id,
monitor_id=monitor_id) monitor_id=monitor_id)
@ -577,11 +569,7 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase,
def delete_pool_health_monitor(self, context, id, pool_id): def delete_pool_health_monitor(self, context, id, pool_id):
with context.session.begin(subtransactions=True): with context.session.begin(subtransactions=True):
try: pool = self._get_resource(context, Pool, pool_id)
pool_qry = context.session.query(Pool)
pool = pool_qry.filter_by(id=pool_id).one()
except exc.NoResultFound:
raise loadbalancer.PoolNotFound(pool_id=pool_id)
try: try:
monitor_qry = context.session.query(PoolMonitorAssociation) monitor_qry = context.session.query(PoolMonitorAssociation)
monitor = monitor_qry.filter_by(monitor_id=id, monitor = monitor_qry.filter_by(monitor_id=id,
@ -613,11 +601,8 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase,
tenant_id = self._get_tenant_id_for_create(context, v) tenant_id = self._get_tenant_id_for_create(context, v)
with context.session.begin(subtransactions=True): with context.session.begin(subtransactions=True):
try: # ensuring that pool exists
qry = context.session.query(Pool) self._get_resource(context, Pool, v['pool_id'])
qry.filter_by(id=v['pool_id']).one()
except exc.NoResultFound:
raise loadbalancer.PoolNotFound(pool_id=v['pool_id'])
member_db = Member(id=uuidutils.generate_uuid(), member_db = Member(id=uuidutils.generate_uuid(),
tenant_id=tenant_id, tenant_id=tenant_id,