[API] Fix validation for multi lbs per device

Change-Id: I2bf3b82b4c755f7d9cc456c873521f84df0c05a5
This commit is contained in:
Marc Pilon 2014-02-26 15:37:34 -05:00
parent f50921e25e
commit 796b760868
1 changed files with 32 additions and 2 deletions

View File

@ -395,7 +395,8 @@ class LoadBalancersController(RestController):
lb.port = body.port
else:
raise ClientSideError(
'Port number {0} is invalid'.format(body.port)
'Port number {0} is not allowed for {1} protocol'
.format(body.port, lb.protocol)
)
else:
if lb.protocol == 'HTTP':
@ -473,11 +474,40 @@ class LoadBalancersController(RestController):
count()
if old_count:
session.rollback()
# Error here, can have only one LB per port on a device
# Error, can have only one LB per port on a device
raise ClientSideError(
'Only one load balancer per port allowed per device'
)
if lb.protocol == 'HTTP':
protocol_count = session.query(
LoadBalancer
).join(LoadBalancer.devices).\
join(Device.vip).\
filter(LoadBalancer.tenantid == tenant_id).\
filter(Vip.id == virtual_id).\
filter(LoadBalancer.protocol == lb.protocol).\
count()
else:
# TCP or GALERA. Both are TCP really
protocol_count = session.query(
LoadBalancer
).join(LoadBalancer.devices).\
join(Device.vip).\
filter(LoadBalancer.tenantid == tenant_id).\
filter(Vip.id == virtual_id).\
filter((LoadBalancer.protocol == 'TCP') |
(LoadBalancer.protocol == 'GALERA')).\
count()
if protocol_count:
session.rollback()
# Error, can have only one LB per protocol on a device
raise ClientSideError(
'Only one load balancer per protocol'
' allowed per device'
)
if body.algorithm:
lb.algorithm = body.algorithm.upper()
else: