Remove code duplication from loadbalancer db plugin
Use _get_resource instead of duplicating code that fetches pools fixes bug 1191406 Change-Id: I380c97a2ece0536b49891ac797ec7170e44a6a20
This commit is contained in:
parent
489f5b59b6
commit
95c72405c3
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user