diff --git a/vmware_nsx/services/lbaas/lb_const.py b/vmware_nsx/services/lbaas/lb_const.py index cce1900cb4..1f6dfaf48b 100644 --- a/vmware_nsx/services/lbaas/lb_const.py +++ b/vmware_nsx/services/lbaas/lb_const.py @@ -124,3 +124,8 @@ LOADBALANCERS = 'loadbalancers' LISTENERS = 'listeners' POOLS = 'pools' MEMBERS = 'members' + +ONLINE = 'ONLINE' +OFFLINE = 'OFFLINE' +DEGRADED = 'DEGRADED' +DISABLED = 'DISABLED' diff --git a/vmware_nsx/services/lbaas/lbaas_mocks.py b/vmware_nsx/services/lbaas/lbaas_mocks.py new file mode 100644 index 0000000000..b3ddd7282d --- /dev/null +++ b/vmware_nsx/services/lbaas/lbaas_mocks.py @@ -0,0 +1,21 @@ +# 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. + +# This file contains LBaaS mocks, to allow the vmware nsx plugins to work when +# LBaaS code does not exist, and LBaaS is not configured in neutron + + +class LoadBalancer(object): + pass diff --git a/vmware_nsx/services/lbaas/nsx_v3/implementation/loadbalancer_mgr.py b/vmware_nsx/services/lbaas/nsx_v3/implementation/loadbalancer_mgr.py index 0b6a5928f6..d71d93ec75 100644 --- a/vmware_nsx/services/lbaas/nsx_v3/implementation/loadbalancer_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_v3/implementation/loadbalancer_mgr.py @@ -18,8 +18,6 @@ from neutron_lib import exceptions as n_exc from oslo_log import log as logging from oslo_utils import excutils -from neutron_lbaas.services.loadbalancer import constants - from vmware_nsx._i18n import _ from vmware_nsx.db import db as nsx_db from vmware_nsx.services.lbaas import base_mgr @@ -115,21 +113,21 @@ class EdgeLoadBalancerManagerFromDict(base_mgr.Nsxv3LoadbalancerBaseManager): def _nsx_status_to_lb_status(self, nsx_status): if not nsx_status: # default fallback - return constants.ONLINE + return lb_const.ONLINE # Statuses that are considered ONLINE: if nsx_status.upper() in ['UP', 'UNKNOWN', 'PARTIALLY_UP', 'NO_STANDBY']: - return constants.ONLINE + return lb_const.ONLINE # Statuses that are considered OFFLINE: if nsx_status.upper() in ['PRIMARY_DOWN', 'DETACHED', 'DOWN', 'ERROR']: - return constants.OFFLINE + return lb_const.OFFLINE if nsx_status.upper() == 'DISABLED': - return constants.DISABLED + return lb_const.DISABLED # default fallback LOG.debug("NSX LB status %s - interpreted as ONLINE", nsx_status) - return constants.ONLINE + return lb_const.ONLINE def get_lb_pool_members_statuses(self, nsx_pool_id, members_statuses): # Combine the NSX pool members data and the NSX statuses to provide diff --git a/vmware_nsx/services/lbaas/octavia/octavia_listener.py b/vmware_nsx/services/lbaas/octavia/octavia_listener.py index bb2a58aa64..14fd365377 100644 --- a/vmware_nsx/services/lbaas/octavia/octavia_listener.py +++ b/vmware_nsx/services/lbaas/octavia/octavia_listener.py @@ -25,10 +25,14 @@ from oslo_log import log as logging import oslo_messaging as messaging from oslo_messaging.rpc import dispatcher -from neutron_lbaas.db.loadbalancer import models - from vmware_nsx.services.lbaas.octavia import constants +try: + from neutron_lbaas.db.loadbalancer import models +except ImportError: + # LBaaS project not found. + from vmware_nsx.services.lbaas import lbaas_mocks as models + LOG = logging.getLogger(__name__) @@ -342,6 +346,10 @@ class NSXOctaviaStatisticsCollector(object): case that the plugin is currently unavailable, but entries already exist on the DB. """ + if not hasattr(models.LoadBalancer, '__tablename__'): + # No neutron-lbaas on this deployment + return [] + nl_loadbalancers = context.session.query(models.LoadBalancer).all() return [lb.id for lb in nl_loadbalancers]