LBaaS Layer4 TCP VIP should use LVS

When a VIP is configured for L4 LB only, we can use LVS to improve
performance. To achieve that, we should enable acceleration on the Edge
appliance.

Depends-On: I7f3b95b43f87b35d641f0c7535d648ee178eda41
Change-Id: I027cb1e4b5cd82006a80e17f3fd2b0feca1278a4
This commit is contained in:
Kobi Samoray 2015-11-29 17:16:50 +02:00
parent 8785d5fdde
commit feb2dc9d04
5 changed files with 36 additions and 2 deletions

View File

@ -582,6 +582,12 @@ def get_nsxv_lbaas_loadbalancer_binding(session, loadbalancer_id):
return
def get_nsxv_lbaas_loadbalancer_binding_by_edge(session, edge_id):
return session.query(
nsxv_models.NsxvLbaasLoadbalancerBinding).filter_by(
edge_id=edge_id).all()
def del_nsxv_lbaas_loadbalancer_binding(session, loadbalancer_id):
return (session.query(nsxv_models.NsxvLbaasLoadbalancerBinding).
filter_by(loadbalancer_id=loadbalancer_id).delete())

View File

@ -249,3 +249,13 @@ def get_lbaas_fw_section_id(vcns):
fw_section_id = et.fromstring(sect).attrib['id']
return fw_section_id
def enable_edge_acceleration(vcns, edge_id):
with locking.LockManager.get_lock(edge_id, external=True):
config = {
'accelerationEnabled': True,
'enabled': True,
'featureType': 'loadbalancer_4.0'}
vcns.enable_service_loadbalancer(edge_id, config)

View File

@ -188,6 +188,12 @@ class EdgeLbDriver(object):
'No suitable Edge found for subnet %s') % pool['subnet_id']
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
# If Edge appliance is used for the 1st time for LB,
# enable LB acceleration
if not self.is_edge_in_use(context,
edge_id):
lb_common.enable_edge_acceleration(self.vcns, edge_id)
edge_pool = convert_lbaas_pool(pool)
try:
with locking.LockManager.get_lock(edge_id, external=True):
@ -617,8 +623,8 @@ class EdgeLbDriver(object):
'active_connections': 0,
'total_connections': 0}
def is_edge_in_use(self, edge_id):
return self.lbv1_driver.is_edge_in_use(edge_id)
def is_edge_in_use(self, context, edge_id):
return self.lbv1_driver.is_edge_in_use(context, edge_id)
def is_subnet_in_use(self, context, subnet_id):
plugin = self._get_lb_plugin()

View File

@ -37,6 +37,10 @@ class EdgeLoadBalancerManager(base_mgr.EdgeLoadbalancerBaseManager):
edge_id = lb_common.get_lbaas_edge_id_for_subnet(
context, self.core_plugin, lb.vip_subnet_id)
if not nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge(
context.session, edge_id):
lb_common.enable_edge_acceleration(self.vcns, edge_id)
lb_common.add_vip_as_secondary_ip(self.vcns, edge_id,
lb.vip_address)
edge_fw_rule_id = lb_common.add_vip_fw_rule(

View File

@ -138,10 +138,16 @@ class TestEdgeLbaasV2Loadbalancer(BaseTestEdgeLbaasV2):
) as mock_vip_sec_ip, \
mock.patch.object(lb_common, 'add_vip_fw_rule'
) as mock_add_vip_fwr, \
mock.patch.object(lb_common, 'enable_edge_acceleration'
) as mock_enable_edge_acceleration, \
mock.patch.object(nsxv_db,
'get_nsxv_lbaas_loadbalancer_binding_by_edge'
) as mock_get_lb_binding_by_edge, \
mock.patch.object(nsxv_db, 'add_nsxv_lbaas_loadbalancer_binding'
) as mock_db_binding:
mock_get_edge.return_value = LB_EDGE_ID
mock_add_vip_fwr.return_value = LB_VIP_FWR_ID
mock_get_lb_binding_by_edge.return_value = []
self.edge_driver.loadbalancer.create(self.context, self.lb)
@ -161,6 +167,8 @@ class TestEdgeLbaasV2Loadbalancer(BaseTestEdgeLbaasV2):
self.lbv2_driver.load_balancer.successful_completion)
mock_successful_completion.assert_called_with(self.context,
self.lb)
mock_enable_edge_acceleration.assert_called_with(
self.edge_driver.vcns, LB_EDGE_ID)
def test_update(self):
new_lb = lb_models.LoadBalancer(LB_ID, 'yyy-yyy', 'lb-name', 'heh-huh',