Merge "Add octavia client plugin and constraints"

This commit is contained in:
Zuul 2018-01-04 10:03:23 +00:00 committed by Gerrit Code Review
commit 9762cdf205
4 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,98 @@
#
# 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.
from octaviaclient.api import constants
from octaviaclient.api.v2 import octavia
from osc_lib import exceptions
from heat.engine.clients import client_plugin
from heat.engine import constraints
CLIENT_NAME = 'octavia'
DEFAULT_FIND_ATTR = 'name'
def _is_translated_exception(ex, code):
return (isinstance(ex, octavia.OctaviaClientException)
and ex.code == code)
class OctaviaClientPlugin(client_plugin.ClientPlugin):
exceptions_module = octavia
service_types = [LOADBALANCER] = ['load-balancer']
supported_versions = [V2] = ['2']
default_version = V2
def _create(self, version=None):
interface = self._get_client_option(CLIENT_NAME, 'endpoint_type')
endpoint = self.url_for(service_type=self.LOADBALANCER,
endpoint_type=interface)
return octavia.OctaviaAPI(
session=self.context.keystone_session,
service_type=self.LOADBALANCER,
endpoint=endpoint)
def is_not_found(self, ex):
return isinstance(
ex, exceptions.NotFound) or _is_translated_exception(ex, 404)
def is_over_limit(self, ex):
return isinstance(
ex, exceptions.OverLimit) or _is_translated_exception(ex, 413)
def is_conflict(self, ex):
return isinstance(
ex, exceptions.Conflict) or _is_translated_exception(ex, 409)
def get_pool(self, value):
pool = self.client().find(path=constants.BASE_POOL_URL,
value=value, attr=DEFAULT_FIND_ATTR)
return pool['id']
def get_listener(self, value):
lsnr = self.client().find(path=constants.BASE_LISTENER_URL,
value=value, attr=DEFAULT_FIND_ATTR)
return lsnr['id']
def get_loadbalancer(self, value):
lb = self.client().find(path=constants.BASE_LOADBALANCER_URL,
value=value, attr=DEFAULT_FIND_ATTR)
return lb['id']
class OctaviaConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exceptions.NotFound,
octavia.OctaviaClientException)
base_url = None
def validate_with_client(self, client, value):
octavia_client = client.client(CLIENT_NAME)
octavia_client.find(path=self.base_url, value=value,
attr=DEFAULT_FIND_ATTR)
class LoadbalancerConstraint(OctaviaConstraint):
base_url = constants.BASE_LOADBALANCER_URL
class ListenerConstraint(OctaviaConstraint):
base_url = constants.BASE_LISTENER_URL
class PoolConstraint(OctaviaConstraint):
base_url = constants.BASE_POOL_URL

View File

@ -0,0 +1,24 @@
#
# 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.
from heat.tests import common
from heat.tests import utils
class OctaviaClientPluginTest(common.HeatTestCase):
def test_create(self):
context = utils.dummy_context()
plugin = context.clients.client_plugin('octavia')
client = plugin.client()
self.assertIsNotNone(client.endpoint)

View File

@ -44,6 +44,7 @@ python-mistralclient>=3.1.0 # Apache-2.0
python-monascaclient>=1.7.0 # Apache-2.0
python-neutronclient>=6.3.0 # Apache-2.0
python-novaclient>=9.1.0 # Apache-2.0
python-octaviaclient>=1.0.0 # Apache-2.0
python-openstackclient>=3.12.0 # Apache-2.0
python-saharaclient>=1.4.0 # Apache-2.0
python-senlinclient>=1.1.0 # Apache-2.0

View File

@ -79,6 +79,7 @@ heat.clients =
monasca = heat.engine.clients.os.monasca:MonascaClientPlugin
nova = heat.engine.clients.os.nova:NovaClientPlugin
neutron = heat.engine.clients.os.neutron:NeutronClientPlugin
octavia = heat.engine.clients.os.octavia:OctaviaClientPlugin
openstack = heat.engine.clients.os.openstacksdk:OpenStackSDKPlugin
sahara = heat.engine.clients.os.sahara:SaharaClientPlugin
senlin = heat.engine.clients.os.senlin:SenlinClientPlugin
@ -147,6 +148,9 @@ heat.constraints =
nova.keypair = heat.engine.clients.os.nova:KeypairConstraint
nova.network = heat.engine.constraint.common_constraints:TestConstraintDelay
nova.server = heat.engine.clients.os.nova:ServerConstraint
octavia.listener = heat.engine.clients.os.octavia:ListenerConstraint
octavia.loadbalancer = heat.engine.clients.os.octavia:LoadbalancerConstraint
octavia.pool = heat.engine.clients.os.octavia:PoolConstraint
sahara.cluster = heat.engine.clients.os.sahara:ClusterConstraint
sahara.cluster_template = heat.engine.clients.os.sahara:ClusterTemplateConstraint
sahara.data_source = heat.engine.clients.os.sahara:DataSourceConstraint