Add endpoint override conf option for neutron and nova

In some implementations overriding the neutron and/or nova endpoint returned in
the keystone catalog will be necessary.  Adding this will allow that to happen.

Change-Id: I66a9ed82a895b9fe282ef7b2c4bdfb954af0cc0c
changes/37/275337/5
Trevor Vardeman 7 years ago
parent 6f786fdad7
commit 240931610f
  1. 6
      etc/octavia.conf
  2. 16
      octavia/common/clients.py
  3. 8
      octavia/common/config.py
  4. 3
      octavia/compute/drivers/nova_driver.py
  5. 4
      octavia/network/drivers/neutron/allowed_address_pairs.py
  6. 5
      octavia/network/drivers/neutron/base.py
  7. 6
      octavia/tests/unit/common/test_clients.py

@ -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 =
# service_name =
# Custom neutron endpoint if override is necessary
# endpoint =

@ -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."))

@ -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

@ -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,

@ -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]

@ -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()

@ -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)

Loading…
Cancel
Save