diff --git a/etc/octavia.conf b/etc/octavia.conf index 7ebb136e4a..aaf2b376ac 100644 --- a/etc/octavia.conf +++ b/etc/octavia.conf @@ -207,7 +207,11 @@ [nova] # The name of the nova service in the keystone catalog # service_name = +# Custom nova endpoint if override is necessary +# endpoint = [neutron] # The name of the neutron service in the keystone catalog -# service_name = \ No newline at end of file +# service_name = +# Custom neutron endpoint if override is necessary +# endpoint = diff --git a/octavia/common/clients.py b/octavia/common/clients.py index 4297694cfb..d3dfe4d6df 100644 --- a/octavia/common/clients.py +++ b/octavia/common/clients.py @@ -27,11 +27,12 @@ class NovaAuth(object): nova_client = None @classmethod - def get_nova_client(cls, region, service_name=None): + def get_nova_client(cls, region, service_name=None, endpoint=None): """Create nova client object. :param region: The region of the service :param service_name: The name of the nova service in the catalog + :param endpoint: The endpoint of the service :return: a Nova Client object. :raises Exception: if the client cannot be created """ @@ -40,10 +41,11 @@ class NovaAuth(object): 'session': keystone.get_session()} if service_name: kwargs['service_name'] = service_name + if endpoint: + kwargs['endpoint_override'] = endpoint try: cls.nova_client = nova_client.Client( - NOVA_VERSION, **kwargs - ) + NOVA_VERSION, **kwargs) except Exception: with excutils.save_and_reraise_exception(): LOG.exception(_LE("Error creating Nova client.")) @@ -54,11 +56,12 @@ class NeutronAuth(object): neutron_client = None @classmethod - def get_neutron_client(cls, region, service_name=None): + def get_neutron_client(cls, region, service_name=None, endpoint=None): """Create neutron client object. :param region: The region of the service :param service_name: The name of the neutron service in the catalog + :param endpoint: The endpoint of the service :return: a Neutron Client object. :raises Exception: if the client cannot be created """ @@ -67,10 +70,11 @@ class NeutronAuth(object): 'session': keystone.get_session()} if service_name: kwargs['service_name'] = service_name + if endpoint: + kwargs['endpoint_override'] = endpoint try: cls.neutron_client = neutron_client.Client( - NEUTRON_VERSION, **kwargs - ) + NEUTRON_VERSION, **kwargs) except Exception: with excutils.save_and_reraise_exception(): LOG.exception(_LE("Error creating Neutron client.")) diff --git a/octavia/common/config.py b/octavia/common/config.py index 8fce08b66e..403890ebff 100644 --- a/octavia/common/config.py +++ b/octavia/common/config.py @@ -346,13 +346,17 @@ keepalived_vrrp_opts = [ nova_opts = [ cfg.StrOpt('service_name', - help=_('The name of the nova service in the keystone catalog')) + help=_('The name of the nova service in the keystone catalog')), + cfg.StrOpt('endpoint', help=_('A new endpoint to override the endpoint ' + 'in the keystone catalog.')) ] neutron_opts = [ cfg.StrOpt('service_name', help=_('The name of the neutron service in the ' - 'keystone catalog')) + 'keystone catalog')), + cfg.StrOpt('endpoint', help=_('A new endpoint to override the endpoint ' + 'in the keystone catalog.')) ] # Register the configuration options diff --git a/octavia/compute/drivers/nova_driver.py b/octavia/compute/drivers/nova_driver.py index 05ea8e7a21..fccb6fdb31 100644 --- a/octavia/compute/drivers/nova_driver.py +++ b/octavia/compute/drivers/nova_driver.py @@ -37,7 +37,8 @@ class VirtualMachineManager(compute_base.ComputeBase): super(VirtualMachineManager, self).__init__() # Must initialize nova api region = CONF.os_region_name - self._nova_client = clients.NovaAuth.get_nova_client(region) + self._nova_client = clients.NovaAuth.get_nova_client( + region, endpoint=CONF.nova.endpoint) self.manager = self._nova_client.servers def build(self, name="amphora_name", amphora_flavor=None, image_id=None, diff --git a/octavia/network/drivers/neutron/allowed_address_pairs.py b/octavia/network/drivers/neutron/allowed_address_pairs.py index 36cdc656d9..2462d5eb8b 100644 --- a/octavia/network/drivers/neutron/allowed_address_pairs.py +++ b/octavia/network/drivers/neutron/allowed_address_pairs.py @@ -40,8 +40,8 @@ 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, service_name=cfg.CONF.nova.service_name - ) + cfg.CONF.os_region_name, service_name=cfg.CONF.nova.service_name, + endpoint=cfg.CONF.nova.endpoint) def _check_aap_loaded(self): aliases = [ext.get('alias') for ext in self._extensions] diff --git a/octavia/network/drivers/neutron/base.py b/octavia/network/drivers/neutron/base.py index 3ed4059055..b8e5722da3 100644 --- a/octavia/network/drivers/neutron/base.py +++ b/octavia/network/drivers/neutron/base.py @@ -33,8 +33,9 @@ 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, service_name=cfg.CONF.neutron.service_name - ) + cfg.CONF.os_region_name, + service_name=cfg.CONF.neutron.service_name, + endpoint=cfg.CONF.neutron.endpoint) extensions = self.neutron_client.list_extensions() self._extensions = extensions.get('extensions') self._check_sec_grps() diff --git a/octavia/tests/unit/common/test_clients.py b/octavia/tests/unit/common/test_clients.py index 0e776c39c4..d896e2d2a4 100644 --- a/octavia/tests/unit/common/test_clients.py +++ b/octavia/tests/unit/common/test_clients.py @@ -55,7 +55,8 @@ class TestNovaAuth(base.TestCase): # Getting the session again should return the same object bc2 = clients.NovaAuth.get_nova_client( - region="test-region", service_name='novaEndpoint1') + region="test-region", service_name='novaEndpoint1', + endpoint="test-endpoint") self.assertIs(bc1, bc2) @@ -92,5 +93,6 @@ class TestNeutronAuth(base.TestCase): # Getting the session again should return the same object bc2 = clients.NeutronAuth.get_neutron_client( - region="test-region", service_name="neutronEndpoint1") + region="test-region", service_name="neutronEndpoint1", + endpoint="test-endpoint") self.assertIs(bc1, bc2)