From 9a6698fb4535e408b6c4a522088197af0ab4aa4d Mon Sep 17 00:00:00 2001 From: Jim Bach Date: Mon, 5 Nov 2018 07:57:58 -0800 Subject: [PATCH] Add Octavia python client for Magnum Adding the client enables the manipulation of Octavia resources with Magnum such as during cluster deletion, being able to clean up non-heat created resouces. Change-Id: I976ab136e24b98d447d61028ce07d0f5dd9d255a story: 2004259 task: 27795 --- lower-constraints.txt | 1 + magnum/common/clients.py | 17 ++++++ magnum/conf/__init__.py | 2 + magnum/conf/octavia.py | 58 +++++++++++++++++++ .../add-octavia-client-4e5520084eae3c2b.yaml | 5 ++ requirements.txt | 1 + 6 files changed, 84 insertions(+) create mode 100644 magnum/conf/octavia.py create mode 100644 releasenotes/notes/add-octavia-client-4e5520084eae3c2b.yaml diff --git a/lower-constraints.txt b/lower-constraints.txt index a6a3d89bc9..729117b8b5 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -121,6 +121,7 @@ python-keystoneclient==3.8.0 python-mimeparse==1.6.0 python-neutronclient==6.7.0 python-novaclient==9.1.0 +python-octaviaclient==1.6.0 python-subunit==1.0.0 python-swiftclient==3.5.0 pytz==2013.6 diff --git a/magnum/common/clients.py b/magnum/common/clients.py index bd69f2bd00..3fdda431e3 100644 --- a/magnum/common/clients.py +++ b/magnum/common/clients.py @@ -18,6 +18,7 @@ from heatclient import client as heatclient from keystoneauth1.exceptions import catalog from neutronclient.v2_0 import client as neutronclient from novaclient import client as novaclient +from octaviaclient.api.v2 import octavia from oslo_log import log as logging from magnum.common import exception @@ -39,6 +40,7 @@ class OpenStackClients(object): self._barbican = None self._nova = None self._neutron = None + self._octavia = None def url_for(self, **kwargs): return self.keystone().session.get_endpoint(**kwargs) @@ -80,6 +82,21 @@ class OpenStackClients(object): def _get_client_option(self, client, option): return getattr(getattr(CONF, '%s_client' % client), option) + @exception.wrap_keystone_exception + def octavia(self): + if self._octavia: + return self._octavia + + region_name = self._get_client_option('octavia', 'region_name') + endpoint_type = self._get_client_option('octavia', 'endpoint_type') + endpoint = self.url_for(service_type='load-balancer', + interface=endpoint_type, + region_name=region_name) + session = self.keystone().session + return octavia.OctaviaAPI(session=session, + service_type='load-balancer', + endpoint=endpoint) + @exception.wrap_keystone_exception def heat(self): if self._heat: diff --git a/magnum/conf/__init__.py b/magnum/conf/__init__.py index 6f9f4e23cc..1d1612eaa6 100644 --- a/magnum/conf/__init__.py +++ b/magnum/conf/__init__.py @@ -33,6 +33,7 @@ from magnum.conf import keystone from magnum.conf import magnum_client from magnum.conf import neutron from magnum.conf import nova +from magnum.conf import octavia from magnum.conf import paths from magnum.conf import profiler from magnum.conf import quota @@ -62,6 +63,7 @@ keystone.register_opts(CONF) magnum_client.register_opts(CONF) neutron.register_opts(CONF) nova.register_opts(CONF) +octavia.register_opts(CONF) paths.register_opts(CONF) quota.register_opts(CONF) rpc.register_opts(CONF) diff --git a/magnum/conf/octavia.py b/magnum/conf/octavia.py new file mode 100644 index 0000000000..db7d7f4589 --- /dev/null +++ b/magnum/conf/octavia.py @@ -0,0 +1,58 @@ +# 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. + +import itertools + +from oslo_config import cfg + +from magnum.i18n import _ + +octavia_group = cfg.OptGroup(name='octavia_client', + title='Options for the Octavia client') + +octavia_client_opts = [ + cfg.StrOpt('region_name', + help=_('Region in Identity service catalog to use for ' + 'communication with the OpenStack service.')), + cfg.StrOpt('endpoint_type', + default='publicURL', + help=_('Type of endpoint in Identity service catalog to use ' + 'for communication with the OpenStack service.'))] + +common_security_opts = [ + cfg.StrOpt('ca_file', + help=_('Optional CA cert file to use in SSL connections.')), + cfg.StrOpt('cert_file', + help=_('Optional PEM-formatted certificate chain file.')), + cfg.StrOpt('key_file', + help=_('Optional PEM-formatted file that contains the ' + 'private key.')), + cfg.BoolOpt('insecure', + default=False, + help=_("If set, then the server's certificate will not " + "be verified."))] + +ALL_OPTS = list(itertools.chain( + octavia_client_opts, + common_security_opts +)) + + +def register_opts(conf): + conf.register_group(octavia_group) + conf.register_opts(ALL_OPTS, group=octavia_group) + + +def list_opts(): + return { + octavia_group: ALL_OPTS + } diff --git a/releasenotes/notes/add-octavia-client-4e5520084eae3c2b.yaml b/releasenotes/notes/add-octavia-client-4e5520084eae3c2b.yaml new file mode 100644 index 0000000000..738dc4ad3e --- /dev/null +++ b/releasenotes/notes/add-octavia-client-4e5520084eae3c2b.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + This will add the octavia client code for client to interact with + the Octavia component of OpenStack diff --git a/requirements.txt b/requirements.txt index 0e5ffaaf04..cf3eff2926 100644 --- a/requirements.txt +++ b/requirements.txt @@ -46,6 +46,7 @@ python-heatclient>=1.10.0 # Apache-2.0 python-neutronclient>=6.7.0 # Apache-2.0 python-novaclient>=9.1.0 # Apache-2.0 python-keystoneclient>=3.8.0 # Apache-2.0 +python-octaviaclient>=1.6.0 # Apache-2.0 requests>=2.14.2 # Apache-2.0 setuptools!=24.0.0,!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,!=36.2.0,>=21.0.0 # PSF/ZPL six>=1.10.0 # MIT