From 4ea97143e659889902830fa79a41237c7c66f531 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Mon, 18 Dec 2017 05:16:30 -0800 Subject: [PATCH] TVD: LBaaS support Change-Id: I3dda84a4d9d5df4ea39457a5d089a698b88cf69f --- vmware_nsx/plugins/nsx/plugin.py | 2 + vmware_nsx/services/lbaas/base_mgr.py | 24 +++ vmware_nsx/services/lbaas/nsx/__init__.py | 0 vmware_nsx/services/lbaas/nsx/lb_driver_v2.py | 198 ++++++++++++++++++ 4 files changed, 224 insertions(+) create mode 100644 vmware_nsx/services/lbaas/nsx/__init__.py create mode 100644 vmware_nsx/services/lbaas/nsx/lb_driver_v2.py diff --git a/vmware_nsx/plugins/nsx/plugin.py b/vmware_nsx/plugins/nsx/plugin.py index d665e97a79..9bdd5d0290 100644 --- a/vmware_nsx/plugins/nsx/plugin.py +++ b/vmware_nsx/plugins/nsx/plugin.py @@ -53,6 +53,7 @@ from vmware_nsx.plugins.common import plugin as nsx_plugin_common from vmware_nsx.plugins.dvs import plugin as dvs from vmware_nsx.plugins.nsx_v import plugin as v from vmware_nsx.plugins.nsx_v3 import plugin as t +from vmware_nsx.services.lbaas.nsx import lb_driver_v2 LOG = logging.getLogger(__name__) TVD_PLUGIN_TYPE = "Nsx-TVD" @@ -102,6 +103,7 @@ class NsxTVDPlugin(addr_pair_db.AllowedAddressPairsMixin, # init the extensions supported by any of the plugins self.init_extensions() + self.lbv2_driver = lb_driver_v2.EdgeLoadbalancerDriverV2() @staticmethod def plugin_type(): diff --git a/vmware_nsx/services/lbaas/base_mgr.py b/vmware_nsx/services/lbaas/base_mgr.py index 6708f6d2d0..723cd61683 100644 --- a/vmware_nsx/services/lbaas/base_mgr.py +++ b/vmware_nsx/services/lbaas/base_mgr.py @@ -17,6 +17,8 @@ from neutron_lib.plugins import constants as plugin_const from neutron_lib.plugins import directory from oslo_log import log as logging +from vmware_nsx.extensions import projectpluginmap + LOG = logging.getLogger(__name__) @@ -68,8 +70,30 @@ class EdgeLoadbalancerBaseManager(LoadbalancerBaseManager): def vcns(self): return self.vcns_driver.vcns + @property + def core_plugin(self): + if not self._core_plugin: + self._core_plugin = ( + self._get_plugin(plugin_const.CORE)) + if self._core_plugin.is_tvd_plugin(): + # get the plugin that match this driver + self._core_plugin = self._core_plugin.get_plugin_by_type( + projectpluginmap.NsxPlugins.NSX_V) + return self._core_plugin + class Nsxv3LoadbalancerBaseManager(LoadbalancerBaseManager): def __init__(self): super(Nsxv3LoadbalancerBaseManager, self).__init__() + + @property + def core_plugin(self): + if not self._core_plugin: + self._core_plugin = ( + self._get_plugin(plugin_const.CORE)) + if self._core_plugin.is_tvd_plugin(): + # get the plugin that match this driver + self._core_plugin = self._core_plugin.get_plugin_by_type( + projectpluginmap.NsxPlugins.NSX_T) + return self._core_plugin diff --git a/vmware_nsx/services/lbaas/nsx/__init__.py b/vmware_nsx/services/lbaas/nsx/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vmware_nsx/services/lbaas/nsx/lb_driver_v2.py b/vmware_nsx/services/lbaas/nsx/lb_driver_v2.py new file mode 100644 index 0000000000..639dd889e8 --- /dev/null +++ b/vmware_nsx/services/lbaas/nsx/lb_driver_v2.py @@ -0,0 +1,198 @@ +# Copyright 2017 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 oslo_log import log as logging + +from vmware_nsx.services.lbaas import base_mgr + +LOG = logging.getLogger(__name__) + + +class EdgeLoadbalancerDriverV2(object): + @log_helpers.log_method_call + def __init__(self): + super(EdgeLoadbalancerDriverV2, self).__init__() + + self.loadbalancer = EdgeLoadBalancerManager() + self.listener = EdgeListenerManager() + self.pool = EdgePoolManager() + self.member = EdgeMemberManager() + self.healthmonitor = EdgeHealthMonitorManager() + self.l7policy = EdgeL7PolicyManager() + self.l7rule = EdgeL7RuleManager() + + +class EdgeLoadBalancerManager(base_mgr.LoadbalancerBaseManager): + + @log_helpers.log_method_call + def create(self, context, lb): + p = self.core_plugin._get_plugin_from_project(context, + lb.tenant_id) + return p.lbv2_driver.loadbalancer.create(context, lb) + + @log_helpers.log_method_call + def update(self, context, old_lb, new_lb): + p = self.core_plugin._get_plugin_from_project(context, + new_lb.tenant_id) + return p.lbv2_driver.loadbalancer.update(context, old_lb, new_lb) + + @log_helpers.log_method_call + def delete(self, context, lb): + p = self.core_plugin._get_plugin_from_project(context, + lb.tenant_id) + return p.lbv2_driver.loadbalancer.delete(context, lb) + + @log_helpers.log_method_call + def refresh(self, context, lb): + p = self.core_plugin._get_plugin_from_project(context, + lb.tenant_id) + return p.lbv2_driver.loadbalancer.refresh(context, lb) + + @log_helpers.log_method_call + def stats(self, context, lb): + p = self.core_plugin._get_plugin_from_project(context, + lb.tenant_id) + return p.lbv2_driver.loadbalancer.stats(context, lb) + + +class EdgeListenerManager(base_mgr.LoadbalancerBaseManager): + + @log_helpers.log_method_call + def create(self, context, listener, certificate=None): + p = self.core_plugin._get_plugin_from_project(context, + listener.tenant_id) + return p.lbv2_driver.listener.create(context, listener, + certificate=certificate) + + @log_helpers.log_method_call + def update(self, context, old_listener, new_listener, certificate=None): + p = self.core_plugin._get_plugin_from_project(context, + new_listener.tenant_id) + return p.lbv2_driver.listener.update(context, + old_listener, + new_listener, + certificate=certificate) + + @log_helpers.log_method_call + def delete(self, context, listener): + p = self.core_plugin._get_plugin_from_project(context, + listener.tenant_id) + return p.lbv2_driver.listener.delete(context, listener) + + +class EdgePoolManager(base_mgr.LoadbalancerBaseManager): + + @log_helpers.log_method_call + def create(self, context, pool): + p = self.core_plugin._get_plugin_from_project(context, + pool.tenant_id) + return p.lbv2_driver.pool.create(context, pool) + + @log_helpers.log_method_call + def update(self, context, old_pool, new_pool): + p = self.core_plugin._get_plugin_from_project(context, + new_pool.tenant_id) + return p.lbv2_driver.pool.update(context, old_pool, new_pool) + + @log_helpers.log_method_call + def delete(self, context, pool): + p = self.core_plugin._get_plugin_from_project(context, + pool.tenant_id) + return p.lbv2_driver.pool.delete(context, pool) + + +class EdgeMemberManager(base_mgr.LoadbalancerBaseManager): + + @log_helpers.log_method_call + def create(self, context, member): + p = self.core_plugin._get_plugin_from_project(context, + member.tenant_id) + return p.lbv2_driver.member.create(context, member) + + @log_helpers.log_method_call + def update(self, context, old_member, new_member): + p = self.core_plugin._get_plugin_from_project(context, + new_member.tenant_id) + return p.lbv2_driver.member.update(context, old_member, new_member) + + @log_helpers.log_method_call + def delete(self, context, member): + p = self.core_plugin._get_plugin_from_project(context, + member.tenant_id) + return p.lbv2_driver.member.delete(context, member) + + +class EdgeHealthMonitorManager(base_mgr.LoadbalancerBaseManager): + + @log_helpers.log_method_call + def create(self, context, hm): + p = self.core_plugin._get_plugin_from_project(context, + hm.tenant_id) + return p.lbv2_driver.healthmonitor.create(context, hm) + + @log_helpers.log_method_call + def update(self, context, old_hm, new_hm): + p = self.core_plugin._get_plugin_from_project(context, + new_hm.tenant_id) + return p.lbv2_driver.healthmonitor.update(context, old_hm, new_hm) + + @log_helpers.log_method_call + def delete(self, context, hm): + p = self.core_plugin._get_plugin_from_project(context, + hm.tenant_id) + return p.lbv2_driver.healthmonitor.delete(context, hm) + + +class EdgeL7PolicyManager(base_mgr.LoadbalancerBaseManager): + + @log_helpers.log_method_call + def create(self, context, policy): + p = self.core_plugin._get_plugin_from_project(context, + policy.tenant_id) + return p.lbv2_driver.l7policy.create(context, policy) + + @log_helpers.log_method_call + def update(self, context, old_policy, new_policy): + p = self.core_plugin._get_plugin_from_project(context, + new_policy.tenant_id) + return p.lbv2_driver.l7policy.update(context, old_policy, new_policy) + + @log_helpers.log_method_call + def delete(self, context, policy): + p = self.core_plugin._get_plugin_from_project(context, + policy.tenant_id) + return p.lbv2_driver.l7policy.delete(context, policy) + + +class EdgeL7RuleManager(base_mgr.LoadbalancerBaseManager): + + @log_helpers.log_method_call + def create(self, context, rule): + p = self.core_plugin._get_plugin_from_project(context, + rule.tenant_id) + return p.lbv2_driver.l7rule.create(context, rule) + + @log_helpers.log_method_call + def update(self, context, old_rule, new_rule): + p = self.core_plugin._get_plugin_from_project(context, + new_rule.tenant_id) + return p.lbv2_driver.l7rule.update(context, old_rule, new_rule) + + @log_helpers.log_method_call + def delete(self, context, rule): + p = self.core_plugin._get_plugin_from_project(context, + rule.tenant_id) + return p.lbv2_driver.l7rule.delete(context, rule)