NSX|V+V3: Preparations for Octavia support
Create internal drivers for each object that will use dictionaries instead of objects, and will use a generic fail/success notifiers. The LBaaS nsx-v/v3 drivers will translate the objects to dictionaries and use the LBaaS callbacks for successful_completion and failed_completion. Later we can add drivers for Octavia that will use the same internal drivers. Change-Id: I5f99f979bd5333ccfc781217379d217d611cb015
This commit is contained in:
parent
956e2e6015
commit
f6b0643782
@ -115,7 +115,7 @@ from vmware_nsx.plugins.nsx_v3 import utils as v3_utils
|
||||
from vmware_nsx.services.fwaas.common import utils as fwaas_utils
|
||||
from vmware_nsx.services.fwaas.nsx_v3 import fwaas_callbacks_v1
|
||||
from vmware_nsx.services.fwaas.nsx_v3 import fwaas_callbacks_v2
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import lb_driver_v2
|
||||
from vmware_nsx.services.lbaas.nsx_v3.v2 import lb_driver_v2
|
||||
from vmware_nsx.services.qos.common import utils as qos_com_utils
|
||||
from vmware_nsx.services.qos.nsx_v3 import driver as qos_driver
|
||||
from vmware_nsx.services.trunk.nsx_v3 import driver as trunk_driver
|
||||
|
87
vmware_nsx/services/lbaas/lb_helper.py
Normal file
87
vmware_nsx/services/lbaas/lb_helper.py
Normal file
@ -0,0 +1,87 @@
|
||||
# Copyright 2015 VMware, Inc.
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_log import helpers as log_helpers
|
||||
|
||||
from neutron_lib import exceptions as n_exc
|
||||
|
||||
|
||||
class LBaaSNSXObjectManagerWrapper(object):
|
||||
"""Wrapper class to connect the LB api with the NSX-V/V3 implementations
|
||||
|
||||
This class will call the actual NSX-V LBaaS logic after translating
|
||||
the LB object into a dictionary, and will also handle success/failure cases
|
||||
"""
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self, object_type, implementor, translator, get_completor):
|
||||
super(LBaaSNSXObjectManagerWrapper, self).__init__()
|
||||
self.object_type = object_type
|
||||
self.implementor = implementor
|
||||
self.translator = translator
|
||||
self.get_completor = get_completor
|
||||
|
||||
def get_completor_func(self, context, obj, delete=False):
|
||||
# return a method that will be called on success/failure completion
|
||||
def completor_func(success=True):
|
||||
completor = self.get_completor()
|
||||
if completor:
|
||||
if success:
|
||||
return completor.successful_completion(
|
||||
context, obj, delete=delete)
|
||||
else:
|
||||
return completor.failed_completion(
|
||||
context, obj)
|
||||
|
||||
return completor_func
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, obj, **args):
|
||||
obj_dict = self.translator(obj)
|
||||
completor_func = self.get_completor_func(context, obj)
|
||||
self.implementor.create(context, obj_dict, completor_func, **args)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_obj, new_obj, **args):
|
||||
old_obj_dict = self.translator(old_obj)
|
||||
new_obj_dict = self.translator(new_obj)
|
||||
completor_func = self.get_completor_func(context, new_obj)
|
||||
self.implementor.update(context, old_obj_dict, new_obj_dict,
|
||||
completor_func, **args)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, obj, **args):
|
||||
obj_dict = self.translator(obj)
|
||||
completor_func = self.get_completor_func(context, obj, delete=True)
|
||||
self.implementor.delete(context, obj_dict, completor_func, **args)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def refresh(self, context, obj):
|
||||
# verify that this api exists (supported only for loadbalancer)
|
||||
if not hasattr(self.implementor, 'refresh'):
|
||||
msg = (_("LBaaS object %s does not support refresh api") %
|
||||
self.object_type)
|
||||
raise n_exc.BadRequest(resource='edge', msg=msg)
|
||||
obj_dict = self.translator(obj)
|
||||
self.implementor.refresh(context, obj_dict)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def stats(self, context, obj):
|
||||
# verify that this api exists (supported only for loadbalancer)
|
||||
if not hasattr(self.implementor, 'stats'):
|
||||
msg = (_("LBaaS object %s does not support stats api") %
|
||||
self.object_type)
|
||||
raise n_exc.BadRequest(resource='edge', msg=msg)
|
||||
obj_dict = self.translator(obj)
|
||||
self.implementor.stats(context, obj_dict)
|
111
vmware_nsx/services/lbaas/lb_translators.py
Normal file
111
vmware_nsx/services/lbaas/lb_translators.py
Normal file
@ -0,0 +1,111 @@
|
||||
# Copyright 2018 VMware, Inc.
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def lb_hm_obj_to_dict(hm):
|
||||
# Translate the LBaaS HM to a dictionary skipping the pool object to avoid
|
||||
# recursions
|
||||
hm_dict = hm.to_dict(pool=False)
|
||||
# Translate the pool separately without it's internal objects
|
||||
if hm.pool:
|
||||
hm_dict['pool'] = lb_pool_obj_to_dict(hm.pool, with_listeners=False)
|
||||
return hm_dict
|
||||
|
||||
|
||||
def lb_listener_obj_to_dict(listener):
|
||||
# Translate the LBaaS listener to a dictionary skipping the some objects
|
||||
# to avoid recursions
|
||||
listener_dict = listener.to_dict(loadbalancer=False, default_pool=False)
|
||||
# Translate the default pool separately without it's internal objects
|
||||
if listener.default_pool:
|
||||
listener_dict['default_pool'] = lb_pool_obj_to_dict(
|
||||
listener.default_pool, with_listeners=False)
|
||||
else:
|
||||
listener_dict['default_pool'] = None
|
||||
if listener.loadbalancer:
|
||||
listener_dict['loadbalancer'] = lb_loadbalancer_obj_to_dict(
|
||||
listener.loadbalancer)
|
||||
else:
|
||||
listener_dict['loadbalancer'] = None
|
||||
return listener_dict
|
||||
|
||||
|
||||
def lb_pool_obj_to_dict(pool, with_listeners=True):
|
||||
# Translate the LBaaS pool to a dictionary skipping the some objects
|
||||
# to avoid recursions
|
||||
pool_dict = pool.to_dict(listeners=False, listener=False)
|
||||
if with_listeners:
|
||||
# Translate the listener/s separately without it's internal objects
|
||||
if pool.listener:
|
||||
pool_dict['listener'] = lb_listener_obj_to_dict(pool.listener)
|
||||
else:
|
||||
pool_dict['listener'] = None
|
||||
pool_dict['listeners'] = []
|
||||
if pool.listeners:
|
||||
for listener in pool.listeners:
|
||||
pool_dict['listeners'].append(
|
||||
lb_listener_obj_to_dict(listener))
|
||||
return pool_dict
|
||||
|
||||
|
||||
def lb_loadbalancer_obj_to_dict(loadbalancer):
|
||||
return loadbalancer.to_dict()
|
||||
|
||||
|
||||
def lb_member_obj_to_dict(member):
|
||||
# Translate the LBaaS member to a dictionary skipping the some objects
|
||||
# to avoid recursions
|
||||
member_dict = member.to_dict(pool=False)
|
||||
# Add the pool dictionary (with its listeners and loadbalancer)
|
||||
if member.pool:
|
||||
member_dict['pool'] = lb_pool_obj_to_dict(member.pool)
|
||||
else:
|
||||
member_dict['pool'] = None
|
||||
return member_dict
|
||||
|
||||
|
||||
def lb_l7policy_obj_to_dict(l7policy):
|
||||
# Translate the LBaaS L7 policy to a dictionary skipping the some objects
|
||||
# to avoid recursions
|
||||
l7policy_dict = l7policy.to_dict(listener=False, rules=False)
|
||||
# Add the listener dictionary
|
||||
if l7policy.listener:
|
||||
l7policy_dict['listener'] = lb_listener_obj_to_dict(l7policy.listener)
|
||||
else:
|
||||
l7policy_dict['listener'] = None
|
||||
# Add the rules
|
||||
l7policy_dict['rules'] = []
|
||||
if l7policy.rules:
|
||||
for rule in l7policy.rules:
|
||||
l7policy_dict['rules'].append(
|
||||
lb_l7rule_obj_to_dict(rule, with_policy=False))
|
||||
|
||||
return l7policy_dict
|
||||
|
||||
|
||||
def lb_l7rule_obj_to_dict(l7rule, with_policy=True):
|
||||
# Translate the LBaaS L7 rule to a dictionary skipping the some objects
|
||||
# to avoid recursions
|
||||
l7rule_dict = l7rule.to_dict(policy=False)
|
||||
# Add the policy dictionary
|
||||
if with_policy:
|
||||
l7rule_dict['policy'] = lb_l7policy_obj_to_dict(l7rule.policy)
|
||||
else:
|
||||
l7rule_dict['policy'] = None
|
||||
return l7rule_dict
|
@ -29,43 +29,40 @@ from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgeHealthMonitorManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
|
||||
class EdgeHealthMonitorManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def _convert_lbaas_monitor(self, hm):
|
||||
"""
|
||||
Transform OpenStack health monitor dict to NSXv health monitor dict.
|
||||
"""
|
||||
mon = {
|
||||
'type': lb_const.HEALTH_MONITOR_MAP.get(hm.type, 'icmp'),
|
||||
'interval': hm.delay,
|
||||
'timeout': hm.timeout,
|
||||
'maxRetries': hm.max_retries,
|
||||
'name': hm.id}
|
||||
'type': lb_const.HEALTH_MONITOR_MAP.get(hm['type'], 'icmp'),
|
||||
'interval': hm['delay'],
|
||||
'timeout': hm['timeout'],
|
||||
'maxRetries': hm['max_retries'],
|
||||
'name': hm['id']}
|
||||
|
||||
if hm.http_method:
|
||||
mon['method'] = hm.http_method
|
||||
if hm['http_method']:
|
||||
mon['method'] = hm['http_method']
|
||||
|
||||
if hm.url_path:
|
||||
mon['url'] = hm.url_path
|
||||
if hm['url_path']:
|
||||
mon['url'] = hm['url_path']
|
||||
return mon
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self, vcns_driver):
|
||||
super(EdgeHealthMonitorManager, self).__init__(vcns_driver)
|
||||
super(EdgeHealthMonitorManagerFromDict, self).__init__(vcns_driver)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, hm):
|
||||
lb_id = hm.pool.loadbalancer_id
|
||||
def create(self, context, hm, completor):
|
||||
lb_id = hm['pool']['loadbalancer_id']
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
edge_id = lb_binding['edge_id']
|
||||
|
||||
pool_id = hm['pool']['id']
|
||||
pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
|
||||
context.session, lb_id, hm.pool.id)
|
||||
context.session, lb_id, pool_id)
|
||||
if not pool_binding:
|
||||
self.lbv2_driver.health_monitor.failed_completion(
|
||||
context, hm)
|
||||
completor(success=False)
|
||||
msg = _('Failed to create health monitor on edge: %s. '
|
||||
'Binding not found') % edge_id
|
||||
LOG.error(msg)
|
||||
@ -74,7 +71,7 @@ class EdgeHealthMonitorManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
edge_pool_id = pool_binding['edge_pool_id']
|
||||
|
||||
hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
|
||||
context.session, lb_id, hm.pool.id, hm.id, edge_id)
|
||||
context.session, lb_id, pool_id, hm['id'], edge_id)
|
||||
edge_mon_id = None
|
||||
|
||||
if hm_binding:
|
||||
@ -88,13 +85,12 @@ class EdgeHealthMonitorManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
edge_mon_id = lb_common.extract_resource_id(h['location'])
|
||||
|
||||
nsxv_db.add_nsxv_lbaas_monitor_binding(
|
||||
context.session, lb_id, hm.pool.id, hm.id, edge_id,
|
||||
context.session, lb_id, pool_id, hm['id'], edge_id,
|
||||
edge_mon_id)
|
||||
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.health_monitor.failed_completion(
|
||||
context, hm)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to create health monitor on edge: %s',
|
||||
edge_id)
|
||||
|
||||
@ -111,23 +107,22 @@ class EdgeHealthMonitorManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.health_monitor.failed_completion(context, hm)
|
||||
LOG.error(
|
||||
'Failed to create health monitor on edge: %s',
|
||||
edge_id)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to create health monitor on edge: %s',
|
||||
edge_id)
|
||||
|
||||
self.lbv2_driver.health_monitor.successful_completion(context, hm)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_hm, new_hm):
|
||||
lb_id = new_hm.pool.loadbalancer_id
|
||||
def update(self, context, old_hm, new_hm, completor):
|
||||
lb_id = new_hm['pool']['loadbalancer_id']
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
|
||||
edge_id = lb_binding['edge_id']
|
||||
|
||||
hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
|
||||
context.session, lb_id, new_hm.pool.id, new_hm.id, edge_id)
|
||||
context.session, lb_id, new_hm['pool']['id'],
|
||||
new_hm['id'], edge_id)
|
||||
|
||||
edge_monitor = self._convert_lbaas_monitor(new_hm)
|
||||
|
||||
@ -139,16 +134,14 @@ class EdgeHealthMonitorManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.health_monitor.failed_completion(context,
|
||||
new_hm)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update monitor on edge: %s', edge_id)
|
||||
|
||||
self.lbv2_driver.health_monitor.successful_completion(context, new_hm)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, hm):
|
||||
pool_id = hm.pool.id
|
||||
lb_id = hm.pool.loadbalancer_id
|
||||
def delete(self, context, hm, completor):
|
||||
pool_id = hm['pool']['id']
|
||||
lb_id = hm['pool']['loadbalancer_id']
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
edge_id = lb_binding['edge_id']
|
||||
@ -157,18 +150,17 @@ class EdgeHealthMonitorManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
context.session, lb_id, pool_id)
|
||||
if not pool_binding:
|
||||
nsxv_db.del_nsxv_lbaas_monitor_binding(
|
||||
context.session, lb_id, pool_id, hm.id, edge_id)
|
||||
self.lbv2_driver.health_monitor.successful_completion(
|
||||
context, hm, delete=True)
|
||||
context.session, lb_id, pool_id, hm['id'], edge_id)
|
||||
completor(success=True)
|
||||
return
|
||||
|
||||
edge_pool_id = pool_binding['edge_pool_id']
|
||||
|
||||
hm_binding = nsxv_db.get_nsxv_lbaas_monitor_binding(
|
||||
context.session, lb_id, pool_id, hm.id, edge_id)
|
||||
context.session, lb_id, pool_id, hm['id'], edge_id)
|
||||
|
||||
edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1]
|
||||
if hm_binding['edge_mon_id'] in edge_pool['monitorId']:
|
||||
if hm_binding and hm_binding['edge_mon_id'] in edge_pool['monitorId']:
|
||||
edge_pool['monitorId'].remove(hm_binding['edge_mon_id'])
|
||||
|
||||
try:
|
||||
@ -176,24 +168,21 @@ class EdgeHealthMonitorManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
self.vcns.update_pool(edge_id, edge_pool_id, edge_pool)
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.health_monitor.failed_completion(context,
|
||||
hm)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to delete monitor mapping on edge: %s',
|
||||
edge_id)
|
||||
|
||||
# If this monitor is not used on this edge anymore, delete it
|
||||
if not edge_pool['monitorId']:
|
||||
if hm_binding and not edge_pool['monitorId']:
|
||||
try:
|
||||
with locking.LockManager.get_lock(edge_id):
|
||||
self.vcns.delete_health_monitor(hm_binding['edge_id'],
|
||||
hm_binding['edge_mon_id'])
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.health_monitor.failed_completion(context,
|
||||
hm)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to delete monitor on edge: %s', edge_id)
|
||||
|
||||
nsxv_db.del_nsxv_lbaas_monitor_binding(
|
||||
context.session, lb_id, pool_id, hm.id, edge_id)
|
||||
self.lbv2_driver.health_monitor.successful_completion(
|
||||
context, hm, delete=True)
|
||||
context.session, lb_id, pool_id, hm['id'], edge_id)
|
||||
completor(success=True)
|
@ -41,67 +41,67 @@ type_by_compare_type = {
|
||||
def policy_to_application_rule(policy):
|
||||
condition = ''
|
||||
rule_lines = []
|
||||
for rule in policy.rules:
|
||||
if rule.provisioning_status == constants.PENDING_DELETE:
|
||||
for rule in policy['rules']:
|
||||
if rule['provisioning_status'] == constants.PENDING_DELETE:
|
||||
# skip this rule as it is being deleted
|
||||
continue
|
||||
|
||||
type_by_comp = type_by_compare_type.get(rule.compare_type)
|
||||
type_by_comp = type_by_compare_type.get(rule['compare_type'])
|
||||
if type_by_comp is None:
|
||||
type_by_comp = ''
|
||||
LOG.warnning('Unsupported compare type %(type)s is used in '
|
||||
'policy %(id)s', {'type': rule.compare_type,
|
||||
'id': policy.id})
|
||||
'policy %(id)s', {'type': rule['compare_type'],
|
||||
'id': policy['id']})
|
||||
|
||||
if rule.type == lb_const.L7_RULE_TYPE_COOKIE:
|
||||
if rule['type'] == lb_const.L7_RULE_TYPE_COOKIE:
|
||||
# Example: acl <id> hdr_sub(cookie) SEEN=1
|
||||
hdr_type = 'hdr' + type_by_comp
|
||||
rule_line = ('acl %(rule_id)s %(hdr_type)s(cookie) '
|
||||
'%(key)s=%(val)s' % {'rule_id': rule.id,
|
||||
'%(key)s=%(val)s' % {'rule_id': rule['id'],
|
||||
'hdr_type': hdr_type,
|
||||
'key': rule.key,
|
||||
'val': rule.value})
|
||||
elif rule.type == lb_const.L7_RULE_TYPE_HEADER:
|
||||
'key': rule['key'],
|
||||
'val': rule['value']})
|
||||
elif rule['type'] == lb_const.L7_RULE_TYPE_HEADER:
|
||||
# Example: acl <id> hdr(user-agent) -i test
|
||||
hdr_type = 'hdr' + type_by_comp
|
||||
rule_line = ('acl %(rule_id)s %(hdr_type)s(%(key)s) '
|
||||
'-i %(val)s' % {'rule_id': rule.id,
|
||||
'-i %(val)s' % {'rule_id': rule['id'],
|
||||
'hdr_type': hdr_type,
|
||||
'key': rule.key,
|
||||
'val': rule.value})
|
||||
elif rule.type == lb_const.L7_RULE_TYPE_HOST_NAME:
|
||||
'key': rule['key'],
|
||||
'val': rule['value']})
|
||||
elif rule['type'] == lb_const.L7_RULE_TYPE_HOST_NAME:
|
||||
# Example: acl <id> hdr_beg(host) -i abcd
|
||||
hdr_type = 'hdr' + type_by_comp
|
||||
# -i for case insensitive host name
|
||||
rule_line = ('acl %(rule_id)s %(hdr_type)s(host) '
|
||||
'-i %(val)s' % {'rule_id': rule.id,
|
||||
'-i %(val)s' % {'rule_id': rule['id'],
|
||||
'hdr_type': hdr_type,
|
||||
'val': rule.value})
|
||||
elif rule.type == lb_const.L7_RULE_TYPE_PATH:
|
||||
'val': rule['value']})
|
||||
elif rule['type'] == lb_const.L7_RULE_TYPE_PATH:
|
||||
# Example: acl <id> path_beg -i /images
|
||||
# -i for case insensitive path
|
||||
path_type = 'path' + type_by_comp
|
||||
rule_line = ('acl %(rule_id)s %(path_type)s '
|
||||
'-i %(val)s' % {'rule_id': rule.id,
|
||||
'-i %(val)s' % {'rule_id': rule['id'],
|
||||
'path_type': path_type,
|
||||
'val': rule.value})
|
||||
elif rule.type == lb_const.L7_RULE_TYPE_FILE_TYPE:
|
||||
'val': rule['value']})
|
||||
elif rule['type'] == lb_const.L7_RULE_TYPE_FILE_TYPE:
|
||||
# Example: acl <id> path_sub -i .jpg
|
||||
# Regardless of the compare type, always check contained in path.
|
||||
# -i for case insensitive file type
|
||||
val = rule.value
|
||||
val = rule['value']
|
||||
if not val.startswith('.'):
|
||||
val = '.' + val
|
||||
rule_line = ('acl %(rule_id)s path_sub '
|
||||
'-i %(val)s' % {'rule_id': rule.id,
|
||||
'-i %(val)s' % {'rule_id': rule['id'],
|
||||
'val': val})
|
||||
else:
|
||||
msg = _('Unsupported L7rule type %s') % rule.type
|
||||
msg = _('Unsupported L7rule type %s') % rule['type']
|
||||
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
|
||||
|
||||
rule_lines.append(rule_line)
|
||||
invert_sign = '!' if rule.invert else ''
|
||||
condition = condition + invert_sign + rule.id + ' '
|
||||
invert_sign = '!' if rule['invert'] else ''
|
||||
condition = condition + invert_sign + rule['id'] + ' '
|
||||
|
||||
if rule_lines:
|
||||
# concatenate all the rules with new lines
|
||||
@ -113,21 +113,21 @@ def policy_to_application_rule(policy):
|
||||
condition = 'TRUE'
|
||||
|
||||
# prepare the action
|
||||
if policy.action == lb_const.L7_POLICY_ACTION_REJECT:
|
||||
if policy['action'] == lb_const.L7_POLICY_ACTION_REJECT:
|
||||
# return HTTP 403 response
|
||||
action = 'http-request deny'
|
||||
elif policy.action == lb_const.L7_POLICY_ACTION_REDIRECT_TO_POOL:
|
||||
action = 'use_backend pool_%s' % policy.redirect_pool_id
|
||||
elif policy.action == lb_const.L7_POLICY_ACTION_REDIRECT_TO_URL:
|
||||
action = 'redirect location %s' % policy.redirect_url
|
||||
elif policy['action'] == lb_const.L7_POLICY_ACTION_REDIRECT_TO_POOL:
|
||||
action = 'use_backend pool_%s' % policy['redirect_pool_id']
|
||||
elif policy['action'] == lb_const.L7_POLICY_ACTION_REDIRECT_TO_URL:
|
||||
action = 'redirect location %s' % policy['redirect_url']
|
||||
else:
|
||||
msg = _('Unsupported L7policy action %s') % policy.action
|
||||
msg = _('Unsupported L7policy action %s') % policy['action']
|
||||
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
|
||||
|
||||
# Build the final script
|
||||
script = all_rules + '%(action)s if %(cond)s' % {
|
||||
'action': action, 'cond': condition}
|
||||
app_rule = {'name': 'pol_' + policy.id, 'script': script}
|
||||
app_rule = {'name': 'pol_' + policy['id'], 'script': script}
|
||||
return app_rule
|
||||
|
||||
|
||||
@ -141,10 +141,10 @@ def policy_to_edge_and_rule_id(context, policy_id):
|
||||
return binding['edge_id'], binding['edge_app_rule_id']
|
||||
|
||||
|
||||
class EdgeL7PolicyManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
class EdgeL7PolicyManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self, vcns_driver):
|
||||
super(EdgeL7PolicyManager, self).__init__(vcns_driver)
|
||||
super(EdgeL7PolicyManagerFromDict, self).__init__(vcns_driver)
|
||||
|
||||
def _add_app_rule_to_virtual_server(self, edge_id, vse_id, app_rule_id,
|
||||
policy_position):
|
||||
@ -200,29 +200,29 @@ class EdgeL7PolicyManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
self.vcns.update_vip(edge_id, vse_id, vse)
|
||||
|
||||
def _get_vse_id(self, context, pol):
|
||||
lb_id = pol.listener.loadbalancer_id
|
||||
list_id = pol.listener.id
|
||||
lb_id = pol['listener']['loadbalancer_id']
|
||||
list_id = pol['listener']['id']
|
||||
listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
|
||||
context.session, lb_id, list_id)
|
||||
if listener_binding:
|
||||
return listener_binding['vse_id']
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, pol):
|
||||
def create(self, context, pol, completor):
|
||||
# find out the edge to be updated, by the listener of this policy
|
||||
lb_id = pol.listener.loadbalancer_id
|
||||
listener = pol['listener']
|
||||
lb_id = listener['loadbalancer_id']
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
if not lb_binding:
|
||||
msg = _(
|
||||
'No suitable Edge found for listener %s') % pol.listener_id
|
||||
'No suitable Edge found for listener %s') % listener['id']
|
||||
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
|
||||
|
||||
if (pol.listener.protocol == lb_const.LB_PROTOCOL_HTTPS or
|
||||
pol.listener.protocol == lb_const.LB_PROTOCOL_TERMINATED_HTTPS):
|
||||
if (listener['protocol'] == lb_const.LB_PROTOCOL_HTTPS or
|
||||
listener['protocol'] == lb_const.LB_PROTOCOL_TERMINATED_HTTPS):
|
||||
msg = _(
|
||||
'L7 policy is not supported for %(prot)s listener %(ls)s') % {
|
||||
'prot': pol.listener.protocol, 'ls': pol.listener_id}
|
||||
'prot': listener['protocol'], 'ls': pol['listener_id']}
|
||||
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
|
||||
|
||||
edge_id = lb_binding['edge_id']
|
||||
@ -239,10 +239,10 @@ class EdgeL7PolicyManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
vse_id = self._get_vse_id(context, pol)
|
||||
if vse_id:
|
||||
self._add_app_rule_to_virtual_server(
|
||||
edge_id, vse_id, app_rule_id, pol.position)
|
||||
edge_id, vse_id, app_rule_id, pol['position'])
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.l7policy.failed_completion(context, pol)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to create L7policy on edge %(edge)s: '
|
||||
'%(err)s',
|
||||
{'edge': edge_id, 'err': e})
|
||||
@ -255,15 +255,15 @@ class EdgeL7PolicyManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
pass
|
||||
|
||||
# save the nsx application rule id in the DB
|
||||
nsxv_db.add_nsxv_lbaas_l7policy_binding(context.session, pol.id,
|
||||
nsxv_db.add_nsxv_lbaas_l7policy_binding(context.session, pol['id'],
|
||||
edge_id, app_rule_id)
|
||||
# complete the transaction
|
||||
self.lbv2_driver.l7policy.successful_completion(context, pol)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_pol, new_pol):
|
||||
def update(self, context, old_pol, new_pol, completor):
|
||||
# get the nsx application rule id and edge id from the nsx DB
|
||||
edge_id, app_rule_id = policy_to_edge_and_rule_id(context, new_pol.id)
|
||||
edge_id, app_rule_id = policy_to_edge_and_rule_id(
|
||||
context, new_pol['id'])
|
||||
# create the script for the new policy data
|
||||
app_rule = policy_to_application_rule(new_pol)
|
||||
try:
|
||||
@ -272,32 +272,31 @@ class EdgeL7PolicyManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
self.vcns.update_app_rule(edge_id, app_rule_id, app_rule)
|
||||
|
||||
# if the position changed - update it too
|
||||
if old_pol.position != new_pol.position:
|
||||
if old_pol['position'] != new_pol['position']:
|
||||
vse_id = self._get_vse_id(context, new_pol)
|
||||
if vse_id:
|
||||
self._update_app_rule_possition_in_virtual_server(
|
||||
edge_id, vse_id, app_rule_id, new_pol.position)
|
||||
edge_id, vse_id, app_rule_id, new_pol['position'])
|
||||
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.l7policy.failed_completion(context, new_pol)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update L7policy on edge %(edge)s: '
|
||||
'%(err)s',
|
||||
{'edge': edge_id, 'err': e})
|
||||
|
||||
# complete the transaction
|
||||
self.lbv2_driver.l7policy.successful_completion(context, new_pol)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, pol):
|
||||
def delete(self, context, pol, completor):
|
||||
# get the nsx application rule id and edge id from the nsx DB
|
||||
try:
|
||||
edge_id, app_rule_id = policy_to_edge_and_rule_id(context, pol.id)
|
||||
edge_id, app_rule_id = policy_to_edge_and_rule_id(
|
||||
context, pol['id'])
|
||||
except n_exc.BadRequest:
|
||||
# This is probably a policy that we failed to create properly.
|
||||
# We should allow deleting it
|
||||
self.lbv2_driver.l7policy.successful_completion(context, pol,
|
||||
delete=True)
|
||||
completor(success=True)
|
||||
return
|
||||
|
||||
with locking.LockManager.get_lock(edge_id):
|
||||
@ -312,14 +311,13 @@ class EdgeL7PolicyManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
self.vcns.delete_app_rule(edge_id, app_rule_id)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.l7policy.failed_completion(context, pol)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to delete L7policy on edge '
|
||||
'%(edge)s: %(err)s',
|
||||
{'edge': edge_id, 'err': e})
|
||||
|
||||
# delete the nsxv db entry
|
||||
nsxv_db.del_nsxv_lbaas_l7policy_binding(context.session, pol.id)
|
||||
nsxv_db.del_nsxv_lbaas_l7policy_binding(context.session, pol['id'])
|
||||
|
||||
# complete the transaction
|
||||
self.lbv2_driver.l7policy.successful_completion(context, pol,
|
||||
delete=True)
|
||||
completor(success=True)
|
@ -19,48 +19,46 @@ from oslo_utils import excutils
|
||||
|
||||
from vmware_nsx.common import locking
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import l7policy_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.implementation import l7policy_mgr
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgeL7RuleManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
class EdgeL7RuleManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self, vcns_driver):
|
||||
super(EdgeL7RuleManager, self).__init__(vcns_driver)
|
||||
super(EdgeL7RuleManagerFromDict, self).__init__(vcns_driver)
|
||||
|
||||
def _handle_l7policy_rules_change(self, context, rule, delete=False):
|
||||
def _handle_l7policy_rules_change(self, context, rule, completor,
|
||||
delete=False):
|
||||
# Get the nsx application rule id and edge id
|
||||
edge_id, app_rule_id = l7policy_mgr.policy_to_edge_and_rule_id(
|
||||
context, rule.l7policy_id)
|
||||
context, rule['l7policy_id'])
|
||||
|
||||
# Create the script for the new policy data.
|
||||
# The policy obj on the rule is already updated with the
|
||||
# created/updated/deleted rule.
|
||||
app_rule = l7policy_mgr.policy_to_application_rule(rule.policy)
|
||||
app_rule = l7policy_mgr.policy_to_application_rule(rule['policy'])
|
||||
try:
|
||||
with locking.LockManager.get_lock(edge_id):
|
||||
# update the backend application rule for the updated policy
|
||||
self.vcns.update_app_rule(edge_id, app_rule_id, app_rule)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.l7rule.failed_completion(context, rule)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update L7rules on edge %(edge)s: '
|
||||
'%(err)s',
|
||||
{'edge': edge_id, 'err': e})
|
||||
|
||||
# complete the transaction
|
||||
self.lbv2_driver.l7rule.successful_completion(context, rule,
|
||||
delete=delete)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, rule):
|
||||
self._handle_l7policy_rules_change(context, rule)
|
||||
def create(self, context, rule, completor):
|
||||
self._handle_l7policy_rules_change(context, rule, completor)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_rule, new_rule):
|
||||
self._handle_l7policy_rules_change(context, new_rule)
|
||||
def update(self, context, old_rule, new_rule, completor):
|
||||
self._handle_l7policy_rules_change(context, new_rule, completor)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, rule):
|
||||
self._handle_l7policy_rules_change(context, rule, delete=True)
|
||||
def delete(self, context, rule, completor):
|
||||
self._handle_l7policy_rules_change(context, rule, completor,
|
||||
delete=True)
|
@ -32,14 +32,14 @@ LOG = logging.getLogger(__name__)
|
||||
def listener_to_edge_app_profile(listener, edge_cert_id):
|
||||
edge_app_profile = {
|
||||
'insertXForwardedFor': False,
|
||||
'name': listener.id,
|
||||
'name': listener['id'],
|
||||
'serverSslEnabled': False,
|
||||
'sslPassthrough': False,
|
||||
'template': lb_const.PROTOCOL_MAP[listener.protocol],
|
||||
'template': lb_const.PROTOCOL_MAP[listener['protocol']],
|
||||
}
|
||||
|
||||
if (listener.protocol == lb_const.LB_PROTOCOL_HTTPS or
|
||||
listener.protocol == lb_const.LB_PROTOCOL_TERMINATED_HTTPS):
|
||||
if (listener['protocol'] == lb_const.LB_PROTOCOL_HTTPS or
|
||||
listener['protocol'] == lb_const.LB_PROTOCOL_TERMINATED_HTTPS):
|
||||
if edge_cert_id:
|
||||
edge_app_profile['clientSsl'] = {
|
||||
'caCertificate': [],
|
||||
@ -49,55 +49,55 @@ def listener_to_edge_app_profile(listener, edge_cert_id):
|
||||
else:
|
||||
edge_app_profile['sslPassthrough'] = True
|
||||
|
||||
if listener.default_pool:
|
||||
if listener.default_pool.session_persistence:
|
||||
pool_sess_persist = listener.default_pool.session_persistence
|
||||
sess_persist_type = pool_sess_persist.type
|
||||
persistence = {
|
||||
'method':
|
||||
lb_const.SESSION_PERSISTENCE_METHOD_MAP.get(
|
||||
sess_persist_type)}
|
||||
if (listener.get('default_pool') and
|
||||
listener['default_pool'].get('session_persistence')):
|
||||
pool_sess_persist = listener['default_pool']['session_persistence']
|
||||
sess_persist_type = pool_sess_persist['type']
|
||||
persistence = {
|
||||
'method':
|
||||
lb_const.SESSION_PERSISTENCE_METHOD_MAP.get(
|
||||
sess_persist_type)}
|
||||
|
||||
if (sess_persist_type in
|
||||
lb_const.SESSION_PERSISTENCE_COOKIE_MAP):
|
||||
cookie_name = getattr(pool_sess_persist, 'cookie_name', None)
|
||||
if cookie_name is None:
|
||||
cookie_name = 'default_cookie_name'
|
||||
persistence.update({
|
||||
'cookieName': cookie_name,
|
||||
'cookieMode': lb_const.SESSION_PERSISTENCE_COOKIE_MAP[
|
||||
sess_persist_type]})
|
||||
if (sess_persist_type in
|
||||
lb_const.SESSION_PERSISTENCE_COOKIE_MAP):
|
||||
cookie_name = pool_sess_persist.get('cookie_name', None)
|
||||
if cookie_name is None:
|
||||
cookie_name = 'default_cookie_name'
|
||||
persistence.update({
|
||||
'cookieName': cookie_name,
|
||||
'cookieMode': lb_const.SESSION_PERSISTENCE_COOKIE_MAP[
|
||||
sess_persist_type]})
|
||||
|
||||
edge_app_profile['persistence'] = persistence
|
||||
edge_app_profile['persistence'] = persistence
|
||||
|
||||
return edge_app_profile
|
||||
|
||||
|
||||
def listener_to_edge_vse(context, listener, vip_address, default_pool,
|
||||
app_profile_id):
|
||||
if listener.connection_limit:
|
||||
connection_limit = max(0, listener.connection_limit)
|
||||
if listener['connection_limit']:
|
||||
connection_limit = max(0, listener['connection_limit'])
|
||||
else:
|
||||
connection_limit = 0
|
||||
|
||||
vse = {
|
||||
'name': 'vip_' + listener.id,
|
||||
'description': listener.description,
|
||||
'name': 'vip_' + listener['id'],
|
||||
'description': listener['description'],
|
||||
'ipAddress': vip_address,
|
||||
'protocol': lb_const.PROTOCOL_MAP[listener.protocol],
|
||||
'port': listener.protocol_port,
|
||||
'protocol': lb_const.PROTOCOL_MAP[listener['protocol']],
|
||||
'port': listener['protocol_port'],
|
||||
'connectionLimit': connection_limit,
|
||||
'defaultPoolId': default_pool,
|
||||
'accelerationEnabled': (
|
||||
listener.protocol == lb_const.LB_PROTOCOL_TCP),
|
||||
listener['protocol'] == lb_const.LB_PROTOCOL_TCP),
|
||||
'applicationProfileId': app_profile_id}
|
||||
|
||||
# Add the L7 policies
|
||||
if listener.l7_policies:
|
||||
if listener['l7_policies']:
|
||||
app_rule_ids = []
|
||||
for pol in listener.l7_policies:
|
||||
for pol in listener['l7_policies']:
|
||||
binding = nsxv_db.get_nsxv_lbaas_l7policy_binding(
|
||||
context.session, pol.id)
|
||||
context.session, pol['id'])
|
||||
if binding:
|
||||
app_rule_ids.append(binding['edge_app_rule_id'])
|
||||
vse['applicationRuleId'] = app_rule_ids
|
||||
@ -106,9 +106,9 @@ def listener_to_edge_vse(context, listener, vip_address, default_pool,
|
||||
|
||||
|
||||
def update_app_profile(vcns, context, listener, edge_id, edge_cert_id=None):
|
||||
lb_id = listener.loadbalancer_id
|
||||
lb_id = listener['loadbalancer_id']
|
||||
listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
|
||||
context.session, lb_id, listener.id)
|
||||
context.session, lb_id, listener['id'])
|
||||
app_profile_id = listener_binding['app_profile_id']
|
||||
app_profile = listener_to_edge_app_profile(listener, edge_cert_id)
|
||||
with locking.LockManager.get_lock(edge_id):
|
||||
@ -117,10 +117,10 @@ def update_app_profile(vcns, context, listener, edge_id, edge_cert_id=None):
|
||||
return app_profile_id
|
||||
|
||||
|
||||
class EdgeListenerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
class EdgeListenerManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self, vcns_driver):
|
||||
super(EdgeListenerManager, self).__init__(vcns_driver)
|
||||
super(EdgeListenerManagerFromDict, self).__init__(vcns_driver)
|
||||
|
||||
def _upload_certificate(self, context, edge_id, cert_id, certificate):
|
||||
cert_binding = nsxv_db.get_nsxv_lbaas_certificate_binding(
|
||||
@ -145,18 +145,17 @@ class EdgeListenerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
context.session, cert_id, edge_id, edge_cert_id)
|
||||
return edge_cert_id
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, listener, certificate=None):
|
||||
def create(self, context, listener, completor, certificate=None):
|
||||
default_pool = None
|
||||
|
||||
lb_id = listener.loadbalancer_id
|
||||
lb_id = listener['loadbalancer_id']
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
edge_id = lb_binding['edge_id']
|
||||
|
||||
if listener.default_pool and listener.default_pool.id:
|
||||
if listener.get('default_pool') and listener['default_pool'].get('id'):
|
||||
pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
|
||||
context.session, lb_id, listener.default_pool.id)
|
||||
context.session, lb_id, listener['default_pool']['id'])
|
||||
if pool_binding:
|
||||
default_pool = pool_binding['edge_pool_id']
|
||||
|
||||
@ -164,12 +163,11 @@ class EdgeListenerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
if certificate:
|
||||
try:
|
||||
edge_cert_id = self._upload_certificate(
|
||||
context, edge_id, listener.default_tls_container_id,
|
||||
context, edge_id, listener['default_tls_container_id'],
|
||||
certificate)
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.listener.failed_completion(context,
|
||||
listener)
|
||||
completor(success=False)
|
||||
|
||||
app_profile = listener_to_edge_app_profile(listener, edge_cert_id)
|
||||
app_profile_id = None
|
||||
@ -180,7 +178,7 @@ class EdgeListenerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
app_profile_id = lb_common.extract_resource_id(h['location'])
|
||||
except vcns_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.listener.failed_completion(context, listener)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to create app profile on edge: %s',
|
||||
lb_binding['edge_id'])
|
||||
|
||||
@ -196,54 +194,53 @@ class EdgeListenerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
|
||||
nsxv_db.add_nsxv_lbaas_listener_binding(context.session,
|
||||
lb_id,
|
||||
listener.id,
|
||||
listener['id'],
|
||||
app_profile_id,
|
||||
edge_vse_id)
|
||||
self.lbv2_driver.listener.successful_completion(context, listener)
|
||||
completor(success=True)
|
||||
|
||||
except vcns_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.listener.failed_completion(context, listener)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to create vip on Edge: %s', edge_id)
|
||||
self.vcns.delete_app_profile(edge_id, app_profile_id)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_listener, new_listener, certificate=None):
|
||||
|
||||
def update(self, context, old_listener, new_listener, completor,
|
||||
certificate=None):
|
||||
default_pool = None
|
||||
if new_listener.default_pool and new_listener.default_pool.id:
|
||||
if (new_listener.get('default_pool') and
|
||||
new_listener['default_pool'].get('id')):
|
||||
pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
|
||||
context.session, new_listener.loadbalancer_id,
|
||||
new_listener.default_pool.id)
|
||||
context.session, new_listener['loadbalancer_id'],
|
||||
new_listener['default_pool']['id'])
|
||||
if pool_binding:
|
||||
default_pool = pool_binding['edge_pool_id']
|
||||
else:
|
||||
LOG.error("Couldn't find pool binding for pool %s",
|
||||
new_listener.default_pool.id)
|
||||
new_listener['default_pool']['id'])
|
||||
|
||||
lb_id = new_listener.loadbalancer_id
|
||||
lb_id = new_listener['loadbalancer_id']
|
||||
listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
|
||||
context.session, lb_id, new_listener.id)
|
||||
context.session, lb_id, new_listener['id'])
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
edge_id = lb_binding['edge_id']
|
||||
|
||||
edge_cert_id = None
|
||||
if certificate:
|
||||
if (old_listener.default_tls_container_id !=
|
||||
new_listener.default_tls_container_id):
|
||||
if (old_listener['default_tls_container_id'] !=
|
||||
new_listener['default_tls_container_id']):
|
||||
try:
|
||||
edge_cert_id = self._upload_certificate(
|
||||
context, edge_id,
|
||||
new_listener.default_tls_container_id,
|
||||
new_listener['default_tls_container_id'],
|
||||
certificate)
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.listener.failed_completion(
|
||||
context, new_listener)
|
||||
completor(success=False)
|
||||
else:
|
||||
cert_binding = nsxv_db.get_nsxv_lbaas_certificate_binding(
|
||||
context.session, new_listener.default_tls_container_id,
|
||||
context.session, new_listener['default_tls_container_id'],
|
||||
edge_id)
|
||||
edge_cert_id = cert_binding['edge_cert_id']
|
||||
|
||||
@ -259,20 +256,17 @@ class EdgeListenerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
with locking.LockManager.get_lock(edge_id):
|
||||
self.vcns.update_vip(edge_id, listener_binding['vse_id'], vse)
|
||||
|
||||
self.lbv2_driver.listener.successful_completion(context,
|
||||
new_listener)
|
||||
completor(success=True)
|
||||
except vcns_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.listener.failed_completion(context,
|
||||
new_listener)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update app profile on edge: %s',
|
||||
edge_id)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, listener):
|
||||
lb_id = listener.loadbalancer_id
|
||||
def delete(self, context, listener, completor):
|
||||
lb_id = listener['loadbalancer_id']
|
||||
listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
|
||||
context.session, lb_id, listener.id)
|
||||
context.session, lb_id, listener['id'])
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
|
||||
@ -299,7 +293,6 @@ class EdgeListenerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
LOG.error('Failed to delete app profile on Edge: %s', edge_id)
|
||||
|
||||
nsxv_db.del_nsxv_lbaas_listener_binding(context.session, lb_id,
|
||||
listener.id)
|
||||
listener['id'])
|
||||
|
||||
self.lbv2_driver.listener.successful_completion(
|
||||
context, listener, delete=True)
|
||||
completor(success=True)
|
@ -35,10 +35,10 @@ from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgeLoadBalancerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
class EdgeLoadBalancerManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self, vcns_driver):
|
||||
super(EdgeLoadBalancerManager, self).__init__(vcns_driver)
|
||||
super(EdgeLoadBalancerManagerFromDict, self).__init__(vcns_driver)
|
||||
registry.subscribe(
|
||||
self._handle_subnet_gw_change,
|
||||
resources.SUBNET, events.AFTER_UPDATE)
|
||||
@ -59,25 +59,23 @@ class EdgeLoadBalancerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
'sizes': vcns_const.ALLOWED_EDGE_SIZES})
|
||||
raise n_exc.InvalidInput(error_message=err_msg)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, lb):
|
||||
def create(self, context, lb, completor):
|
||||
sub_id = lb['vip_subnet_id']
|
||||
if cfg.CONF.nsxv.use_routers_as_lbaas_platform:
|
||||
edge_id = lb_common.get_lbaas_edge_id_for_subnet(
|
||||
context, self.core_plugin, lb.vip_subnet_id, lb.tenant_id)
|
||||
context, self.core_plugin, sub_id, lb['tenant_id'])
|
||||
if not edge_id:
|
||||
msg = _(
|
||||
'No suitable Edge found for subnet %s') % lb.vip_subnet_id
|
||||
msg = _('No suitable Edge found for subnet %s') % sub_id
|
||||
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
|
||||
else:
|
||||
lb_size = self._get_lb_flavor_size(context, lb.flavor_id)
|
||||
lb_size = self._get_lb_flavor_size(context, lb.get('flavor_id'))
|
||||
edge_id = lb_common.get_lbaas_edge_id(
|
||||
context, self.core_plugin, lb.id, lb.vip_address,
|
||||
lb.vip_subnet_id, lb.tenant_id, lb_size)
|
||||
context, self.core_plugin, lb['id'], lb['vip_address'],
|
||||
sub_id, lb['tenant_id'], lb_size)
|
||||
|
||||
if not edge_id:
|
||||
msg = _('Failed to allocate Edge on subnet %(sub)s for '
|
||||
'loadbalancer %(lb)s') % {'sub': lb.vip_subnet_id,
|
||||
'lb': lb.id}
|
||||
'loadbalancer %(lb)s') % {'sub': sub_id, 'lb': lb['id']}
|
||||
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
|
||||
|
||||
try:
|
||||
@ -86,12 +84,12 @@ class EdgeLoadBalancerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
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)
|
||||
lb['vip_address'])
|
||||
else:
|
||||
lb_common.enable_edge_acceleration(self.vcns, edge_id)
|
||||
|
||||
edge_fw_rule_id = lb_common.add_vip_fw_rule(
|
||||
self.vcns, edge_id, lb.id, lb.vip_address)
|
||||
self.vcns, edge_id, lb['id'], lb['vip_address'])
|
||||
|
||||
# set LB default rule
|
||||
if not cfg.CONF.nsxv.use_routers_as_lbaas_platform:
|
||||
@ -99,24 +97,22 @@ class EdgeLoadBalancerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
'accept')
|
||||
|
||||
nsxv_db.add_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb.id, edge_id, edge_fw_rule_id,
|
||||
lb.vip_address)
|
||||
self.lbv2_driver.load_balancer.successful_completion(context, lb)
|
||||
context.session, lb['id'], edge_id, edge_fw_rule_id,
|
||||
lb['vip_address'])
|
||||
completor(success=True)
|
||||
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.load_balancer.failed_completion(context, lb)
|
||||
LOG.error('Failed to create pool %s', lb.id)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to create loadbalancer %s', lb['id'])
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_lb, new_lb):
|
||||
self.lbv2_driver.load_balancer.successful_completion(context, new_lb)
|
||||
def update(self, context, old_lb, new_lb, completor):
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, lb):
|
||||
def delete(self, context, lb, completor):
|
||||
# Discard any ports which are associated with LB
|
||||
filters = {
|
||||
'device_id': [lb.id],
|
||||
'device_id': [lb['id']],
|
||||
'device_owner': [constants.DEVICE_OWNER_NEUTRON_PREFIX + 'LB']}
|
||||
lb_ports = self.core_plugin.get_ports(context.elevated(),
|
||||
filters=filters)
|
||||
@ -124,7 +120,7 @@ class EdgeLoadBalancerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
self.core_plugin.delete_port(context.elevated(), lb_port['id'])
|
||||
|
||||
binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb.id)
|
||||
context.session, lb['id'])
|
||||
if binding:
|
||||
edge_binding = nsxv_db.get_nsxv_router_binding_by_edge(
|
||||
context.session, binding['edge_id'])
|
||||
@ -136,7 +132,7 @@ class EdgeLoadBalancerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
old_lb = lb_common.is_lb_on_router_edge(
|
||||
context, self.core_plugin, binding['edge_id'])
|
||||
if not old_lb:
|
||||
resource_id = lb_common.get_lb_resource_id(lb.id)
|
||||
resource_id = lb_common.get_lb_resource_id(lb['id'])
|
||||
self.core_plugin.edge_manager.delete_lrouter(
|
||||
context, resource_id, dist=False)
|
||||
else:
|
||||
@ -148,26 +144,24 @@ class EdgeLoadBalancerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
except nsxv_exc.VcnsApiException as e:
|
||||
LOG.error('Failed to delete loadbalancer %(lb)s '
|
||||
'FW rule. exception is %(exc)s',
|
||||
{'lb': lb.id, 'exc': e})
|
||||
{'lb': lb['id'], 'exc': e})
|
||||
try:
|
||||
lb_common.del_vip_as_secondary_ip(self.vcns,
|
||||
binding['edge_id'],
|
||||
lb.vip_address)
|
||||
lb['vip_address'])
|
||||
except Exception as e:
|
||||
LOG.error('Failed to delete loadbalancer %(lb)s '
|
||||
'interface IP. exception is %(exc)s',
|
||||
{'lb': lb.id, 'exc': e})
|
||||
{'lb': lb['id'], 'exc': e})
|
||||
|
||||
nsxv_db.del_nsxv_lbaas_loadbalancer_binding(context.session, lb.id)
|
||||
self.lbv2_driver.load_balancer.successful_completion(context, lb,
|
||||
delete=True)
|
||||
nsxv_db.del_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb['id'])
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def refresh(self, context, lb):
|
||||
# TODO(kobis): implememnt
|
||||
pass
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def stats(self, context, lb):
|
||||
stats = {'bytes_in': 0,
|
||||
'bytes_out': 0,
|
||||
@ -175,7 +169,7 @@ class EdgeLoadBalancerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
'total_connections': 0}
|
||||
|
||||
binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(context.session,
|
||||
lb.id)
|
||||
lb['id'])
|
||||
|
||||
try:
|
||||
lb_stats = self.vcns.get_loadbalancer_statistics(
|
@ -29,32 +29,32 @@ from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgeMemberManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
class EdgeMemberManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self, vcns_driver):
|
||||
super(EdgeMemberManager, self).__init__(vcns_driver)
|
||||
super(EdgeMemberManagerFromDict, self).__init__(vcns_driver)
|
||||
self._fw_section_id = None
|
||||
|
||||
def _get_pool_lb_id(self, member):
|
||||
listener = member.pool.listener
|
||||
if not member.get('pool'):
|
||||
return
|
||||
listener = member['pool']['listener']
|
||||
if listener:
|
||||
lb_id = listener.loadbalancer_id
|
||||
lb_id = listener['loadbalancer_id']
|
||||
else:
|
||||
lb_id = member.pool.loadbalancer.id
|
||||
lb_id = member['pool']['loadbalancer']['id']
|
||||
return lb_id
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, member):
|
||||
def create(self, context, member, completor):
|
||||
lb_id = self._get_pool_lb_id(member)
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
edge_id = lb_binding['edge_id']
|
||||
|
||||
pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
|
||||
context.session, lb_id, member.pool_id)
|
||||
context.session, lb_id, member['pool_id'])
|
||||
if not pool_binding:
|
||||
self.lbv2_driver.member.failed_completion(
|
||||
context, member)
|
||||
completor(success=False)
|
||||
msg = _('Failed to create member on edge: %s. '
|
||||
'Binding not found') % edge_id
|
||||
LOG.error(msg)
|
||||
@ -69,20 +69,20 @@ class EdgeMemberManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
# Verify that Edge appliance is connected to the member's
|
||||
# subnet (only if this is a dedicated loadbalancer edge)
|
||||
if not lb_common.get_lb_interface(
|
||||
context, self.core_plugin, lb_id, member.subnet_id):
|
||||
context, self.core_plugin, lb_id, member['subnet_id']):
|
||||
lb_common.create_lb_interface(
|
||||
context, self.core_plugin, lb_id, member.subnet_id,
|
||||
member.tenant_id)
|
||||
context, self.core_plugin, lb_id, member['subnet_id'],
|
||||
member['tenant_id'])
|
||||
|
||||
edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1]
|
||||
edge_member = {
|
||||
'ipAddress': member.address,
|
||||
'weight': member.weight,
|
||||
'port': member.protocol_port,
|
||||
'monitorPort': member.protocol_port,
|
||||
'name': lb_common.get_member_id(member.id),
|
||||
'ipAddress': member['address'],
|
||||
'weight': member['weight'],
|
||||
'port': member['protocol_port'],
|
||||
'monitorPort': member['protocol_port'],
|
||||
'name': lb_common.get_member_id(member['id']),
|
||||
'condition':
|
||||
'enabled' if member.admin_state_up else 'disabled'}
|
||||
'enabled' if member['admin_state_up'] else 'disabled'}
|
||||
|
||||
if edge_pool.get('member'):
|
||||
edge_pool['member'].append(edge_member)
|
||||
@ -91,69 +91,63 @@ class EdgeMemberManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
|
||||
try:
|
||||
self.vcns.update_pool(edge_id, edge_pool_id, edge_pool)
|
||||
self.lbv2_driver.member.successful_completion(context, member)
|
||||
completor(success=True)
|
||||
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.member.failed_completion(context, member)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to create member on edge: %s',
|
||||
edge_id)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_member, new_member):
|
||||
def update(self, context, old_member, new_member, completor):
|
||||
lb_id = self._get_pool_lb_id(new_member)
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(context.session,
|
||||
lb_id,
|
||||
new_member.pool_id)
|
||||
pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
|
||||
context.session, lb_id, new_member['pool_id'])
|
||||
|
||||
edge_id = lb_binding['edge_id']
|
||||
edge_pool_id = pool_binding['edge_pool_id']
|
||||
|
||||
edge_member = {
|
||||
'ipAddress': new_member.address,
|
||||
'weight': new_member.weight,
|
||||
'port': new_member.protocol_port,
|
||||
'monitorPort': new_member.protocol_port,
|
||||
'name': lb_common.get_member_id(new_member.id),
|
||||
'ipAddress': new_member['address'],
|
||||
'weight': new_member['weight'],
|
||||
'port': new_member['protocol_port'],
|
||||
'monitorPort': new_member['protocol_port'],
|
||||
'name': lb_common.get_member_id(new_member['id']),
|
||||
'condition':
|
||||
'enabled' if new_member.admin_state_up else 'disabled'}
|
||||
'enabled' if new_member['admin_state_up'] else 'disabled'}
|
||||
|
||||
with locking.LockManager.get_lock(edge_id):
|
||||
edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1]
|
||||
|
||||
if edge_pool.get('member'):
|
||||
for i, m in enumerate(edge_pool['member']):
|
||||
if m['name'] == lb_common.get_member_id(new_member.id):
|
||||
if m['name'] == lb_common.get_member_id(new_member['id']):
|
||||
edge_pool['member'][i] = edge_member
|
||||
break
|
||||
|
||||
try:
|
||||
self.vcns.update_pool(edge_id, edge_pool_id, edge_pool)
|
||||
|
||||
self.lbv2_driver.member.successful_completion(
|
||||
context, new_member)
|
||||
completor(success=True)
|
||||
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.member.failed_completion(
|
||||
context, new_member)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update member on edge: %s',
|
||||
edge_id)
|
||||
else:
|
||||
LOG.error('Pool %(pool_id)s on Edge %(edge_id)s has no '
|
||||
'members to update',
|
||||
{'pool_id': new_member.pool.id,
|
||||
{'pool_id': new_member['pool']['id'],
|
||||
'edge_id': edge_id})
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, member):
|
||||
def delete(self, context, member, completor):
|
||||
lb_id = self._get_pool_lb_id(member)
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
|
||||
context.session, lb_id, member.pool_id)
|
||||
context.session, lb_id, member['pool_id'])
|
||||
edge_id = lb_binding['edge_id']
|
||||
|
||||
with locking.LockManager.get_lock(edge_id):
|
||||
@ -161,38 +155,36 @@ class EdgeMemberManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
# we should remove LB subnet interface if no members are
|
||||
# attached and this is not the LB's VIP interface
|
||||
remove_interface = True
|
||||
if member.subnet_id == member.pool.loadbalancer.vip_subnet_id:
|
||||
pool = member['pool']
|
||||
subnet_id = member['subnet_id']
|
||||
if subnet_id == pool['loadbalancer']['vip_subnet_id']:
|
||||
remove_interface = False
|
||||
else:
|
||||
for m in member.pool.members:
|
||||
if (m.subnet_id == member.subnet_id and
|
||||
m.id != member.id):
|
||||
for m in pool['members']:
|
||||
if (m['subnet_id'] == subnet_id and
|
||||
m['id'] != member['id']):
|
||||
remove_interface = False
|
||||
if remove_interface:
|
||||
lb_common.delete_lb_interface(context, self.core_plugin,
|
||||
lb_id, member.subnet_id)
|
||||
lb_id, subnet_id)
|
||||
|
||||
if not pool_binding:
|
||||
self.lbv2_driver.member.successful_completion(
|
||||
context, member, delete=True)
|
||||
completor(success=True)
|
||||
return
|
||||
|
||||
edge_pool_id = pool_binding['edge_pool_id']
|
||||
edge_pool = self.vcns.get_pool(edge_id, edge_pool_id)[1]
|
||||
|
||||
for i, m in enumerate(edge_pool['member']):
|
||||
if m['name'] == lb_common.get_member_id(member.id):
|
||||
if m['name'] == lb_common.get_member_id(member['id']):
|
||||
edge_pool['member'].pop(i)
|
||||
break
|
||||
|
||||
try:
|
||||
self.vcns.update_pool(edge_id, edge_pool_id, edge_pool)
|
||||
|
||||
self.lbv2_driver.member.successful_completion(
|
||||
context, member, delete=True)
|
||||
completor(success=True)
|
||||
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.member.failed_completion(context, member)
|
||||
LOG.error('Failed to delete member on edge: %s',
|
||||
edge_id)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to delete member on edge: %s', edge_id)
|
@ -24,34 +24,34 @@ from vmware_nsx.db import nsxv_db
|
||||
from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as nsxv_exc
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas import lb_const
|
||||
from vmware_nsx.services.lbaas.nsx_v.implementation import listener_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import listener_mgr
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgePoolManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
class EdgePoolManagerFromDict(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self, vcns_driver):
|
||||
super(EdgePoolManager, self).__init__(vcns_driver)
|
||||
super(EdgePoolManagerFromDict, self).__init__(vcns_driver)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, pool):
|
||||
def create(self, context, pool, completor):
|
||||
|
||||
pool_id = pool['id']
|
||||
edge_pool = {
|
||||
'name': 'pool_' + pool.id,
|
||||
'description': getattr(pool, 'description', getattr(pool, 'name')),
|
||||
'algorithm': lb_const.BALANCE_MAP.get(pool.lb_algorithm,
|
||||
'name': 'pool_' + pool_id,
|
||||
'description': pool.get('description', pool.get('name')),
|
||||
'algorithm': lb_const.BALANCE_MAP.get(pool['lb_algorithm'],
|
||||
'round-robin'),
|
||||
'transparent': False
|
||||
}
|
||||
|
||||
lb_id = pool.loadbalancer_id
|
||||
lb_id = pool['loadbalancer_id']
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
if not lb_binding:
|
||||
msg = _(
|
||||
'No suitable Edge found for pool %s') % pool.id
|
||||
'No suitable Edge found for pool %s') % pool_id
|
||||
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
|
||||
edge_id = lb_binding['edge_id']
|
||||
|
||||
@ -60,16 +60,16 @@ class EdgePoolManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
h = self.vcns.create_pool(edge_id, edge_pool)[0]
|
||||
edge_pool_id = lb_common.extract_resource_id(h['location'])
|
||||
nsxv_db.add_nsxv_lbaas_pool_binding(context.session, lb_id,
|
||||
pool.id,
|
||||
pool_id,
|
||||
edge_pool_id)
|
||||
|
||||
if pool.listener:
|
||||
if pool['listener']:
|
||||
listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
|
||||
context.session, lb_id, pool.listener.id)
|
||||
context.session, lb_id, pool['listener']['id'])
|
||||
# Associate listener with pool
|
||||
vse = listener_mgr.listener_to_edge_vse(
|
||||
context,
|
||||
pool.listener,
|
||||
pool['listener'],
|
||||
lb_binding['vip_address'],
|
||||
edge_pool_id,
|
||||
listener_binding['app_profile_id'])
|
||||
@ -78,38 +78,36 @@ class EdgePoolManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
vse)
|
||||
# This action also set this pool as the default pool of the
|
||||
# listener, so the application profile may need to be updated
|
||||
if pool.session_persistence:
|
||||
if pool['session_persistence']:
|
||||
listener_mgr.update_app_profile(
|
||||
self.vcns, context, pool.listener, edge_id)
|
||||
self.vcns, context, pool['listener'], edge_id)
|
||||
|
||||
self.lbv2_driver.pool.successful_completion(context, pool)
|
||||
completor(success=True)
|
||||
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.pool.failed_completion(context, pool)
|
||||
LOG.error('Failed to create pool %s', pool.id)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to create pool %s', pool['id'])
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_pool, new_pool):
|
||||
def update(self, context, old_pool, new_pool, completor):
|
||||
edge_pool = {
|
||||
'name': 'pool_' + new_pool.id,
|
||||
'description': getattr(new_pool, 'description',
|
||||
getattr(new_pool, 'name')),
|
||||
'name': 'pool_' + new_pool['id'],
|
||||
'description': new_pool.get('description', new_pool.get('name')),
|
||||
'algorithm': lb_const.BALANCE_MAP.get(
|
||||
new_pool.lb_algorithm, 'round-robin'),
|
||||
new_pool['lb_algorithm'], 'round-robin'),
|
||||
'transparent': False
|
||||
}
|
||||
|
||||
if new_pool.listener:
|
||||
listener = new_pool.listener
|
||||
lb_id = listener.loadbalancer_id
|
||||
if new_pool['listener']:
|
||||
listener = new_pool['listener']
|
||||
lb_id = listener['loadbalancer_id']
|
||||
else:
|
||||
lb_id = new_pool.loadbalancer_id
|
||||
lb_id = new_pool['loadbalancer_id']
|
||||
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
|
||||
context.session, lb_id, new_pool.id)
|
||||
context.session, lb_id, new_pool['id'])
|
||||
|
||||
edge_id = lb_binding['edge_id']
|
||||
edge_pool_id = pool_binding['edge_pool_id']
|
||||
@ -128,52 +126,51 @@ class EdgePoolManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
|
||||
self.vcns.update_pool(edge_id, edge_pool_id, edge_pool)
|
||||
|
||||
self.lbv2_driver.pool.successful_completion(context, new_pool)
|
||||
completor(success=True)
|
||||
|
||||
# if the session_persistence was changed,
|
||||
# we may need to update the listener application profile
|
||||
if new_pool.listener:
|
||||
old_sess_persist = old_pool.session_persistence
|
||||
new_sess_persist = new_pool.session_persistence
|
||||
if new_pool['listener']:
|
||||
old_sess_persist = old_pool['session_persistence']
|
||||
new_sess_persist = new_pool['session_persistence']
|
||||
|
||||
if new_sess_persist != old_sess_persist:
|
||||
listener_mgr.update_app_profile(
|
||||
self.vcns, context, new_pool.listener, edge_id)
|
||||
self.vcns, context, new_pool['listener'], edge_id)
|
||||
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.pool.failed_completion(context, new_pool)
|
||||
LOG.error('Failed to update pool %s', new_pool.id)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update pool %s', new_pool['id'])
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, pool):
|
||||
lb_id = pool.loadbalancer_id
|
||||
def delete(self, context, pool, completor):
|
||||
lb_id = pool['loadbalancer_id']
|
||||
|
||||
lb_binding = nsxv_db.get_nsxv_lbaas_loadbalancer_binding(
|
||||
context.session, lb_id)
|
||||
pool_binding = nsxv_db.get_nsxv_lbaas_pool_binding(
|
||||
context.session, lb_id, pool.id)
|
||||
context.session, lb_id, pool['id'])
|
||||
|
||||
edge_id = lb_binding['edge_id']
|
||||
if not pool_binding:
|
||||
self.lbv2_driver.pool.successful_completion(
|
||||
context, pool, delete=True)
|
||||
completor(success=True)
|
||||
return
|
||||
|
||||
edge_pool_id = pool_binding['edge_pool_id']
|
||||
|
||||
listeners_to_update = []
|
||||
try:
|
||||
if pool.listeners:
|
||||
for listener in pool.listeners:
|
||||
if pool['listeners']:
|
||||
for listener in pool['listeners']:
|
||||
# the pool session persistence may affect the associated
|
||||
# pool application profile
|
||||
if (pool.session_persistence and listener.default_pool and
|
||||
listener.default_pool.id == pool.id):
|
||||
if (pool['session_persistence'] and
|
||||
listener['default_pool'] and
|
||||
listener['default_pool']['id'] == pool['id']):
|
||||
listeners_to_update.append(listener)
|
||||
|
||||
listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
|
||||
context.session, lb_id, listener.id)
|
||||
context.session, lb_id, listener['id'])
|
||||
vse = listener_mgr.listener_to_edge_vse(
|
||||
context,
|
||||
listener,
|
||||
@ -184,17 +181,16 @@ class EdgePoolManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
self.vcns.update_vip(
|
||||
edge_id, listener_binding['vse_id'], vse)
|
||||
self.vcns.delete_pool(edge_id, edge_pool_id)
|
||||
self.lbv2_driver.pool.successful_completion(
|
||||
context, pool, delete=True)
|
||||
completor(success=True)
|
||||
nsxv_db.del_nsxv_lbaas_pool_binding(
|
||||
context.session, lb_id, pool.id)
|
||||
context.session, lb_id, pool['id'])
|
||||
|
||||
for listener in listeners_to_update:
|
||||
# need to update the listeners too, now with no default pool
|
||||
listener.default_pool = None
|
||||
listener['default_pool'] = None
|
||||
listener_mgr.update_app_profile(
|
||||
self.vcns, context, listener, edge_id)
|
||||
|
||||
except nsxv_exc.VcnsApiException:
|
||||
self.lbv2_driver.pool.failed_completion(context, pool)
|
||||
LOG.error('Failed to delete pool %s', pool.id)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to delete pool %s', pool['id'])
|
@ -16,23 +16,63 @@
|
||||
|
||||
from oslo_log import helpers as log_helpers
|
||||
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import healthmon_mgr as hm_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import l7policy_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import l7rule_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import listener_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import loadbalancer_mgr as lb_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import member_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import pool_mgr
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas import lb_helper
|
||||
from vmware_nsx.services.lbaas import lb_translators
|
||||
from vmware_nsx.services.lbaas.nsx_v.implementation import healthmon_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.implementation import l7policy_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.implementation import l7rule_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.implementation import listener_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.implementation import loadbalancer_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.implementation import member_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.implementation import pool_mgr
|
||||
|
||||
|
||||
class EdgeLoadbalancerDriverV2(object):
|
||||
class EdgeLoadbalancerDriverV2(base_mgr.LoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self):
|
||||
super(EdgeLoadbalancerDriverV2, self).__init__()
|
||||
self.loadbalancer = lb_mgr.EdgeLoadBalancerManager(self)
|
||||
self.listener = listener_mgr.EdgeListenerManager(self)
|
||||
self.pool = pool_mgr.EdgePoolManager(self)
|
||||
self.member = member_mgr.EdgeMemberManager(self)
|
||||
self.healthmonitor = hm_mgr.EdgeHealthMonitorManager(self)
|
||||
self.l7policy = l7policy_mgr.EdgeL7PolicyManager(self)
|
||||
self.l7rule = l7rule_mgr.EdgeL7RuleManager(self)
|
||||
# Init all LBaaS objects
|
||||
# Note(asarfaty): self.lbv2_driver is not yet defined at init time
|
||||
# so lambda is used to retrieve it later.
|
||||
self.loadbalancer = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"loadbalancer",
|
||||
loadbalancer_mgr.EdgeLoadBalancerManagerFromDict(self),
|
||||
lb_translators.lb_loadbalancer_obj_to_dict,
|
||||
lambda: self.lbv2_driver.load_balancer)
|
||||
|
||||
self.listener = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"listener",
|
||||
listener_mgr.EdgeListenerManagerFromDict(self),
|
||||
lb_translators.lb_listener_obj_to_dict,
|
||||
lambda: self.lbv2_driver.listener)
|
||||
|
||||
self.pool = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"pool",
|
||||
pool_mgr.EdgePoolManagerFromDict(self),
|
||||
lb_translators.lb_pool_obj_to_dict,
|
||||
lambda: self.lbv2_driver.pool)
|
||||
|
||||
self.member = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"member",
|
||||
member_mgr.EdgeMemberManagerFromDict(self),
|
||||
lb_translators.lb_member_obj_to_dict,
|
||||
lambda: self.lbv2_driver.member)
|
||||
|
||||
self.healthmonitor = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"healthmonitor",
|
||||
healthmon_mgr.EdgeHealthMonitorManagerFromDict(self),
|
||||
lb_translators.lb_hm_obj_to_dict,
|
||||
lambda: self.lbv2_driver.health_monitor)
|
||||
|
||||
self.l7policy = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"l7policy",
|
||||
l7policy_mgr.EdgeL7PolicyManagerFromDict(self),
|
||||
lb_translators.lb_l7policy_obj_to_dict,
|
||||
lambda: self.lbv2_driver.l7policy)
|
||||
|
||||
self.l7rule = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"l7rule",
|
||||
l7rule_mgr.EdgeL7RuleManagerFromDict(self),
|
||||
lb_translators.lb_l7rule_obj_to_dict,
|
||||
lambda: self.lbv2_driver.l7rule)
|
||||
|
@ -22,53 +22,56 @@ from vmware_nsx._i18n import _
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas import lb_const
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import lb_utils
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import lb_utils
|
||||
from vmware_nsxlib.v3 import exceptions as nsxlib_exc
|
||||
from vmware_nsxlib.v3 import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgeHealthMonitorManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
class EdgeHealthMonitorManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self):
|
||||
super(EdgeHealthMonitorManager, self).__init__()
|
||||
super(EdgeHealthMonitorManagerFromDict, self).__init__()
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def _build_monitor_args(self, hm):
|
||||
if hm.type in lb_const.NSXV3_MONITOR_MAP:
|
||||
monitor_type = lb_const.NSXV3_MONITOR_MAP.get(hm.type)
|
||||
# TODO(asarfaty): Add description to backend parameters
|
||||
if hm['type'] in lb_const.NSXV3_MONITOR_MAP:
|
||||
monitor_type = lb_const.NSXV3_MONITOR_MAP.get(hm['type'])
|
||||
else:
|
||||
msg = (_('Cannot create health monitor %(monitor)s with '
|
||||
'type %(type)s') % {'monitor': hm.id, 'type': hm.type})
|
||||
'type %(type)s') % {'monitor': hm['id'],
|
||||
'type': hm['type']})
|
||||
raise n_exc.InvalidInput(error_message=msg)
|
||||
body = {'resource_type': monitor_type,
|
||||
'interval': hm.delay,
|
||||
'fall_count': hm.max_retries,
|
||||
'timeout': hm.timeout}
|
||||
'interval': hm['delay'],
|
||||
'fall_count': hm['max_retries'],
|
||||
'timeout': hm['timeout']}
|
||||
if monitor_type in [lb_const.LB_HEALTH_MONITOR_HTTP,
|
||||
lb_const.LB_HEALTH_MONITOR_HTTPS]:
|
||||
if hm.http_method:
|
||||
body['request_method'] = hm.http_method
|
||||
if hm.url_path:
|
||||
body['request_url'] = hm.url_path
|
||||
if hm['http_method']:
|
||||
body['request_method'] = hm['http_method']
|
||||
if hm['url_path']:
|
||||
body['request_url'] = hm['url_path']
|
||||
# TODO(tongl): nsxv3 backend doesn't support granular control
|
||||
# of expected_codes. So we ignore it and use default for now.
|
||||
# Once backend supports it, we can add it back.
|
||||
# if hm.expected_codes:
|
||||
# body['response_status'] = hm.expected_codes
|
||||
# if hm['expected_codes']:
|
||||
# body['response_status'] = hm['expected_codes']
|
||||
return body
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, hm):
|
||||
lb_id = hm.pool.loadbalancer_id
|
||||
pool_id = hm.pool.id
|
||||
def create(self, context, hm, completor):
|
||||
lb_id = hm['pool']['loadbalancer_id']
|
||||
pool_id = hm['pool']['id']
|
||||
pool_client = self.core_plugin.nsxlib.load_balancer.pool
|
||||
monitor_client = self.core_plugin.nsxlib.load_balancer.monitor
|
||||
monitor_name = utils.get_name_and_uuid(hm.name or 'monitor', hm.id)
|
||||
tags = lb_utils.get_tags(self.core_plugin, hm.id, lb_const.LB_HM_TYPE,
|
||||
hm.tenant_id, context.project_name)
|
||||
monitor_name = utils.get_name_and_uuid(hm['name'] or 'monitor',
|
||||
hm['id'])
|
||||
tags = lb_utils.get_tags(self.core_plugin, hm['id'],
|
||||
lb_const.LB_HM_TYPE,
|
||||
hm['tenant_id'], context.project_name)
|
||||
monitor_body = self._build_monitor_args(hm)
|
||||
|
||||
try:
|
||||
@ -76,7 +79,7 @@ class EdgeHealthMonitorManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
display_name=monitor_name, tags=tags, **monitor_body)
|
||||
except nsxlib_exc.ManagerError:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.health_monitor.failed_completion(context, hm)
|
||||
completor(success=False)
|
||||
|
||||
binding = nsx_db.get_nsx_lbaas_pool_binding(
|
||||
context.session, lb_id, pool_id)
|
||||
@ -86,31 +89,29 @@ class EdgeHealthMonitorManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
pool_client.add_monitor_to_pool(lb_pool_id,
|
||||
lb_monitor['id'])
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.health_monitor.failed_completion(
|
||||
context, hm)
|
||||
completor(success=False)
|
||||
msg = _('Failed to attach monitor %(monitor)s to pool '
|
||||
'%(pool)s') % {'monitor': lb_monitor['id'],
|
||||
'pool': lb_pool_id}
|
||||
raise n_exc.BadRequest(resource='lbaas-hm', msg=msg)
|
||||
nsx_db.add_nsx_lbaas_monitor_binding(
|
||||
context.session, lb_id, pool_id, hm.id, lb_monitor['id'],
|
||||
context.session, lb_id, pool_id, hm['id'], lb_monitor['id'],
|
||||
lb_pool_id)
|
||||
|
||||
self.lbv2_driver.health_monitor.successful_completion(context, hm)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_hm, new_hm):
|
||||
self.lbv2_driver.health_monitor.successful_completion(context, new_hm)
|
||||
def update(self, context, old_hm, new_hm, completor):
|
||||
# TODO(asarfaty): Shouldn't this be implemented?
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, hm):
|
||||
lb_id = hm.pool.loadbalancer_id
|
||||
pool_id = hm.pool.id
|
||||
def delete(self, context, hm, completor):
|
||||
lb_id = hm['pool']['loadbalancer_id']
|
||||
pool_id = hm['pool']['id']
|
||||
pool_client = self.core_plugin.nsxlib.load_balancer.pool
|
||||
monitor_client = self.core_plugin.nsxlib.load_balancer.monitor
|
||||
|
||||
binding = nsx_db.get_nsx_lbaas_monitor_binding(
|
||||
context.session, lb_id, pool_id, hm.id)
|
||||
context.session, lb_id, pool_id, hm['id'])
|
||||
if binding:
|
||||
lb_monitor_id = binding['lb_monitor_id']
|
||||
lb_pool_id = binding['lb_pool_id']
|
||||
@ -132,6 +133,5 @@ class EdgeHealthMonitorManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
'exc': exc})
|
||||
|
||||
nsx_db.delete_nsx_lbaas_monitor_binding(context.session, lb_id,
|
||||
pool_id, hm.id)
|
||||
self.lbv2_driver.health_monitor.successful_completion(
|
||||
context, hm, delete=True)
|
||||
pool_id, hm['id'])
|
||||
completor(success=True)
|
@ -22,16 +22,16 @@ from vmware_nsx._i18n import _
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas import lb_const
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import lb_utils
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import lb_utils
|
||||
from vmware_nsxlib.v3 import exceptions as nsxlib_exc
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgeL7PolicyManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
class EdgeL7PolicyManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self):
|
||||
super(EdgeL7PolicyManager, self).__init__()
|
||||
super(EdgeL7PolicyManagerFromDict, self).__init__()
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def _update_policy_position(self, vs_id, rule_id, position):
|
||||
@ -46,19 +46,18 @@ class EdgeL7PolicyManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
lb_rules.insert(position - 1, rule_id)
|
||||
vs_client.update(vs_id, rule_ids=lb_rules)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, policy):
|
||||
lb_id = policy.listener.loadbalancer_id
|
||||
listener_id = policy.listener_id
|
||||
def create(self, context, policy, completor):
|
||||
lb_id = policy['listener']['loadbalancer_id']
|
||||
listener_id = policy['listener_id']
|
||||
rule_client = self.core_plugin.nsxlib.load_balancer.rule
|
||||
tags = lb_utils.get_tags(self.core_plugin, policy.id,
|
||||
tags = lb_utils.get_tags(self.core_plugin, policy['id'],
|
||||
lb_const.LB_L7POLICY_TYPE,
|
||||
policy.tenant_id, context.project_name)
|
||||
policy['tenant_id'], context.project_name)
|
||||
|
||||
binding = nsx_db.get_nsx_lbaas_listener_binding(
|
||||
context.session, lb_id, listener_id)
|
||||
if not binding:
|
||||
self.lbv2_driver.l7policy.failed_completion(context, policy)
|
||||
completor(success=False)
|
||||
msg = _('Cannot find nsx lbaas binding for listener '
|
||||
'%(listener_id)s') % {'listener_id': listener_id}
|
||||
raise n_exc.BadRequest(resource='lbaas-l7policy-create', msg=msg)
|
||||
@ -69,31 +68,30 @@ class EdgeL7PolicyManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
lb_rule = rule_client.create(tags=tags, **rule_body)
|
||||
except nsxlib_exc.ManagerError:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.l7policy.failed_completion(context, policy)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to create lb rule at NSX backend')
|
||||
try:
|
||||
self._update_policy_position(vs_id, lb_rule['id'],
|
||||
policy.position)
|
||||
policy['position'])
|
||||
except nsxlib_exc.ManagerError:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.l7policy.failed_completion(context, policy)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to add rule %(rule)% to virtual server '
|
||||
'%(vs)s at NSX backend', {'rule': lb_rule['id'],
|
||||
'vs': vs_id})
|
||||
|
||||
nsx_db.add_nsx_lbaas_l7policy_binding(
|
||||
context.session, policy.id, lb_rule['id'], vs_id)
|
||||
self.lbv2_driver.l7policy.successful_completion(context, policy)
|
||||
context.session, policy['id'], lb_rule['id'], vs_id)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_policy, new_policy):
|
||||
def update(self, context, old_policy, new_policy, completor):
|
||||
rule_client = self.core_plugin.nsxlib.load_balancer.rule
|
||||
binding = nsx_db.get_nsx_lbaas_l7policy_binding(context.session,
|
||||
old_policy.id)
|
||||
old_policy['id'])
|
||||
if not binding:
|
||||
self.lbv2_driver.l7rule.failed_completion(context, new_policy)
|
||||
completor(success=False)
|
||||
msg = _('Cannot find nsx lbaas binding for policy '
|
||||
'%(policy_id)s') % {'policy_id': old_policy.id}
|
||||
'%(policy_id)s') % {'policy_id': old_policy['id']}
|
||||
raise n_exc.BadRequest(resource='lbaas-l7policy-update', msg=msg)
|
||||
|
||||
vs_id = binding['lb_vs_id']
|
||||
@ -101,25 +99,23 @@ class EdgeL7PolicyManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
rule_body = lb_utils.convert_l7policy_to_lb_rule(context, new_policy)
|
||||
try:
|
||||
rule_client.update(lb_rule_id, **rule_body)
|
||||
if new_policy.position != old_policy.position:
|
||||
if new_policy['position'] != old_policy['position']:
|
||||
self._update_policy_position(vs_id, lb_rule_id,
|
||||
new_policy.position)
|
||||
new_policy['position'])
|
||||
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.l7policy.failed_completion(context,
|
||||
new_policy)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update L7policy %(policy)s: '
|
||||
'%(err)s', {'policy': old_policy.id, 'err': e})
|
||||
'%(err)s', {'policy': old_policy['id'], 'err': e})
|
||||
|
||||
self.lbv2_driver.l7policy.successful_completion(context, new_policy)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, policy):
|
||||
def delete(self, context, policy, completor):
|
||||
vs_client = self.core_plugin.nsxlib.load_balancer.virtual_server
|
||||
rule_client = self.core_plugin.nsxlib.load_balancer.rule
|
||||
binding = nsx_db.get_nsx_lbaas_l7policy_binding(context.session,
|
||||
policy.id)
|
||||
policy['id'])
|
||||
if binding:
|
||||
vs_id = binding['lb_vs_id']
|
||||
rule_id = binding['lb_rule_id']
|
||||
@ -131,14 +127,12 @@ class EdgeL7PolicyManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
LOG.warning('LB rule %(rule)s is not found on NSX',
|
||||
{'rule': rule_id})
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.l7policy.failed_completion(
|
||||
context, policy)
|
||||
completor(success=False)
|
||||
msg = (_('Failed to delete lb rule: %(rule)s') %
|
||||
{'rule': rule_id})
|
||||
raise n_exc.BadRequest(resource='lbaas-l7policy-delete',
|
||||
msg=msg)
|
||||
nsx_db.delete_nsx_lbaas_l7policy_binding(
|
||||
context.session, policy.id)
|
||||
context.session, policy['id'])
|
||||
|
||||
self.lbv2_driver.l7policy.successful_completion(
|
||||
context, policy, delete=True)
|
||||
completor(success=True)
|
@ -21,49 +21,48 @@ from oslo_utils import excutils
|
||||
from vmware_nsx._i18n import _
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import lb_utils
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import lb_utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgeL7RuleManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
class EdgeL7RuleManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self):
|
||||
super(EdgeL7RuleManager, self).__init__()
|
||||
super(EdgeL7RuleManagerFromDict, self).__init__()
|
||||
|
||||
def _update_l7rule_change(self, context, rule, delete=False):
|
||||
def _update_l7rule_change(self, context, rule, completor,
|
||||
delete=False):
|
||||
rule_client = self.core_plugin.nsxlib.load_balancer.rule
|
||||
policy_id = rule['policy']['id']
|
||||
binding = nsx_db.get_nsx_lbaas_l7policy_binding(context.session,
|
||||
rule.policy.id)
|
||||
policy_id)
|
||||
if not binding:
|
||||
self.lbv2_driver.l7rule.failed_completion(context, rule)
|
||||
completor(success=False)
|
||||
msg = _('Cannot find nsx lbaas binding for policy '
|
||||
'%(policy_id)s') % {'policy_id': rule.policy.id}
|
||||
'%(policy_id)s') % {'policy_id': policy_id}
|
||||
raise n_exc.BadRequest(resource='lbaas-l7policy-update', msg=msg)
|
||||
|
||||
lb_rule_id = binding['lb_rule_id']
|
||||
if delete:
|
||||
lb_utils.remove_rule_from_policy(rule)
|
||||
rule_body = lb_utils.convert_l7policy_to_lb_rule(context, rule.policy)
|
||||
rule_body = lb_utils.convert_l7policy_to_lb_rule(
|
||||
context, rule['policy'])
|
||||
try:
|
||||
rule_client.update(lb_rule_id, **rule_body)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.l7rule.failed_completion(context, rule)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update L7policy %(policy)s: '
|
||||
'%(err)s', {'policy': rule.policy.id, 'err': e})
|
||||
'%(err)s', {'policy': policy_id, 'err': e})
|
||||
|
||||
self.lbv2_driver.l7rule.successful_completion(context, rule,
|
||||
delete=delete)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, rule):
|
||||
self._update_l7rule_change(context, rule)
|
||||
def create(self, context, rule, completor):
|
||||
self._update_l7rule_change(context, rule, completor)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_rule, new_rule):
|
||||
self._update_l7rule_change(context, new_rule)
|
||||
def update(self, context, old_rule, new_rule, completor):
|
||||
self._update_l7rule_change(context, new_rule, completor)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, rule):
|
||||
self._update_l7rule_change(context, rule, delete=True)
|
||||
def delete(self, context, rule, completor):
|
||||
self._update_l7rule_change(context, rule, completor, delete=True)
|
@ -92,49 +92,49 @@ def get_rule_match_conditions(policy):
|
||||
# values in rule have already been validated in LBaaS API,
|
||||
# we won't need to valid anymore in driver, and just get
|
||||
# the LB rule mapping from the dict.
|
||||
for rule in policy.rules:
|
||||
match_type = lb_const.LB_RULE_MATCH_TYPE[rule.compare_type]
|
||||
if rule.type == lb_const.L7_RULE_TYPE_COOKIE:
|
||||
header_value = rule.key + '=' + rule.value
|
||||
for rule in policy['rules']:
|
||||
match_type = lb_const.LB_RULE_MATCH_TYPE[rule['compare_type']]
|
||||
if rule['type'] == lb_const.L7_RULE_TYPE_COOKIE:
|
||||
header_value = rule['key'] + '=' + rule['value']
|
||||
match_conditions.append(
|
||||
{'type': 'LbHttpRequestHeaderCondition',
|
||||
'match_type': match_type,
|
||||
'header_name': 'Cookie',
|
||||
'header_value': header_value})
|
||||
elif rule.type == lb_const.L7_RULE_TYPE_FILE_TYPE:
|
||||
elif rule['type'] == lb_const.L7_RULE_TYPE_FILE_TYPE:
|
||||
match_conditions.append(
|
||||
{'type': 'LbHttpRequestUriCondition',
|
||||
'match_type': match_type,
|
||||
'uri': '*.' + rule.value})
|
||||
elif rule.type == lb_const.L7_RULE_TYPE_HEADER:
|
||||
'uri': '*.' + rule['value']})
|
||||
elif rule['type'] == lb_const.L7_RULE_TYPE_HEADER:
|
||||
match_conditions.append(
|
||||
{'type': 'LbHttpRequestHeaderCondition',
|
||||
'match_type': match_type,
|
||||
'header_name': rule.key,
|
||||
'header_value': rule.value})
|
||||
elif rule.type == lb_const.L7_RULE_TYPE_HOST_NAME:
|
||||
'header_name': rule['key'],
|
||||
'header_value': rule['value']})
|
||||
elif rule['type'] == lb_const.L7_RULE_TYPE_HOST_NAME:
|
||||
match_conditions.append(
|
||||
{'type': 'LbHttpRequestHeaderCondition',
|
||||
'match_type': match_type,
|
||||
'header_name': 'Host',
|
||||
'header_value': rule.value})
|
||||
elif rule.type == lb_const.L7_RULE_TYPE_PATH:
|
||||
'header_value': rule['value']})
|
||||
elif rule['type'] == lb_const.L7_RULE_TYPE_PATH:
|
||||
match_conditions.append(
|
||||
{'type': 'LbHttpRequestUriCondition',
|
||||
'match_type': match_type,
|
||||
'uri': rule.value})
|
||||
'uri': rule['value']})
|
||||
else:
|
||||
msg = (_('l7rule type %(type)s is not supported in LBaaS') %
|
||||
{'type': rule.type})
|
||||
{'type': rule['type']})
|
||||
raise n_exc.BadRequest(resource='lbaas-l7rule', msg=msg)
|
||||
return match_conditions
|
||||
|
||||
|
||||
def get_rule_actions(context, l7policy):
|
||||
lb_id = l7policy.listener.loadbalancer_id
|
||||
if l7policy.action == lb_const.L7_POLICY_ACTION_REDIRECT_TO_POOL:
|
||||
lb_id = l7policy['listener']['loadbalancer_id']
|
||||
if l7policy['action'] == lb_const.L7_POLICY_ACTION_REDIRECT_TO_POOL:
|
||||
pool_binding = nsx_db.get_nsx_lbaas_pool_binding(
|
||||
context.session, lb_id, l7policy.redirect_pool_id)
|
||||
context.session, lb_id, l7policy['redirect_pool_id'])
|
||||
if pool_binding:
|
||||
lb_pool_id = pool_binding['lb_pool_id']
|
||||
actions = [{'type': lb_const.LB_SELECT_POOL_ACTION,
|
||||
@ -143,16 +143,16 @@ def get_rule_actions(context, l7policy):
|
||||
msg = _('Failed to get LB pool binding from nsx db')
|
||||
raise n_exc.BadRequest(resource='lbaas-l7rule-create',
|
||||
msg=msg)
|
||||
elif l7policy.action == lb_const.L7_POLICY_ACTION_REDIRECT_TO_URL:
|
||||
elif l7policy['action'] == lb_const.L7_POLICY_ACTION_REDIRECT_TO_URL:
|
||||
actions = [{'type': lb_const.LB_HTTP_REDIRECT_ACTION,
|
||||
'redirect_status': lb_const.LB_HTTP_REDIRECT_STATUS,
|
||||
'redirect_url': l7policy.redirect_url}]
|
||||
elif l7policy.action == lb_const.L7_POLICY_ACTION_REJECT:
|
||||
'redirect_url': l7policy['redirect_url']}]
|
||||
elif l7policy['action'] == lb_const.L7_POLICY_ACTION_REJECT:
|
||||
actions = [{'type': lb_const.LB_REJECT_ACTION,
|
||||
'reply_status': lb_const.LB_HTTP_REJECT_STATUS}]
|
||||
else:
|
||||
msg = (_('Invalid l7policy action: %(action)s') %
|
||||
{'action': l7policy.action})
|
||||
{'action': l7policy['action']})
|
||||
raise n_exc.BadRequest(resource='lbaas-l7rule-create',
|
||||
msg=msg)
|
||||
return actions
|
||||
@ -168,5 +168,5 @@ def convert_l7policy_to_lb_rule(context, policy):
|
||||
|
||||
|
||||
def remove_rule_from_policy(rule):
|
||||
l7rules = rule.policy.rules
|
||||
rule.policy.rules = [r for r in l7rules if r.id != rule.id]
|
||||
l7rules = rule['policy']['rules']
|
||||
rule['policy']['rules'] = [r for r in l7rules if r['id'] != rule['id']]
|
@ -23,51 +23,51 @@ from vmware_nsx.common import exceptions as nsx_exc
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas import lb_const
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import lb_utils
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import lb_utils
|
||||
from vmware_nsxlib.v3 import exceptions as nsxlib_exc
|
||||
from vmware_nsxlib.v3 import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgeListenerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
class EdgeListenerManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self):
|
||||
super(EdgeListenerManager, self).__init__()
|
||||
super(EdgeListenerManagerFromDict, self).__init__()
|
||||
|
||||
def _get_virtual_server_kwargs(self, context, listener, vs_name, tags,
|
||||
app_profile_id, certificate=None):
|
||||
# If loadbalancer vip_port already has floating ip, use floating
|
||||
# IP as the virtual server VIP address. Else, use the loadbalancer
|
||||
# vip_address directly on virtual server.
|
||||
filters = {'port_id': [listener.loadbalancer.vip_port_id]}
|
||||
filters = {'port_id': [listener['loadbalancer']['vip_port_id']]}
|
||||
floating_ips = self.core_plugin.get_floatingips(context,
|
||||
filters=filters)
|
||||
if floating_ips:
|
||||
lb_vip_address = floating_ips[0]['floating_ip_address']
|
||||
else:
|
||||
lb_vip_address = listener.loadbalancer.vip_address
|
||||
kwargs = {'enabled': listener.admin_state_up,
|
||||
lb_vip_address = listener['loadbalancer']['vip_address']
|
||||
kwargs = {'enabled': listener['admin_state_up'],
|
||||
'ip_address': lb_vip_address,
|
||||
'port': listener.protocol_port,
|
||||
'port': listener['protocol_port'],
|
||||
'application_profile_id': app_profile_id}
|
||||
if vs_name:
|
||||
kwargs['display_name'] = vs_name
|
||||
if tags:
|
||||
kwargs['tags'] = tags
|
||||
if listener.connection_limit != -1:
|
||||
if listener['connection_limit'] != -1:
|
||||
kwargs['max_concurrent_connections'] = \
|
||||
listener.connection_limit
|
||||
if listener.default_pool_id:
|
||||
listener['connection_limit']
|
||||
if listener['default_pool_id']:
|
||||
pool_binding = nsx_db.get_nsx_lbaas_pool_binding(
|
||||
context.session, listener.loadbalancer.id,
|
||||
listener.default_pool_id)
|
||||
context.session, listener['loadbalancer']['id'],
|
||||
listener['default_pool_id'])
|
||||
if pool_binding:
|
||||
kwargs['pool_id'] = pool_binding.get('lb_pool_id')
|
||||
ssl_profile_binding = self._get_ssl_profile_binding(
|
||||
tags, certificate=certificate)
|
||||
if (listener.protocol == lb_const.LB_PROTOCOL_TERMINATED_HTTPS and
|
||||
ssl_profile_binding):
|
||||
if (listener['protocol'] == lb_const.LB_PROTOCOL_TERMINATED_HTTPS and
|
||||
ssl_profile_binding):
|
||||
kwargs.update(ssl_profile_binding)
|
||||
return kwargs
|
||||
|
||||
@ -95,38 +95,40 @@ class EdgeListenerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
}
|
||||
|
||||
def _get_listener_tags(self, context, listener):
|
||||
tags = lb_utils.get_tags(self.core_plugin, listener.id,
|
||||
tags = lb_utils.get_tags(self.core_plugin, listener['id'],
|
||||
lb_const.LB_LISTENER_TYPE,
|
||||
listener.tenant_id,
|
||||
listener['tenant_id'],
|
||||
context.project_name)
|
||||
tags.append({'scope': 'os-lbaas-lb-name',
|
||||
'tag': listener.loadbalancer.name[:utils.MAX_TAG_LEN]})
|
||||
tags.append({'scope': 'os-lbaas-lb-id',
|
||||
'tag': listener.loadbalancer_id})
|
||||
tags.append({
|
||||
'scope': 'os-lbaas-lb-name',
|
||||
'tag': listener['loadbalancer']['name'][:utils.MAX_TAG_LEN]})
|
||||
tags.append({
|
||||
'scope': 'os-lbaas-lb-id',
|
||||
'tag': listener['loadbalancer_id']})
|
||||
return tags
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, listener, certificate=None):
|
||||
lb_id = listener.loadbalancer_id
|
||||
load_balancer = self.core_plugin.nsxlib.load_balancer
|
||||
app_client = load_balancer.application_profile
|
||||
vs_client = load_balancer.virtual_server
|
||||
service_client = load_balancer.service
|
||||
vs_name = utils.get_name_and_uuid(listener.name or 'listener',
|
||||
listener.id)
|
||||
def create(self, context, listener, completor,
|
||||
certificate=None):
|
||||
lb_id = listener['loadbalancer_id']
|
||||
nsxlib_lb = self.core_plugin.nsxlib.load_balancer
|
||||
app_client = nsxlib_lb.application_profile
|
||||
vs_client = nsxlib_lb.virtual_server
|
||||
service_client = nsxlib_lb.service
|
||||
vs_name = utils.get_name_and_uuid(listener['name'] or 'listener',
|
||||
listener['id'])
|
||||
tags = self._get_listener_tags(context, listener)
|
||||
|
||||
if (listener.protocol == lb_const.LB_PROTOCOL_HTTP or
|
||||
listener.protocol == lb_const.LB_PROTOCOL_TERMINATED_HTTPS):
|
||||
if (listener['protocol'] == lb_const.LB_PROTOCOL_HTTP or
|
||||
listener['protocol'] == lb_const.LB_PROTOCOL_TERMINATED_HTTPS):
|
||||
profile_type = lb_const.LB_HTTP_PROFILE
|
||||
elif (listener.protocol == lb_const.LB_PROTOCOL_TCP or
|
||||
listener.protocol == lb_const.LB_PROTOCOL_HTTPS):
|
||||
elif (listener['protocol'] == lb_const.LB_PROTOCOL_TCP or
|
||||
listener['protocol'] == lb_const.LB_PROTOCOL_HTTPS):
|
||||
profile_type = lb_const.LB_TCP_PROFILE
|
||||
else:
|
||||
msg = (_('Cannot create listener %(listener)s with '
|
||||
'protocol %(protocol)s') %
|
||||
{'listener': listener.id,
|
||||
'protocol': listener.protocol})
|
||||
{'listener': listener['id'],
|
||||
'protocol': listener['protocol']})
|
||||
raise n_exc.BadRequest(resource='lbaas-listener', msg=msg)
|
||||
try:
|
||||
app_profile = app_client.create(
|
||||
@ -136,7 +138,7 @@ class EdgeListenerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
context, listener, vs_name, tags, app_profile_id, certificate)
|
||||
virtual_server = vs_client.create(**kwargs)
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.listener.failed_completion(context, listener)
|
||||
completor(success=False)
|
||||
msg = _('Failed to create virtual server at NSX backend')
|
||||
raise n_exc.BadRequest(resource='lbaas-listener', msg=msg)
|
||||
|
||||
@ -150,33 +152,35 @@ class EdgeListenerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
service_client.add_virtual_server(lb_service_id,
|
||||
virtual_server['id'])
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.listener.failed_completion(context, listener)
|
||||
completor(success=False)
|
||||
msg = _('Failed to add virtual server to lb service '
|
||||
'at NSX backend')
|
||||
raise n_exc.BadRequest(resource='lbaas-listener', msg=msg)
|
||||
|
||||
nsx_db.add_nsx_lbaas_listener_binding(
|
||||
context.session, lb_id, listener.id, app_profile_id,
|
||||
context.session, lb_id, listener['id'], app_profile_id,
|
||||
virtual_server['id'])
|
||||
self.lbv2_driver.listener.successful_completion(
|
||||
context, listener)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_listener, new_listener, certificate=None):
|
||||
vs_client = self.core_plugin.nsxlib.load_balancer.virtual_server
|
||||
app_client = self.core_plugin.nsxlib.load_balancer.application_profile
|
||||
def update(self, context, old_listener, new_listener, completor,
|
||||
certificate=None):
|
||||
nsxlib_lb = self.core_plugin.nsxlib.load_balancer
|
||||
vs_client = nsxlib_lb.virtual_server
|
||||
app_client = nsxlib_lb.application_profile
|
||||
vs_name = None
|
||||
tags = None
|
||||
if new_listener.name != old_listener.name:
|
||||
vs_name = utils.get_name_and_uuid(new_listener.name or 'listener',
|
||||
new_listener.id)
|
||||
if new_listener['name'] != old_listener['name']:
|
||||
vs_name = utils.get_name_and_uuid(
|
||||
new_listener['name'] or 'listener',
|
||||
new_listener['id'])
|
||||
tags = self._get_listener_tags(context, new_listener)
|
||||
|
||||
binding = nsx_db.get_nsx_lbaas_listener_binding(
|
||||
context.session, old_listener.loadbalancer_id, old_listener.id)
|
||||
context.session, old_listener['loadbalancer_id'],
|
||||
old_listener['id'])
|
||||
if not binding:
|
||||
msg = (_('Cannot find listener %(listener)s binding on NSX '
|
||||
'backend'), {'listener': old_listener.id})
|
||||
'backend'), {'listener': old_listener['id']})
|
||||
raise n_exc.BadRequest(resource='lbaas-listener', msg=msg)
|
||||
try:
|
||||
vs_id = binding['lb_vs_id']
|
||||
@ -188,26 +192,23 @@ class EdgeListenerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
if vs_name:
|
||||
app_client.update(app_profile_id, display_name=vs_name,
|
||||
tags=tags)
|
||||
self.lbv2_driver.listener.successful_completion(context,
|
||||
new_listener)
|
||||
completor(success=True)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.listener.failed_completion(
|
||||
context, new_listener)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update listener %(listener)s with '
|
||||
'error %(error)s',
|
||||
{'listener': old_listener.id, 'error': e})
|
||||
{'listener': old_listener['id'], 'error': e})
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, listener):
|
||||
lb_id = listener.loadbalancer_id
|
||||
load_balancer = self.core_plugin.nsxlib.load_balancer
|
||||
service_client = load_balancer.service
|
||||
vs_client = load_balancer.virtual_server
|
||||
app_client = load_balancer.application_profile
|
||||
def delete(self, context, listener, completor):
|
||||
lb_id = listener['loadbalancer_id']
|
||||
nsxlib_lb = self.core_plugin.nsxlib.load_balancer
|
||||
service_client = nsxlib_lb.service
|
||||
vs_client = nsxlib_lb.virtual_server
|
||||
app_client = nsxlib_lb.application_profile
|
||||
|
||||
binding = nsx_db.get_nsx_lbaas_listener_binding(
|
||||
context.session, lb_id, listener.id)
|
||||
context.session, lb_id, listener['id'])
|
||||
if binding:
|
||||
vs_id = binding['lb_vs_id']
|
||||
app_profile_id = binding['app_profile_id']
|
||||
@ -221,32 +222,30 @@ class EdgeListenerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
if vs_list and vs_id in vs_list:
|
||||
service_client.remove_virtual_server(lbs_id, vs_id)
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.listener.failed_completion(context,
|
||||
listener)
|
||||
completor(success=False)
|
||||
msg = (_('Failed to remove virtual server: %(listener)s '
|
||||
'from lb service %(lbs)s') %
|
||||
{'listener': listener.id, 'lbs': lbs_id})
|
||||
{'listener': listener['id'], 'lbs': lbs_id})
|
||||
raise n_exc.BadRequest(resource='lbaas-listener', msg=msg)
|
||||
try:
|
||||
if listener.default_pool_id:
|
||||
if listener.get('default_pool_id'):
|
||||
vs_client.update(vs_id, pool_id='')
|
||||
# Update pool binding to disassociate virtual server
|
||||
pool_binding = nsx_db.get_nsx_lbaas_pool_binding(
|
||||
context.session, lb_id, listener.default_pool_id)
|
||||
context.session, lb_id, listener['default_pool_id'])
|
||||
if pool_binding:
|
||||
nsx_db.update_nsx_lbaas_pool_binding(
|
||||
context.session, lb_id, listener.default_pool_id,
|
||||
None)
|
||||
context.session, lb_id,
|
||||
listener['default_pool_id'], None)
|
||||
vs_client.delete(vs_id)
|
||||
except nsx_exc.NsxResourceNotFound:
|
||||
msg = (_("virtual server not found on nsx: %(vs)s") %
|
||||
{'vs': vs_id})
|
||||
raise n_exc.BadRequest(resource='lbaas-listener', msg=msg)
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.listener.failed_completion(context,
|
||||
listener)
|
||||
completor(success=False)
|
||||
msg = (_('Failed to delete virtual server: %(listener)s') %
|
||||
{'listener': listener.id})
|
||||
{'listener': listener['id']})
|
||||
raise n_exc.BadRequest(resource='lbaas-listener', msg=msg)
|
||||
try:
|
||||
app_client.delete(app_profile_id)
|
||||
@ -255,30 +254,29 @@ class EdgeListenerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
app_profile_id)
|
||||
raise n_exc.BadRequest(resource='lbaas-listener', msg=msg)
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.listener.failed_completion(context,
|
||||
listener)
|
||||
completor(success=False)
|
||||
msg = (_('Failed to delete application profile: %(app)s') %
|
||||
{'app': app_profile_id})
|
||||
raise n_exc.BadRequest(resource='lbaas-listener', msg=msg)
|
||||
|
||||
# Delete imported NSX cert if there is any
|
||||
cert_tags = [{'scope': lb_const.LB_LISTENER_TYPE,
|
||||
'tag': listener.id}]
|
||||
'tag': listener['id']}]
|
||||
results = self.core_plugin.nsxlib.search_by_tags(
|
||||
tags=cert_tags)
|
||||
# Only delete object related to certificate used by listener
|
||||
for obj in results['results']:
|
||||
if obj.get('resource_type') in lb_const.LB_CERT_RESOURCE_TYPE:
|
||||
for res_obj in results['results']:
|
||||
res_type = res_obj.get('resource_type')
|
||||
if res_type in lb_const.LB_CERT_RESOURCE_TYPE:
|
||||
tm_client = self.core_plugin.nsxlib.trust_management
|
||||
try:
|
||||
tm_client.delete_cert(obj['id'])
|
||||
tm_client.delete_cert(res_obj['id'])
|
||||
except nsxlib_exc.ManagerError:
|
||||
LOG.error("Exception thrown when trying to delete "
|
||||
"certificate: %(cert)s",
|
||||
{'cert': obj['id']})
|
||||
{'cert': res_obj['id']})
|
||||
|
||||
nsx_db.delete_nsx_lbaas_listener_binding(
|
||||
context.session, lb_id, listener.id)
|
||||
context.session, lb_id, listener['id'])
|
||||
|
||||
self.lbv2_driver.listener.successful_completion(
|
||||
context, listener, delete=True)
|
||||
completor(success=True)
|
@ -15,7 +15,6 @@
|
||||
|
||||
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from oslo_log import helpers as log_helpers
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
|
||||
@ -23,39 +22,37 @@ from vmware_nsx._i18n import _
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas import lb_const
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import lb_utils
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import lb_utils
|
||||
from vmware_nsxlib.v3 import exceptions as nsxlib_exc
|
||||
from vmware_nsxlib.v3 import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgeLoadBalancerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
class EdgeLoadBalancerManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, lb):
|
||||
def create(self, context, lb, completor):
|
||||
if lb_utils.validate_lb_subnet(context, self.core_plugin,
|
||||
lb.vip_subnet_id):
|
||||
self.lbv2_driver.load_balancer.successful_completion(context, lb)
|
||||
lb['vip_subnet_id']):
|
||||
completor(success=True)
|
||||
else:
|
||||
msg = (_('Cannot create lb on subnet %(sub)s for '
|
||||
'loadbalancer %(lb)s. The subnet needs to connect a '
|
||||
'router which is already set gateway.') %
|
||||
{'sub': lb.vip_subnet_id, 'lb': lb.id})
|
||||
{'sub': lb['vip_subnet_id'], 'lb': lb['id']})
|
||||
raise n_exc.BadRequest(resource='lbaas-subnet', msg=msg)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_lb, new_lb):
|
||||
def update(self, context, old_lb, new_lb, completor):
|
||||
vs_client = self.core_plugin.nsxlib.load_balancer.virtual_server
|
||||
app_client = self.core_plugin.nsxlib.load_balancer.application_profile
|
||||
if new_lb.name != old_lb.name:
|
||||
for listener in new_lb.listeners:
|
||||
if new_lb['name'] != old_lb['name']:
|
||||
for listener in new_lb['listeners']:
|
||||
binding = nsx_db.get_nsx_lbaas_listener_binding(
|
||||
context.session, new_lb.id, listener.id)
|
||||
context.session, new_lb['id'], listener['id'])
|
||||
if binding:
|
||||
vs_id = binding['lb_vs_id']
|
||||
app_profile_id = binding['app_profile_id']
|
||||
new_lb_name = new_lb.name[:utils.MAX_TAG_LEN]
|
||||
new_lb_name = new_lb['name'][:utils.MAX_TAG_LEN]
|
||||
try:
|
||||
# Update tag on virtual server with new lb name
|
||||
vs = vs_client.get(vs_id)
|
||||
@ -71,19 +68,17 @@ class EdgeLoadBalancerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
|
||||
except nsxlib_exc.ManagerError:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.pool.failed_completion(context,
|
||||
new_lb)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update tag %(tag)s for lb '
|
||||
'%(lb)s', {'tag': updated_tags,
|
||||
'lb': new_lb.name})
|
||||
'lb': new_lb['name']})
|
||||
|
||||
self.lbv2_driver.load_balancer.successful_completion(context, new_lb)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, lb):
|
||||
def delete(self, context, lb, completor):
|
||||
service_client = self.core_plugin.nsxlib.load_balancer.service
|
||||
lb_binding = nsx_db.get_nsx_lbaas_loadbalancer_binding(
|
||||
context.session, lb.id)
|
||||
context.session, lb['id'])
|
||||
if lb_binding:
|
||||
lb_service_id = lb_binding['lb_service_id']
|
||||
nsx_router_id = lb_binding['lb_router_id']
|
||||
@ -103,22 +98,18 @@ class EdgeLoadBalancerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
router_client.update_advertisement(
|
||||
nsx_router_id, advertise_lb_vip=False)
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.load_balancer.failed_completion(
|
||||
context, lb, delete=True)
|
||||
completor(success=False)
|
||||
msg = (_('Failed to delete lb service %(lbs)s from nsx'
|
||||
) % {'lbs': lb_service_id})
|
||||
raise n_exc.BadRequest(resource='lbaas-lb', msg=msg)
|
||||
nsx_db.delete_nsx_lbaas_loadbalancer_binding(
|
||||
context.session, lb.id)
|
||||
self.lbv2_driver.load_balancer.successful_completion(
|
||||
context, lb, delete=True)
|
||||
context.session, lb['id'])
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def refresh(self, context, lb):
|
||||
# TODO(tongl): implememnt
|
||||
pass
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def stats(self, context, lb):
|
||||
# Since multiple LBaaS loadbalancer can share the same LB service,
|
||||
# get the corresponding virtual servers' stats instead of LB service.
|
||||
@ -129,7 +120,7 @@ class EdgeLoadBalancerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
|
||||
service_client = self.core_plugin.nsxlib.load_balancer.service
|
||||
lb_binding = nsx_db.get_nsx_lbaas_loadbalancer_binding(
|
||||
context.session, lb.id)
|
||||
context.session, lb['id'])
|
||||
vs_list = self._get_lb_virtual_servers(context, lb)
|
||||
if lb_binding:
|
||||
lb_service_id = lb_binding.get('lb_service_id')
|
||||
@ -148,16 +139,16 @@ class EdgeLoadBalancerManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
|
||||
except nsxlib_exc.ManagerError:
|
||||
msg = _('Failed to retrieve stats from LB service '
|
||||
'for loadbalancer %(lb)s') % {'lb': lb.id}
|
||||
'for loadbalancer %(lb)s') % {'lb': lb['id']}
|
||||
raise n_exc.BadRequest(resource='lbaas-lb', msg=msg)
|
||||
return stats
|
||||
|
||||
def _get_lb_virtual_servers(self, context, lb):
|
||||
# Get all virtual servers that belong to this loadbalancer
|
||||
vs_list = []
|
||||
for listener in lb.listeners:
|
||||
for listener in lb['listeners']:
|
||||
vs_binding = nsx_db.get_nsx_lbaas_listener_binding(
|
||||
context.session, lb.id, listener.id)
|
||||
context.session, lb['id'], listener['id'])
|
||||
if vs_binding:
|
||||
vs_list.append(vs_binding.get('lb_vs_id'))
|
||||
return vs_list
|
@ -24,17 +24,17 @@ from vmware_nsx.common import locking
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas import lb_const
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import lb_utils
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import lb_utils
|
||||
from vmware_nsxlib.v3 import exceptions as nsxlib_exc
|
||||
from vmware_nsxlib.v3 import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgeMemberManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
class EdgeMemberManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self):
|
||||
super(EdgeMemberManager, self).__init__()
|
||||
super(EdgeMemberManagerFromDict, self).__init__()
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def _get_info_from_fip(self, context, fip):
|
||||
@ -76,16 +76,16 @@ class EdgeMemberManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
|
||||
def _get_updated_pool_members(self, context, lb_pool, member):
|
||||
network = lb_utils.get_network_from_subnet(
|
||||
context, self.core_plugin, member.subnet_id)
|
||||
context, self.core_plugin, member['subnet_id'])
|
||||
if network.get('router:external'):
|
||||
fixed_ip, router_id = self._get_info_from_fip(
|
||||
context, member.address)
|
||||
context, member['address'])
|
||||
else:
|
||||
fixed_ip = member.address
|
||||
fixed_ip = member['address']
|
||||
for m in lb_pool['members']:
|
||||
if m['ip_address'] == fixed_ip:
|
||||
m['display_name'] = member.name[:219] + '_' + member.id
|
||||
m['weight'] = member.weight
|
||||
m['display_name'] = member['name'][:219] + '_' + member['id']
|
||||
m['weight'] = member['weight']
|
||||
return lb_pool['members']
|
||||
|
||||
@log_helpers.log_method_call
|
||||
@ -103,35 +103,34 @@ class EdgeMemberManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
LOG.debug("LB binding has already been added, and no need "
|
||||
"to add here.")
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, member):
|
||||
with locking.LockManager.get_lock('member-%s' %
|
||||
str(member.pool.loadbalancer_id)):
|
||||
self._member_create(context, member)
|
||||
def create(self, context, member, completor):
|
||||
with locking.LockManager.get_lock(
|
||||
'member-%s' % str(member['pool']['loadbalancer_id'])):
|
||||
self._member_create(context, member, completor)
|
||||
|
||||
def _member_create(self, context, member):
|
||||
lb_id = member.pool.loadbalancer_id
|
||||
pool_id = member.pool.id
|
||||
loadbalancer = member.pool.loadbalancer
|
||||
def _member_create(self, context, member, completor):
|
||||
lb_id = member['pool']['loadbalancer_id']
|
||||
pool_id = member['pool']['id']
|
||||
loadbalancer = member['pool']['loadbalancer']
|
||||
if not lb_utils.validate_lb_subnet(context, self.core_plugin,
|
||||
member.subnet_id):
|
||||
member['subnet_id']):
|
||||
msg = (_('Cannot add member %(member)s to pool as member subnet '
|
||||
'%(subnet)s is neither public nor connected to router') %
|
||||
{'member': member.id, 'subnet': member.subnet_id})
|
||||
{'member': member['id'], 'subnet': member['subnet_id']})
|
||||
raise n_exc.BadRequest(resource='lbaas-subnet', msg=msg)
|
||||
|
||||
pool_client = self.core_plugin.nsxlib.load_balancer.pool
|
||||
service_client = self.core_plugin.nsxlib.load_balancer.service
|
||||
|
||||
network = lb_utils.get_network_from_subnet(
|
||||
context, self.core_plugin, member.subnet_id)
|
||||
context, self.core_plugin, member['subnet_id'])
|
||||
if network.get('router:external'):
|
||||
router_id, fixed_ip = self._get_info_from_fip(
|
||||
context, member.address)
|
||||
context, member['address'])
|
||||
else:
|
||||
router_id = lb_utils.get_router_from_network(
|
||||
context, self.core_plugin, member.subnet_id)
|
||||
fixed_ip = member.address
|
||||
context, self.core_plugin, member['subnet_id'])
|
||||
fixed_ip = member['address']
|
||||
|
||||
binding = nsx_db.get_nsx_lbaas_pool_binding(context.session,
|
||||
lb_id, pool_id)
|
||||
@ -147,22 +146,22 @@ class EdgeMemberManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
nsx_router_id)
|
||||
if not lb_service:
|
||||
lb_size = lb_utils.get_lb_flavor_size(
|
||||
self.flavor_plugin, context, loadbalancer.flavor_id)
|
||||
self.flavor_plugin, context,
|
||||
loadbalancer.get('flavor_id'))
|
||||
lb_service = self._create_lb_service(
|
||||
context, service_client, member.tenant_id,
|
||||
router_id, nsx_router_id, loadbalancer.id, lb_size)
|
||||
context, service_client, member['tenant_id'],
|
||||
router_id, nsx_router_id, loadbalancer['id'], lb_size)
|
||||
if lb_service:
|
||||
lb_service_id = lb_service['id']
|
||||
self._add_loadbalancer_binding(
|
||||
context, loadbalancer.id, lb_service_id,
|
||||
nsx_router_id, loadbalancer.vip_address)
|
||||
context, loadbalancer['id'], lb_service_id,
|
||||
nsx_router_id, loadbalancer['vip_address'])
|
||||
if vs_id:
|
||||
try:
|
||||
service_client.add_virtual_server(lb_service_id,
|
||||
vs_id)
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.member.failed_completion(context,
|
||||
member)
|
||||
completor(success=False)
|
||||
msg = (_('Failed to attach virtual server %(vs)s '
|
||||
'to lb service %(service)s') %
|
||||
{'vs': vs_id, 'service': lb_service_id})
|
||||
@ -176,10 +175,11 @@ class EdgeMemberManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
|
||||
lb_pool = pool_client.get(lb_pool_id)
|
||||
old_m = lb_pool.get('members', None)
|
||||
new_m = [{'display_name': member.name[:219] + '_' + member.id,
|
||||
'ip_address': fixed_ip,
|
||||
'port': member.protocol_port,
|
||||
'weight': member.weight}]
|
||||
new_m = [{
|
||||
'display_name': member['name'][:219] + '_' + member['id'],
|
||||
'ip_address': fixed_ip,
|
||||
'port': member['protocol_port'],
|
||||
'weight': member['weight']}]
|
||||
members = (old_m + new_m) if old_m else new_m
|
||||
pool_client.update_pool_with_members(lb_pool_id, members)
|
||||
else:
|
||||
@ -187,12 +187,11 @@ class EdgeMemberManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
member['id'])
|
||||
raise nsx_exc.NsxPluginException(err_msg=msg)
|
||||
|
||||
self.lbv2_driver.member.successful_completion(context, member)
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_member, new_member):
|
||||
lb_id = old_member.pool.loadbalancer_id
|
||||
pool_id = old_member.pool.id
|
||||
def update(self, context, old_member, new_member, completor):
|
||||
lb_id = old_member['pool']['loadbalancer_id']
|
||||
pool_id = old_member['pool']['id']
|
||||
pool_client = self.core_plugin.nsxlib.load_balancer.pool
|
||||
pool_binding = nsx_db.get_nsx_lbaas_pool_binding(
|
||||
context.session, lb_id, pool_id)
|
||||
@ -206,18 +205,15 @@ class EdgeMemberManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
updated_members)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.member.failed_completion(
|
||||
context, new_member)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update member %(member)s: '
|
||||
'%(err)s',
|
||||
{'member': old_member.id, 'err': e})
|
||||
self.lbv2_driver.member.successful_completion(
|
||||
context, new_member)
|
||||
{'member': old_member['id'], 'err': e})
|
||||
completor(success=True)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, member):
|
||||
lb_id = member.pool.loadbalancer_id
|
||||
pool_id = member.pool.id
|
||||
def delete(self, context, member, completor):
|
||||
lb_id = member['pool']['loadbalancer_id']
|
||||
pool_id = member['pool']['id']
|
||||
pool_client = self.core_plugin.nsxlib.load_balancer.pool
|
||||
pool_binding = nsx_db.get_nsx_lbaas_pool_binding(
|
||||
context.session, lb_id, pool_id)
|
||||
@ -226,12 +222,12 @@ class EdgeMemberManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
try:
|
||||
lb_pool = pool_client.get(lb_pool_id)
|
||||
network = lb_utils.get_network_from_subnet(
|
||||
context, self.core_plugin, member.subnet_id)
|
||||
context, self.core_plugin, member['subnet_id'])
|
||||
if network.get('router:external'):
|
||||
fixed_ip, router_id = self._get_info_from_fip(
|
||||
context, member.address)
|
||||
context, member['address'])
|
||||
else:
|
||||
fixed_ip = member.address
|
||||
fixed_ip = member['address']
|
||||
if 'members' in lb_pool:
|
||||
m_list = lb_pool['members']
|
||||
members = [m for m in m_list
|
||||
@ -240,8 +236,8 @@ class EdgeMemberManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
except nsxlib_exc.ResourceNotFound:
|
||||
pass
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.member.failed_completion(context, member)
|
||||
completor(success=False)
|
||||
msg = _('Failed to remove member from pool on NSX backend')
|
||||
raise n_exc.BadRequest(resource='lbaas-member', msg=msg)
|
||||
self.lbv2_driver.member.successful_completion(
|
||||
context, member, delete=True)
|
||||
|
||||
completor(success=True)
|
@ -23,20 +23,21 @@ from vmware_nsx.common import exceptions as nsx_exc
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas import lb_const
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import lb_utils
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import lb_utils
|
||||
from vmware_nsxlib.v3 import exceptions as nsxlib_exc
|
||||
from vmware_nsxlib.v3 import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EdgePoolManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
class EdgePoolManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self):
|
||||
super(EdgePoolManager, self).__init__()
|
||||
super(EdgePoolManagerFromDict, self).__init__()
|
||||
|
||||
def _get_pool_kwargs(self, name=None, tags=None, algorithm=None,
|
||||
session_persistence=None):
|
||||
# TODO(asarfaty): Add description to backend parameters
|
||||
kwargs = {}
|
||||
if name:
|
||||
kwargs['display_name'] = name
|
||||
@ -50,36 +51,35 @@ class EdgePoolManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
return kwargs
|
||||
|
||||
def _get_pool_tags(self, context, pool):
|
||||
return lb_utils.get_tags(self.core_plugin, pool.id,
|
||||
lb_const.LB_POOL_TYPE, pool.tenant_id,
|
||||
return lb_utils.get_tags(self.core_plugin, pool['id'],
|
||||
lb_const.LB_POOL_TYPE, pool['tenant_id'],
|
||||
context.project_name)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def create(self, context, pool):
|
||||
lb_id = pool.loadbalancer_id
|
||||
def create(self, context, pool, completor):
|
||||
lb_id = pool['loadbalancer_id']
|
||||
pool_client = self.core_plugin.nsxlib.load_balancer.pool
|
||||
vs_client = self.core_plugin.nsxlib.load_balancer.virtual_server
|
||||
pool_name = utils.get_name_and_uuid(pool.name or 'pool', pool.id)
|
||||
pool_name = utils.get_name_and_uuid(pool['name'] or 'pool', pool['id'])
|
||||
tags = self._get_pool_tags(context, pool)
|
||||
|
||||
lb_algorithm = lb_const.LB_POOL_ALGORITHM_MAP.get(pool.lb_algorithm)
|
||||
lb_algorithm = lb_const.LB_POOL_ALGORITHM_MAP.get(pool['lb_algorithm'])
|
||||
try:
|
||||
kwargs = self._get_pool_kwargs(pool_name, tags, lb_algorithm)
|
||||
lb_pool = pool_client.create(**kwargs)
|
||||
nsx_db.add_nsx_lbaas_pool_binding(
|
||||
context.session, lb_id, pool.id, lb_pool['id'])
|
||||
context.session, lb_id, pool['id'], lb_pool['id'])
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.pool.failed_completion(context, pool)
|
||||
completor(success=False)
|
||||
msg = (_('Failed to create pool on NSX backend: %(pool)s') %
|
||||
{'pool': pool.id})
|
||||
{'pool': pool['id']})
|
||||
raise n_exc.BadRequest(resource='lbaas-pool', msg=msg)
|
||||
|
||||
# The pool object can be created with either --listener or
|
||||
# --loadbalancer option. If listener is present, the virtual server
|
||||
# will be updated with the pool. Otherwise, just return. The binding
|
||||
# will be added later when the pool is associated with layer7 rule.
|
||||
if pool.listener:
|
||||
listener_id = pool.listener.id
|
||||
if pool['listener']:
|
||||
listener_id = pool['listener']['id']
|
||||
binding = nsx_db.get_nsx_lbaas_listener_binding(
|
||||
context.session, lb_id, listener_id)
|
||||
if binding:
|
||||
@ -88,56 +88,55 @@ class EdgePoolManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
vs_client.update(vs_id, pool_id=lb_pool['id'])
|
||||
except nsxlib_exc.ManagerError:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.pool.failed_completion(context, pool)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to attach pool %s to virtual '
|
||||
'server %s', lb_pool['id'], vs_id)
|
||||
nsx_db.update_nsx_lbaas_pool_binding(
|
||||
context.session, lb_id, pool.id, vs_id)
|
||||
context.session, lb_id, pool['id'], vs_id)
|
||||
else:
|
||||
msg = (_("Couldn't find binding on the listener: %s") %
|
||||
listener_id)
|
||||
raise nsx_exc.NsxPluginException(err_msg=msg)
|
||||
self.lbv2_driver.pool.successful_completion(context, pool)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def update(self, context, old_pool, new_pool):
|
||||
completor(success=True)
|
||||
|
||||
def update(self, context, old_pool, new_pool, completor):
|
||||
pool_client = self.core_plugin.nsxlib.load_balancer.pool
|
||||
pool_name = None
|
||||
tags = None
|
||||
lb_algorithm = None
|
||||
if new_pool.name != old_pool.name:
|
||||
pool_name = utils.get_name_and_uuid(new_pool.name or 'pool',
|
||||
new_pool.id)
|
||||
if new_pool['name'] != old_pool['name']:
|
||||
pool_name = utils.get_name_and_uuid(new_pool['name'] or 'pool',
|
||||
new_pool['id'])
|
||||
tags = self._get_pool_tags(context, new_pool)
|
||||
if new_pool.lb_algorithm != old_pool.lb_algorithm:
|
||||
if new_pool['lb_algorithm'] != old_pool['lb_algorithm']:
|
||||
lb_algorithm = lb_const.LB_POOL_ALGORITHM_MAP.get(
|
||||
new_pool.lb_algorithm)
|
||||
new_pool['lb_algorithm'])
|
||||
binding = nsx_db.get_nsx_lbaas_pool_binding(
|
||||
context.session, old_pool.loadbalancer_id, old_pool.id)
|
||||
context.session, old_pool['loadbalancer_id'], old_pool['id'])
|
||||
if not binding:
|
||||
msg = (_('Cannot find pool %(pool)s binding on NSX db '
|
||||
'mapping'), {'pool': old_pool.id})
|
||||
'mapping') % {'pool': old_pool['id']})
|
||||
raise n_exc.BadRequest(resource='lbaas-pool', msg=msg)
|
||||
try:
|
||||
lb_pool_id = binding['lb_pool_id']
|
||||
kwargs = self._get_pool_kwargs(pool_name, tags, lb_algorithm)
|
||||
pool_client.update(lb_pool_id, **kwargs)
|
||||
self.lbv2_driver.pool.successful_completion(context, new_pool)
|
||||
completor(success=True)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.pool.failed_completion(context, new_pool)
|
||||
completor(success=False)
|
||||
LOG.error('Failed to update pool %(pool)s with '
|
||||
'error %(error)s',
|
||||
{'pool': old_pool.id, 'error': e})
|
||||
{'pool': old_pool['id'], 'error': e})
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete(self, context, pool):
|
||||
lb_id = pool.loadbalancer_id
|
||||
def delete(self, context, pool, completor):
|
||||
lb_id = pool['loadbalancer_id']
|
||||
pool_client = self.core_plugin.nsxlib.load_balancer.pool
|
||||
vs_client = self.core_plugin.nsxlib.load_balancer.virtual_server
|
||||
|
||||
binding = nsx_db.get_nsx_lbaas_pool_binding(
|
||||
context.session, lb_id, pool.id)
|
||||
context.session, lb_id, pool['id'])
|
||||
if binding:
|
||||
vs_id = binding.get('lb_vs_id')
|
||||
lb_pool_id = binding.get('lb_pool_id')
|
||||
@ -147,7 +146,7 @@ class EdgePoolManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
except nsxlib_exc.ResourceNotFound:
|
||||
pass
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.pool.failed_completion(context, pool)
|
||||
completor(success=False)
|
||||
msg = _('Failed to remove lb pool %(pool)s from virtual '
|
||||
'server %(vs)s') % {'pool': lb_pool_id,
|
||||
'vs': vs_id}
|
||||
@ -157,12 +156,11 @@ class EdgePoolManager(base_mgr.Nsxv3LoadbalancerBaseManager):
|
||||
except nsxlib_exc.ResourceNotFound:
|
||||
pass
|
||||
except nsxlib_exc.ManagerError:
|
||||
self.lbv2_driver.pool.failed_completion(context, pool)
|
||||
completor(success=False)
|
||||
msg = (_('Failed to delete lb pool from nsx: %(pool)s') %
|
||||
{'pool': lb_pool_id})
|
||||
raise n_exc.BadRequest(resource='lbaas-pool', msg=msg)
|
||||
nsx_db.delete_nsx_lbaas_pool_binding(context.session,
|
||||
lb_id, pool.id)
|
||||
lb_id, pool['id'])
|
||||
|
||||
self.lbv2_driver.pool.successful_completion(
|
||||
context, pool, delete=True)
|
||||
completor(success=True)
|
0
vmware_nsx/services/lbaas/nsx_v3/v2/__init__.py
Normal file
0
vmware_nsx/services/lbaas/nsx_v3/v2/__init__.py
Normal file
@ -23,13 +23,16 @@ from oslo_log import log as logging
|
||||
|
||||
from vmware_nsx._i18n import _
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import healthmonitor_mgr as hm_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import l7policy_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import l7rule_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import listener_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import loadbalancer_mgr as lb_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import member_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import pool_mgr
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas import lb_helper
|
||||
from vmware_nsx.services.lbaas import lb_translators
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import healthmonitor_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import l7policy_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import l7rule_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import listener_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import loadbalancer_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import member_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import pool_mgr
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -49,18 +52,56 @@ class NotImplementedManager(object):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class EdgeLoadbalancerDriverV2(object):
|
||||
class EdgeLoadbalancerDriverV2(base_mgr.LoadbalancerBaseManager):
|
||||
@log_helpers.log_method_call
|
||||
def __init__(self):
|
||||
super(EdgeLoadbalancerDriverV2, self).__init__()
|
||||
|
||||
self.loadbalancer = lb_mgr.EdgeLoadBalancerManager()
|
||||
self.listener = listener_mgr.EdgeListenerManager()
|
||||
self.pool = pool_mgr.EdgePoolManager()
|
||||
self.member = member_mgr.EdgeMemberManager()
|
||||
self.healthmonitor = hm_mgr.EdgeHealthMonitorManager()
|
||||
self.l7policy = l7policy_mgr.EdgeL7PolicyManager()
|
||||
self.l7rule = l7rule_mgr.EdgeL7RuleManager()
|
||||
# Init all LBaaS objects
|
||||
# Note(asarfaty): self.lbv2_driver is not yet defined at init time
|
||||
# so lambda is used to retrieve it later.
|
||||
self.loadbalancer = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"loadbalancer",
|
||||
loadbalancer_mgr.EdgeLoadBalancerManagerFromDict(),
|
||||
lb_translators.lb_loadbalancer_obj_to_dict,
|
||||
lambda: self.lbv2_driver.load_balancer)
|
||||
|
||||
self.listener = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"listener",
|
||||
listener_mgr.EdgeListenerManagerFromDict(),
|
||||
lb_translators.lb_listener_obj_to_dict,
|
||||
lambda: self.lbv2_driver.listener)
|
||||
|
||||
self.pool = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"pool",
|
||||
pool_mgr.EdgePoolManagerFromDict(),
|
||||
lb_translators.lb_pool_obj_to_dict,
|
||||
lambda: self.lbv2_driver.pool)
|
||||
|
||||
self.member = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"member",
|
||||
member_mgr.EdgeMemberManagerFromDict(),
|
||||
lb_translators.lb_member_obj_to_dict,
|
||||
lambda: self.lbv2_driver.member)
|
||||
|
||||
self.healthmonitor = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"healthmonitor",
|
||||
healthmonitor_mgr.EdgeHealthMonitorManagerFromDict(),
|
||||
lb_translators.lb_hm_obj_to_dict,
|
||||
lambda: self.lbv2_driver.health_monitor)
|
||||
|
||||
self.l7policy = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"l7policy",
|
||||
l7policy_mgr.EdgeL7PolicyManagerFromDict(),
|
||||
lb_translators.lb_l7policy_obj_to_dict,
|
||||
lambda: self.lbv2_driver.l7policy)
|
||||
|
||||
self.l7rule = lb_helper.LBaaSNSXObjectManagerWrapper(
|
||||
"l7rule",
|
||||
l7rule_mgr.EdgeL7RuleManagerFromDict(),
|
||||
lb_translators.lb_l7rule_obj_to_dict,
|
||||
lambda: self.lbv2_driver.l7rule)
|
||||
|
||||
self._subscribe_router_delete_callback()
|
||||
|
||||
def _subscribe_router_delete_callback(self):
|
@ -234,7 +234,8 @@ class TestEdgeLbaasV2LoadbalancerOnRtr(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.load_balancer.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.lb)
|
||||
self.lb,
|
||||
delete=False)
|
||||
mock_enable_edge_acceleration.assert_called_with(
|
||||
self.edge_driver.vcns, LB_EDGE_ID)
|
||||
|
||||
@ -246,7 +247,8 @@ class TestEdgeLbaasV2LoadbalancerOnRtr(BaseTestEdgeLbaasV2):
|
||||
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.load_balancer.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context, new_lb)
|
||||
mock_successful_completion.assert_called_with(self.context, new_lb,
|
||||
delete=False)
|
||||
|
||||
def test_delete_old(self):
|
||||
with mock.patch.object(nsxv_db, 'get_nsxv_lbaas_loadbalancer_binding'
|
||||
@ -375,7 +377,8 @@ class TestEdgeLbaasV2LoadbalancerOnEdge(TestEdgeLbaasV2LoadbalancerOnRtr):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.load_balancer.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.lb)
|
||||
self.lb,
|
||||
delete=False)
|
||||
mock_enable_edge_acceleration.assert_called_with(
|
||||
self.edge_driver.vcns, LB_EDGE_ID)
|
||||
self.lb.flavor_id = None
|
||||
@ -439,7 +442,8 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.listener.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.listener)
|
||||
self.listener,
|
||||
delete=False)
|
||||
|
||||
def test_update(self):
|
||||
new_listener = lb_models.Listener(LISTENER_ID, LB_TENANT_ID,
|
||||
@ -475,7 +479,8 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.listener.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
new_listener)
|
||||
new_listener,
|
||||
delete=False)
|
||||
|
||||
def test_delete(self):
|
||||
with mock.patch.object(nsxv_db, 'get_nsxv_lbaas_listener_binding'
|
||||
@ -547,7 +552,8 @@ class TestEdgeLbaasV2Pool(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.pool.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.pool)
|
||||
self.pool,
|
||||
delete=False)
|
||||
|
||||
def test_update(self):
|
||||
new_pool = lb_models.Pool(POOL_ID, LB_TENANT_ID, 'pool-name', '',
|
||||
@ -586,7 +592,8 @@ class TestEdgeLbaasV2Pool(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.pool.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
new_pool)
|
||||
new_pool,
|
||||
delete=False)
|
||||
|
||||
def test_delete(self):
|
||||
with mock.patch.object(nsxv_db, 'get_nsxv_lbaas_loadbalancer_binding'
|
||||
@ -653,7 +660,8 @@ class TestEdgeLbaasV2Member(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.member.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.member)
|
||||
self.member,
|
||||
delete=False)
|
||||
|
||||
def test_update(self):
|
||||
new_member = lb_models.Member(MEMBER_ID, LB_TENANT_ID, POOL_ID,
|
||||
@ -686,7 +694,8 @@ class TestEdgeLbaasV2Member(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.member.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
new_member)
|
||||
new_member,
|
||||
delete=False)
|
||||
|
||||
def test_delete(self):
|
||||
with mock.patch.object(nsxv_db, 'get_nsxv_lbaas_loadbalancer_binding'
|
||||
@ -764,7 +773,8 @@ class TestEdgeLbaasV2HealthMonitor(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.health_monitor.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.hm)
|
||||
self.hm,
|
||||
delete=False)
|
||||
|
||||
def test_update(self):
|
||||
new_hm = lb_models.HealthMonitor(HM_ID, LB_TENANT_ID, 'PING', 3, 3,
|
||||
@ -791,7 +801,8 @@ class TestEdgeLbaasV2HealthMonitor(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.health_monitor.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
new_hm)
|
||||
new_hm,
|
||||
delete=False)
|
||||
|
||||
def test_delete(self):
|
||||
with mock.patch.object(nsxv_db, 'get_nsxv_lbaas_loadbalancer_binding'
|
||||
@ -876,7 +887,8 @@ class TestEdgeLbaasV2L7Policy(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.l7policy.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.l7policy)
|
||||
self.l7policy,
|
||||
delete=False)
|
||||
|
||||
def test_update(self):
|
||||
url = 'http://www.test.com'
|
||||
@ -919,7 +931,8 @@ class TestEdgeLbaasV2L7Policy(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.l7policy.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
new_pol)
|
||||
new_pol,
|
||||
delete=False)
|
||||
|
||||
def test_delete(self):
|
||||
with mock.patch.object(nsxv_db, 'get_nsxv_lbaas_l7policy_binding'
|
||||
|
@ -51,7 +51,7 @@ from webob import exc
|
||||
from vmware_nsx.api_client import exception as api_exc
|
||||
from vmware_nsx.common import utils
|
||||
from vmware_nsx.plugins.nsx_v3 import plugin as nsx_plugin
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import lb_driver_v2
|
||||
from vmware_nsx.services.lbaas.nsx_v3.v2 import lb_driver_v2
|
||||
from vmware_nsx.tests import unit as vmware
|
||||
from vmware_nsx.tests.unit.extensions import test_metadata
|
||||
from vmware_nsxlib.tests.unit.v3 import mocks as nsx_v3_mocks
|
||||
@ -1407,11 +1407,11 @@ class L3NatTest(test_l3_plugin.L3BaseForIntTests, NsxV3PluginTestCaseMixin,
|
||||
mock_nsx_version.start()
|
||||
# Make sure the LB callback is not called on router deletion
|
||||
self.lb_mock1 = mock.patch(
|
||||
"vmware_nsx.services.lbaas.nsx_v3.lb_driver_v2."
|
||||
"vmware_nsx.services.lbaas.nsx_v3.v2.lb_driver_v2."
|
||||
"EdgeLoadbalancerDriverV2._check_lb_service_on_router")
|
||||
self.lb_mock1.start()
|
||||
self.lb_mock2 = mock.patch(
|
||||
"vmware_nsx.services.lbaas.nsx_v3.lb_driver_v2."
|
||||
"vmware_nsx.services.lbaas.nsx_v3.v2.lb_driver_v2."
|
||||
"EdgeLoadbalancerDriverV2._check_lb_service_on_router_interface")
|
||||
self.lb_mock2.start()
|
||||
|
||||
|
@ -21,8 +21,8 @@ from neutron_lib import exceptions as n_exc
|
||||
|
||||
from vmware_nsx.db import db as nsx_db
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import lb_driver_v2
|
||||
from vmware_nsx.services.lbaas.nsx_v3 import lb_utils
|
||||
from vmware_nsx.services.lbaas.nsx_v3.implementation import lb_utils
|
||||
from vmware_nsx.services.lbaas.nsx_v3.v2 import lb_driver_v2
|
||||
|
||||
|
||||
LB_VIP = '10.0.0.10'
|
||||
@ -213,7 +213,8 @@ class TestEdgeLbaasV2Loadbalancer(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.load_balancer.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.lb)
|
||||
self.lb,
|
||||
delete=False)
|
||||
|
||||
def test_update(self):
|
||||
new_lb = lb_models.LoadBalancer(LB_ID, 'yyy-yyy', 'lb1-new',
|
||||
@ -224,7 +225,8 @@ class TestEdgeLbaasV2Loadbalancer(BaseTestEdgeLbaasV2):
|
||||
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.load_balancer.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context, new_lb)
|
||||
mock_successful_completion.assert_called_with(self.context, new_lb,
|
||||
delete=False)
|
||||
|
||||
def test_delete(self):
|
||||
with mock.patch.object(nsx_db, 'get_nsx_lbaas_loadbalancer_binding'
|
||||
@ -296,7 +298,8 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.listener.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
listener)
|
||||
listener,
|
||||
delete=False)
|
||||
|
||||
def test_create_http_listener(self):
|
||||
self._create_listener()
|
||||
@ -336,7 +339,8 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.listener.successful_completion)
|
||||
mock_successful_completion.assert_called_with(
|
||||
self.context, self.terminated_https_listener)
|
||||
self.context, self.terminated_https_listener,
|
||||
delete=False)
|
||||
|
||||
def test_update(self):
|
||||
new_listener = lb_models.Listener(LISTENER_ID, LB_TENANT_ID,
|
||||
@ -356,7 +360,8 @@ class TestEdgeLbaasV2Listener(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.listener.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
new_listener)
|
||||
new_listener,
|
||||
delete=False)
|
||||
|
||||
def test_delete(self):
|
||||
with mock.patch.object(nsx_db, 'get_nsx_lbaas_listener_binding'
|
||||
@ -426,7 +431,8 @@ class TestEdgeLbaasV2Pool(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.pool.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.pool)
|
||||
self.pool,
|
||||
delete=False)
|
||||
|
||||
def test_update(self):
|
||||
new_pool = lb_models.Pool(POOL_ID, LB_TENANT_ID, 'pool-name', '',
|
||||
@ -441,7 +447,8 @@ class TestEdgeLbaasV2Pool(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.pool.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
new_pool)
|
||||
new_pool,
|
||||
delete=False)
|
||||
|
||||
def test_delete(self):
|
||||
with mock.patch.object(nsx_db, 'get_nsx_lbaas_pool_binding'
|
||||
@ -527,7 +534,8 @@ class TestEdgeLbaasV2Member(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.member.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.member)
|
||||
self.member,
|
||||
delete=False)
|
||||
|
||||
def test_create_lbs_no_router_gateway(self):
|
||||
with mock.patch.object(lb_utils, 'validate_lb_subnet'
|
||||
@ -583,7 +591,8 @@ class TestEdgeLbaasV2Member(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.member.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
new_member)
|
||||
new_member,
|
||||
delete=False)
|
||||
|
||||
def test_delete(self):
|
||||
with mock.patch.object(nsx_db, 'get_nsx_lbaas_pool_binding'
|
||||
@ -640,7 +649,8 @@ class TestEdgeLbaasV2HealthMonitor(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.health_monitor.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.hm)
|
||||
self.hm,
|
||||
delete=False)
|
||||
|
||||
def test_update(self):
|
||||
new_hm = lb_models.HealthMonitor(HM_ID, LB_TENANT_ID, 'PING', 3, 3,
|
||||
@ -649,7 +659,8 @@ class TestEdgeLbaasV2HealthMonitor(BaseTestEdgeLbaasV2):
|
||||
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.health_monitor.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context, new_hm)
|
||||
mock_successful_completion.assert_called_with(self.context, new_hm,
|
||||
delete=False)
|
||||
|
||||
def test_delete(self):
|
||||
with mock.patch.object(nsx_db, 'get_nsx_lbaas_monitor_binding'
|
||||
@ -712,7 +723,8 @@ class TestEdgeLbaasV2L7Policy(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.l7policy.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
self.l7policy)
|
||||
self.l7policy,
|
||||
delete=False)
|
||||
|
||||
def test_update(self):
|
||||
new_l7policy = lb_models.L7Policy(L7POLICY_ID, LB_TENANT_ID,
|
||||
@ -757,7 +769,8 @@ class TestEdgeLbaasV2L7Policy(BaseTestEdgeLbaasV2):
|
||||
mock_successful_completion = (
|
||||
self.lbv2_driver.l7policy.successful_completion)
|
||||
mock_successful_completion.assert_called_with(self.context,
|
||||
new_l7policy)
|
||||
new_l7policy,
|
||||
delete=False)
|
||||
|
||||
def test_delete(self):
|
||||
with mock.patch.object(nsx_db, 'get_nsx_lbaas_l7policy_binding'
|
||||
|
Loading…
x
Reference in New Issue
Block a user