From f4c213519ed16724a40fa5b8a23ab6760c1ce096 Mon Sep 17 00:00:00 2001 From: AleptNmarata Date: Sat, 4 Feb 2017 12:26:52 +0000 Subject: [PATCH] Implement Zun client plugin Co-Authored-By: Hongbin Lu Partial Implements:blueprint heat-plugin-zun Change-Id: Icedc709222f04d52769bbe95a34a0178c01a44e0 --- heat/engine/clients/os/zun.py | 45 +++++++++++++++++++ heat/tests/clients/test_zun_client.py | 24 ++++++++++ ...dd-zun-client-plugin-dfc10ecd1a6e98be.yaml | 5 +++ requirements.txt | 1 + setup.cfg | 1 + 5 files changed, 76 insertions(+) create mode 100644 heat/engine/clients/os/zun.py create mode 100644 heat/tests/clients/test_zun_client.py create mode 100644 releasenotes/notes/add-zun-client-plugin-dfc10ecd1a6e98be.yaml diff --git a/heat/engine/clients/os/zun.py b/heat/engine/clients/os/zun.py new file mode 100644 index 0000000000..bb9287a695 --- /dev/null +++ b/heat/engine/clients/os/zun.py @@ -0,0 +1,45 @@ +# +# 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 zunclient import exceptions as zc_exc +from zunclient.v1 import client as zun_client + +from heat.engine.clients import client_plugin + +CLIENT_NAME = 'zun' + + +class ZunClientPlugin(client_plugin.ClientPlugin): + + service_types = [CONTAINER] = ['container'] + + def _create(self): + interface = self._get_client_option(CLIENT_NAME, 'endpoint_type') + args = { + 'interface': interface, + 'service_type': self.CONTAINER, + 'session': self.context.keystone_session, + 'region_name': self._get_region_name() + } + + client = zun_client.Client(**args) + return client + + def is_not_found(self, ex): + return isinstance(ex, zc_exc.NotFound) + + def is_over_limit(self, ex): + return isinstance(ex, zc_exc.RequestEntityTooLarge) + + def is_conflict(self, ex): + return isinstance(ex, zc_exc.Conflict) diff --git a/heat/tests/clients/test_zun_client.py b/heat/tests/clients/test_zun_client.py new file mode 100644 index 0000000000..28b7124f30 --- /dev/null +++ b/heat/tests/clients/test_zun_client.py @@ -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 ZunClientPluginTest(common.HeatTestCase): + + def test_create(self): + context = utils.dummy_context() + plugin = context.clients.client_plugin('zun') + client = plugin.client() + self.assertEqual('http://server.test:5000/v3', + client.containers.api.session.auth.endpoint) diff --git a/releasenotes/notes/add-zun-client-plugin-dfc10ecd1a6e98be.yaml b/releasenotes/notes/add-zun-client-plugin-dfc10ecd1a6e98be.yaml new file mode 100644 index 0000000000..3ddcfe89e6 --- /dev/null +++ b/releasenotes/notes/add-zun-client-plugin-dfc10ecd1a6e98be.yaml @@ -0,0 +1,5 @@ +--- +other: + - | + Introduce a Zun client plugin module that will be used by the + Zun's resources that are under development. diff --git a/requirements.txt b/requirements.txt index 9d5bea8326..fa8cc59080 100644 --- a/requirements.txt +++ b/requirements.txt @@ -51,6 +51,7 @@ python-senlinclient>=1.1.0 # Apache-2.0 python-swiftclient>=3.2.0 # Apache-2.0 python-troveclient>=2.2.0 # Apache-2.0 python-zaqarclient>=1.0.0 # Apache-2.0 +python-zunclient>=0.1.0 # Apache-2.0 pytz>=2013.6 # MIT PyYAML>=3.10.0 # MIT requests!=2.12.2,!=2.13.0,>=2.10.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 29b01cdfbd..115e4b19a7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -78,6 +78,7 @@ heat.clients = swift = heat.engine.clients.os.swift:SwiftClientPlugin trove = heat.engine.clients.os.trove:TroveClientPlugin zaqar = heat.engine.clients.os.zaqar:ZaqarClientPlugin + zun = heat.engine.clients.os.zun:ZunClientPlugin heat.constraints = # common constraints