LBaaS: Share base_mgr between nsxv and nsxv3
In vmware-nsx lbaas service folder, the base_mgr module can be shared between nsxv and nsxv3. Thus move it under lbaas folder so it can be use by nsxv3 as well. To have minimum impact on nsxv side, rename base to LoadbalancerBaseManager and subclass EdgeLoadbalancerBaseManager from it. Also, this patch fixes a few pep8 error. Change-Id: I994d39a5dbdb38e1b7805b2eec97e8ef7719f556
This commit is contained in:
parent
091cb5a148
commit
931c5a89f1
@ -227,6 +227,8 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
# Create the client to interface with the NSX-v
|
||||
_nsx_v_callbacks = edge_utils.NsxVCallbacks(self)
|
||||
self.nsx_v = vcns_driver.VcnsDriver(_nsx_v_callbacks)
|
||||
# Use the existing class instead of creating a new instance
|
||||
self.lbv2_driver = self.nsx_v
|
||||
# Ensure that edges do concurrency
|
||||
self._ensure_lock_operations()
|
||||
# Configure aggregate publishing
|
||||
|
@ -18,34 +18,40 @@ from neutron_lib.plugins import constants as plugin_const
|
||||
from neutron_lib.plugins import directory
|
||||
|
||||
|
||||
class EdgeLoadbalancerBaseManager(object):
|
||||
class LoadbalancerBaseManager(object):
|
||||
_lbv2_driver = None
|
||||
_core_plugin = None
|
||||
|
||||
def __init__(self, vcns_driver):
|
||||
super(EdgeLoadbalancerBaseManager, self).__init__()
|
||||
self.vcns_driver = vcns_driver
|
||||
def __init__(self):
|
||||
super(LoadbalancerBaseManager, self).__init__()
|
||||
|
||||
def _get_plugin(self, plugin_type):
|
||||
return directory.get_plugin(plugin_type)
|
||||
|
||||
@property
|
||||
def lbv2_driver(self):
|
||||
if not EdgeLoadbalancerBaseManager._lbv2_driver:
|
||||
if not LoadbalancerBaseManager._lbv2_driver:
|
||||
plugin = self._get_plugin(
|
||||
plugin_const.LOADBALANCERV2)
|
||||
EdgeLoadbalancerBaseManager._lbv2_driver = (
|
||||
LoadbalancerBaseManager._lbv2_driver = (
|
||||
plugin.drivers['vmwareedge'])
|
||||
|
||||
return EdgeLoadbalancerBaseManager._lbv2_driver
|
||||
return LoadbalancerBaseManager._lbv2_driver
|
||||
|
||||
@property
|
||||
def core_plugin(self):
|
||||
if not EdgeLoadbalancerBaseManager._core_plugin:
|
||||
EdgeLoadbalancerBaseManager._core_plugin = (
|
||||
if not LoadbalancerBaseManager._core_plugin:
|
||||
LoadbalancerBaseManager._core_plugin = (
|
||||
self._get_plugin(lib_const.CORE))
|
||||
|
||||
return EdgeLoadbalancerBaseManager._core_plugin
|
||||
return LoadbalancerBaseManager._core_plugin
|
||||
|
||||
|
||||
class EdgeLoadbalancerBaseManager(LoadbalancerBaseManager):
|
||||
|
||||
def __init__(self, vcns_driver):
|
||||
super(EdgeLoadbalancerBaseManager, self).__init__()
|
||||
self.vcns_driver = vcns_driver
|
||||
|
||||
@property
|
||||
def vcns(self):
|
@ -20,9 +20,9 @@ from oslo_utils import excutils
|
||||
from vmware_nsx.common import locking
|
||||
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.nsx_v import lbaas_common as lb_common
|
||||
from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -130,7 +130,7 @@ 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)
|
||||
new_hm)
|
||||
LOG.error('Failed to update monitor on edge: %s', edge_id)
|
||||
|
||||
self.lbv2_driver.health_monitor.successful_completion(context, new_hm)
|
||||
@ -170,7 +170,7 @@ class EdgeHealthMonitorManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
except nsxv_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.health_monitor.failed_completion(context,
|
||||
hm)
|
||||
hm)
|
||||
LOG.error('Failed to delete monitor on edge: %s', edge_id)
|
||||
|
||||
nsxv_db.del_nsxv_lbaas_monitor_binding(
|
||||
|
@ -23,9 +23,9 @@ from neutron_lib import exceptions as n_exc
|
||||
from vmware_nsx._i18n import _
|
||||
from vmware_nsx.common import locking
|
||||
from vmware_nsx.db import nsxv_db
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
|
||||
from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -57,34 +57,34 @@ def policy_to_application_rule(policy):
|
||||
# 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,
|
||||
'hdr_type': hdr_type,
|
||||
'key': rule.key,
|
||||
'val': rule.value})
|
||||
'%(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:
|
||||
# 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,
|
||||
'hdr_type': hdr_type,
|
||||
'key': rule.key,
|
||||
'val': rule.value})
|
||||
'-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:
|
||||
# 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,
|
||||
'hdr_type': hdr_type,
|
||||
'val': rule.value})
|
||||
'-i %(val)s' % {'rule_id': rule.id,
|
||||
'hdr_type': hdr_type,
|
||||
'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,
|
||||
'path_type': path_type,
|
||||
'val': rule.value})
|
||||
'-i %(val)s' % {'rule_id': rule.id,
|
||||
'path_type': path_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.
|
||||
@ -93,8 +93,8 @@ def policy_to_application_rule(policy):
|
||||
if not val.startswith('.'):
|
||||
val = '.' + val
|
||||
rule_line = ('acl %(rule_id)s path_sub '
|
||||
'-i %(val)s' % {'rule_id': rule.id,
|
||||
'val': val})
|
||||
'-i %(val)s' % {'rule_id': rule.id,
|
||||
'val': val})
|
||||
else:
|
||||
msg = _('Unsupported L7rule type %s') % rule.type
|
||||
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
|
||||
|
@ -18,7 +18,7 @@ from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
|
||||
from vmware_nsx.common import locking
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import l7policy_mgr
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -22,9 +22,9 @@ from vmware_nsx.common import exceptions as nsxv_exc
|
||||
from vmware_nsx.common import locking
|
||||
from vmware_nsx.db import nsxv_db
|
||||
from vmware_nsx.plugins.nsx_v.vshield.common import exceptions as vcns_exc
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
|
||||
from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -38,8 +38,8 @@ def listener_to_edge_app_profile(listener, edge_cert_id):
|
||||
'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': [],
|
||||
@ -262,7 +262,7 @@ class EdgeListenerManager(base_mgr.EdgeLoadbalancerBaseManager):
|
||||
except vcns_exc.VcnsApiException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
self.lbv2_driver.listener.failed_completion(context,
|
||||
new_listener)
|
||||
new_listener)
|
||||
LOG.error('Failed to update app profile on edge: %s',
|
||||
edge_id)
|
||||
|
||||
|
@ -25,8 +25,8 @@ from oslo_utils import excutils
|
||||
from vmware_nsx._i18n import _
|
||||
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.nsx_v import lbaas_common as lb_common
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -20,8 +20,8 @@ from oslo_utils import excutils
|
||||
from vmware_nsx.common import locking
|
||||
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.nsx_v import lbaas_common as lb_common
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -22,9 +22,9 @@ from neutron_lib import exceptions as n_exc
|
||||
from vmware_nsx.common import locking
|
||||
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.nsx_v import lbaas_common as lb_common
|
||||
from vmware_nsx.services.lbaas.nsx_v import lbaas_const as lb_const
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import listener_mgr
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -21,8 +21,8 @@ from neutron_lib import context
|
||||
|
||||
from vmware_nsx.db import nsxv_db
|
||||
from vmware_nsx.plugins.nsx_v.vshield import vcns_driver
|
||||
from vmware_nsx.services.lbaas import base_mgr
|
||||
from vmware_nsx.services.lbaas.nsx_v import lbaas_common as lb_common
|
||||
from vmware_nsx.services.lbaas.nsx_v.v2 import base_mgr
|
||||
|
||||
|
||||
LB_VIP = '10.0.0.10'
|
||||
@ -98,8 +98,8 @@ class BaseTestEdgeLbaasV2(base.BaseTestCase):
|
||||
|
||||
self.lbv2_driver = mock.Mock()
|
||||
self.core_plugin = mock.Mock()
|
||||
base_mgr.EdgeLoadbalancerBaseManager._lbv2_driver = self.lbv2_driver
|
||||
base_mgr.EdgeLoadbalancerBaseManager._core_plugin = self.core_plugin
|
||||
base_mgr.LoadbalancerBaseManager._lbv2_driver = self.lbv2_driver
|
||||
base_mgr.LoadbalancerBaseManager._core_plugin = self.core_plugin
|
||||
self._patch_lb_plugin(self.lbv2_driver, self._tested_entity)
|
||||
|
||||
self.lb = lb_models.LoadBalancer(LB_ID, LB_TENANT_ID, 'lb-name', '',
|
||||
|
Loading…
x
Reference in New Issue
Block a user