diff --git a/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/driver.py b/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/driver.py new file mode 100644 index 0000000..1e91a9c --- /dev/null +++ b/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/driver.py @@ -0,0 +1,61 @@ +try: + from neutron.services.loadbalancer.drivers import abstract_driver +except ImportError: + from neutron_lbaas.services.loadbalancer.drivers import abstract_driver + +"""Dummy LBAAS driver for OpenContrail. + +This allows to specify a default provider in the neutron.conf. + +LBAAS drivers are now in contrail svc_monitor. +""" + + +class OpencontrailLoadbalancerDummyDriver( + abstract_driver.LoadBalancerAbstractDriver): + + def __init__(self, plugin): + pass + + def create_vip(self, context, vip): + pass + + def update_vip(self, context, old_vip, vip): + pass + + def delete_vip(self, context, vip): + pass + + def create_pool(self, context, pool): + pass + + def update_pool(self, context, old_pool, pool): + pass + + def delete_pool(self, context, pool): + pass + + def stats(self, context, pool_id): + pass + + def create_member(self, context, member): + pass + + def update_member(self, context, old_member, member): + pass + + def delete_member(self, context, member): + pass + + def update_pool_health_monitor(self, context, + health_monitor, + pool_id): + pass + + def create_pool_health_monitor(self, context, + health_monitor, + pool_id): + pass + + def delete_pool_health_monitor(self, context, health_monitor, pool_id): + pass diff --git a/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/loadbalancer_pool.py b/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/loadbalancer_pool.py index 60956f5..fd29be8 100644 --- a/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/loadbalancer_pool.py +++ b/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/loadbalancer_pool.py @@ -143,13 +143,8 @@ def create(self, context, pool): Create a loadbalancer_pool object. """ p = pool['pool'] - try: - sas_fq_name = ["default-global-system-config"] - sas_fq_name.append(p['provider']) - sas_obj = self._api.service_appliance_set_read(fq_name=sas_fq_name) - except NoIdError: - raise pconf.ServiceProviderNotFound( - provider=p['provider'], service_type=constants.LOADBALANCER) + + sas_obj = self.check_provider_exists(p['provider']) tenant_id = self._get_tenant_id_for_create(context, p) project = self._project_read(project_id=tenant_id) @@ -176,7 +171,7 @@ def create(self, context, pool): pool.set_service_appliance_set(sas_obj) - # Custom attributes + # Custom attributes if p['custom_attributes'] != attr.ATTR_NOT_SPECIFIED: custom_attributes = KeyValuePairs() self.create_update_custom_attributes(p['custom_attributes'], custom_attributes) diff --git a/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/plugin.py b/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/plugin.py index 67bb9b3..aec2bd2 100644 --- a/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/plugin.py +++ b/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/plugin.py @@ -7,6 +7,9 @@ from neutron.extensions import loadbalancer except ImportError: from neutron_lbaas.extensions import loadbalancer +from neutron.db import servicetype_db as sdb +from neutron.plugins.common import constants +from neutron.services import provider_configuration as pconf class LoadBalancerPlugin(LoadBalancerPluginDb): @@ -17,13 +20,26 @@ class LoadBalancerPlugin(LoadBalancerPluginDb): def __init__(self): super(LoadBalancerPlugin, self).__init__() + self._get_default_provider() + + def _get_default_provider(self): + service_type_manager = sdb.ServiceTypeManager.get_instance() + try: + provider = (service_type_manager. + get_default_service_provider(None, + constants.LOADBALANCER)) + except pconf.DefaultServiceProviderNotFound: + self.default_provider = "opencontrail" + else: + self._pool_manager.check_provider_exists(provider['name']) + self.default_provider = provider['name'] def get_plugin_description(self): return "OpenContrail LoadBalancer Service Plugin" def _pool_update_provider(self, context, pool): if 'provider' not in pool or not pool['provider'] or pool['provider'].__class__ is object: - pool['provider'] = "opencontrail" + pool['provider'] = self.default_provider def create_pool(self, context, pool): self._pool_update_provider(context, pool['pool']) diff --git a/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/resource_manager.py b/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/resource_manager.py index 219852e..d15ecd3 100644 --- a/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/resource_manager.py +++ b/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/resource_manager.py @@ -2,18 +2,20 @@ # Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. # +import six +import uuid from abc import ABCMeta, abstractmethod, abstractproperty from eventlet import greenthread + from neutron.common import exceptions as n_exc try: from neutron.extensions import loadbalancer except ImportError: from neutron_lbaas.extensions import loadbalancer - from neutron.plugins.common import constants +from neutron.services import provider_configuration as pconf + from vnc_api.vnc_api import NoIdError, RefsExistError -import six -import uuid class LoadbalancerMethodInvalid(n_exc.BadRequest): @@ -111,6 +113,19 @@ def update_object(self, obj, id, resource): """ return False + def check_provider_exists(self, provider_name): + """ + Check if service-appliance-set for provider exists in the API + """ + try: + sas_fq_name = ["default-global-system-config"] + sas_fq_name.append(provider_name) + sas_obj = self._api.service_appliance_set_read(fq_name=sas_fq_name) + except NoIdError: + raise pconf.ServiceProviderNotFound( + provider=provider_name, service_type=constants.LOADBALANCER) + return sas_obj + def _get_tenant_id_for_create(self, context, resource): if context.is_admin and 'tenant_id' in resource: tenant_id = resource['tenant_id']