From 4e07d277d2a27ef027d8e7642ad03133f47ce31b Mon Sep 17 00:00:00 2001 From: Tetiana Lashchova Date: Tue, 30 Dec 2014 15:33:39 +0200 Subject: [PATCH] Add Mistral client plugin Change-Id: I9593e7a13d630ad4aa166dd1cdc88abd9b8eaf67 Implements: partial blueprint mistral-resources-for-heat --- contrib/heat_mistral/README.md | 18 +++++++ contrib/heat_mistral/heat_mistral/__init__.py | 0 contrib/heat_mistral/heat_mistral/client.py | 47 +++++++++++++++++++ contrib/heat_mistral/requirements.txt | 1 + contrib/heat_mistral/setup.cfg | 34 ++++++++++++++ contrib/heat_mistral/setup.py | 29 ++++++++++++ 6 files changed, 129 insertions(+) create mode 100644 contrib/heat_mistral/README.md create mode 100644 contrib/heat_mistral/heat_mistral/__init__.py create mode 100644 contrib/heat_mistral/heat_mistral/client.py create mode 100644 contrib/heat_mistral/requirements.txt create mode 100644 contrib/heat_mistral/setup.cfg create mode 100644 contrib/heat_mistral/setup.py diff --git a/contrib/heat_mistral/README.md b/contrib/heat_mistral/README.md new file mode 100644 index 000000000..61c5bdfde --- /dev/null +++ b/contrib/heat_mistral/README.md @@ -0,0 +1,18 @@ +Mistral plugin for OpenStack Heat +================================ + +This plugin enables using Mistral resources in a Heat template. + + +### 1. Install the Mistral plugin in Heat + +NOTE: These instructions assume the value of heat.conf plugin_dirs includes the +default directory /usr/lib/heat. + +To install the plugin, from this directory run: + sudo python ./setup.py install + +### 2. Restart heat + +Only the process "heat-engine" needs to be restarted to load the newly installed +plugin. diff --git a/contrib/heat_mistral/heat_mistral/__init__.py b/contrib/heat_mistral/heat_mistral/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/contrib/heat_mistral/heat_mistral/client.py b/contrib/heat_mistral/heat_mistral/client.py new file mode 100644 index 000000000..b3a893b49 --- /dev/null +++ b/contrib/heat_mistral/heat_mistral/client.py @@ -0,0 +1,47 @@ +# +# 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 oslo.utils import importutils + +from heat.engine.clients import client_plugin + +mistral_base = importutils.try_import('mistralclient.api.base') +mistral_client = importutils.try_import('mistralclient.api.client') + + +class MistralClientPlugin(client_plugin.ClientPlugin): + + def _create(self): + endpoint_type = self._get_client_option('mistral', 'endpoint_type') + endpoint = self.url_for(service_type='workflowv2', + endpoint_type=endpoint_type) + + args = { + 'mistral_url': endpoint, + 'auth_token': self.auth_token + } + + client = mistral_client.client(**args) + return client + + def is_not_found(self, ex): + return (isinstance(ex, mistral_base.APIException) and + ex.error_code == 404) + + def is_over_limit(self, ex): + return (isinstance(ex, mistral_base.APIException) and + ex.error_code == 413) + + def is_conflict(self, ex): + return (isinstance(ex, mistral_base.APIException) and + ex.error_code == 409) diff --git a/contrib/heat_mistral/requirements.txt b/contrib/heat_mistral/requirements.txt new file mode 100644 index 000000000..60e8a9527 --- /dev/null +++ b/contrib/heat_mistral/requirements.txt @@ -0,0 +1 @@ +python-mistralclient diff --git a/contrib/heat_mistral/setup.cfg b/contrib/heat_mistral/setup.cfg new file mode 100644 index 000000000..7862b51d7 --- /dev/null +++ b/contrib/heat_mistral/setup.cfg @@ -0,0 +1,34 @@ +[metadata] +name = heat-contrib-mistral +summary = Heat resources for Mistral +description-file = + README.md +author = OpenStack +author-email = openstack-dev@lists.openstack.org +home-page = http://www.openstack.org/ +classifier = + Environment :: OpenStack + Intended Audience :: Information Technology + Intended Audience :: System Administrators + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 2.6 + +[files] +packages = + heat_mistral + +# Copy to /usr/lib/heat for plugin loading +data_files = + lib/heat/mistral = heat_mistral/resources/* + +[entry_points] +heat.clients = + mistral = heat_mistral.client:MistralClientPlugin + +[global] +setup-hooks = + pbr.hooks.setup_hook diff --git a/contrib/heat_mistral/setup.py b/contrib/heat_mistral/setup.py new file mode 100644 index 000000000..62f38a592 --- /dev/null +++ b/contrib/heat_mistral/setup.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# +# 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. + +# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT +import setuptools + +# In python < 2.7.4, a lazy loading of package `pbr` will break +# setuptools if some other modules registered functions in `atexit`. +# solution from: http://bugs.python.org/issue15881#msg170215 +try: + import multiprocessing # noqa +except ImportError: + pass + +setuptools.setup( + setup_requires=['pbr'], + pbr=True)