diff --git a/etc/octavia.conf b/etc/octavia.conf index e032abb730..7ebb136e4a 100644 --- a/etc/octavia.conf +++ b/etc/octavia.conf @@ -203,3 +203,11 @@ # Amphora MASTER gratuitous ARP refresh settings # vrrp_garp_refresh_interval = 5 # vrrp_garp_refresh_count = 2 + +[nova] +# The name of the nova service in the keystone catalog +# service_name = + +[neutron] +# The name of the neutron service in the keystone catalog +# service_name = \ No newline at end of file diff --git a/octavia/common/clients.py b/octavia/common/clients.py index 53a754b62f..4297694cfb 100644 --- a/octavia/common/clients.py +++ b/octavia/common/clients.py @@ -27,18 +27,22 @@ class NovaAuth(object): nova_client = None @classmethod - def get_nova_client(cls, region): + def get_nova_client(cls, region, service_name=None): """Create nova client object. :param region: The region of the service + :param service_name: The name of the nova service in the catalog :return: a Nova Client object. :raises Exception: if the client cannot be created """ if not cls.nova_client: + kwargs = {'region_name': region, + 'session': keystone.get_session()} + if service_name: + kwargs['service_name'] = service_name try: cls.nova_client = nova_client.Client( - NOVA_VERSION, session=keystone.get_session(), - region_name=region + NOVA_VERSION, **kwargs ) except Exception: with excutils.save_and_reraise_exception(): @@ -50,18 +54,22 @@ class NeutronAuth(object): neutron_client = None @classmethod - def get_neutron_client(cls, region): + def get_neutron_client(cls, region, service_name=None): """Create neutron client object. :param region: The region of the service + :param service_name: The name of the neutron service in the catalog :return: a Neutron Client object. :raises Exception: if the client cannot be created """ if not cls.neutron_client: + kwargs = {'region_name': region, + 'session': keystone.get_session()} + if service_name: + kwargs['service_name'] = service_name try: cls.neutron_client = neutron_client.Client( - NEUTRON_VERSION, session=keystone.get_session(), - region_name=region + NEUTRON_VERSION, **kwargs ) except Exception: with excutils.save_and_reraise_exception(): diff --git a/octavia/common/config.py b/octavia/common/config.py index 8197128b2d..e6965c68a4 100644 --- a/octavia/common/config.py +++ b/octavia/common/config.py @@ -342,6 +342,17 @@ keepalived_vrrp_opts = [ ] +nova_opts = [ + cfg.StrOpt('service_name', + help=_('The name of the nova service in the keystone catalog')) +] + +neutron_opts = [ + cfg.StrOpt('service_name', + help=_('The name of the neutron service in the ' + 'keystone catalog')) +] + # Register the configuration options cfg.CONF.register_opts(core_opts) cfg.CONF.register_opts(amphora_agent_opts, group='amphora_agent') @@ -360,6 +371,8 @@ cfg.CONF.register_cli_opts(healthmanager_opts, group='health_manager') cfg.CONF.import_group('keystone_authtoken', 'keystonemiddleware.auth_token') cfg.CONF.register_opts(keystone_authtoken_v3_opts, group='keystone_authtoken_v3') +cfg.CONF.register_opts(nova_opts, group='nova') +cfg.CONF.register_opts(neutron_opts, group='neutron') # Ensure that the control exchange is set correctly diff --git a/octavia/network/drivers/neutron/allowed_address_pairs.py b/octavia/network/drivers/neutron/allowed_address_pairs.py index 9fadbe575a..36cdc656d9 100644 --- a/octavia/network/drivers/neutron/allowed_address_pairs.py +++ b/octavia/network/drivers/neutron/allowed_address_pairs.py @@ -40,7 +40,7 @@ class AllowedAddressPairsDriver(neutron_base.BaseNeutronDriver): super(AllowedAddressPairsDriver, self).__init__() self._check_aap_loaded() self.nova_client = clients.NovaAuth.get_nova_client( - cfg.CONF.os_region_name + cfg.CONF.os_region_name, service_name=cfg.CONF.nova.service_name ) def _check_aap_loaded(self): diff --git a/octavia/network/drivers/neutron/base.py b/octavia/network/drivers/neutron/base.py index b5a4e11129..3ed4059055 100644 --- a/octavia/network/drivers/neutron/base.py +++ b/octavia/network/drivers/neutron/base.py @@ -33,7 +33,7 @@ class BaseNeutronDriver(base.AbstractNetworkDriver): def __init__(self): self.sec_grp_enabled = True self.neutron_client = clients.NeutronAuth.get_neutron_client( - cfg.CONF.os_region_name + cfg.CONF.os_region_name, service_name=cfg.CONF.neutron.service_name ) extensions = self.neutron_client.list_extensions() self._extensions = extensions.get('extensions') diff --git a/octavia/tests/unit/common/test_clients.py b/octavia/tests/unit/common/test_clients.py index bfc5a3cead..0e776c39c4 100644 --- a/octavia/tests/unit/common/test_clients.py +++ b/octavia/tests/unit/common/test_clients.py @@ -55,7 +55,7 @@ class TestNovaAuth(base.TestCase): # Getting the session again should return the same object bc2 = clients.NovaAuth.get_nova_client( - region="test-region") + region="test-region", service_name='novaEndpoint1') self.assertIs(bc1, bc2) @@ -92,5 +92,5 @@ class TestNeutronAuth(base.TestCase): # Getting the session again should return the same object bc2 = clients.NeutronAuth.get_neutron_client( - region="test-region") + region="test-region", service_name="neutronEndpoint1") self.assertIs(bc1, bc2)