From 534b10850424d38512b4582941a8e28be6d1006c Mon Sep 17 00:00:00 2001 From: enthurohini Date: Tue, 12 Jan 2016 00:56:34 +0530 Subject: [PATCH] Initial commit for openstack-client support in python-muranoclient This patch enables openstack-client support in python-muranoclient by setting entry points and implementing two interface functions `make_client(instance)` and `build_option_parser(parser)`. Change-Id: I9bd9b9718377e1eb7324d19ee7b0292f18eb22d5 Partially implements: blueprint openstack-client-plugin-support --- muranoclient/osc/__init__.py | 0 muranoclient/osc/plugin.py | 56 +++++++++++++++++++ muranoclient/tests/unit/osc/__init__.py | 0 muranoclient/tests/unit/osc/test_plugin.py | 32 +++++++++++ ...stack-client-support-a273e33d6c31e36e.yaml | 4 ++ requirements.txt | 1 + setup.cfg | 3 + 7 files changed, 96 insertions(+) create mode 100644 muranoclient/osc/__init__.py create mode 100644 muranoclient/osc/plugin.py create mode 100644 muranoclient/tests/unit/osc/__init__.py create mode 100644 muranoclient/tests/unit/osc/test_plugin.py create mode 100644 releasenotes/notes/enable-openstack-client-support-a273e33d6c31e36e.yaml diff --git a/muranoclient/osc/__init__.py b/muranoclient/osc/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/muranoclient/osc/plugin.py b/muranoclient/osc/plugin.py new file mode 100644 index 00000000..963a5add --- /dev/null +++ b/muranoclient/osc/plugin.py @@ -0,0 +1,56 @@ +# 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 openstackclient.common import utils +from oslo_log import log as logging + +from muranoclient.i18n import _ + +LOG = logging.getLogger(__name__) + +DEFAULT_APPLICATION_CATALOG_API_VERSION = "1" +API_VERSION_OPTION = "os_application_catalog_api_version" +API_NAME = "application_catalog" +API_VERSIONS = { + '1': 'muranoclient.v1.client.Client', +} + + +def make_client(instance): + """Returns an application-catalog service client""" + application_catalog_client = utils.get_client_class( + API_NAME, + instance._api_version[API_NAME], + API_VERSIONS) + LOG.debug("Instantiating application-catalog client: {0}".format( + application_catalog_client)) + + client = application_catalog_client( + region_name=instance._region_name, + session=instance.session, + service_type='application-catalog', + ) + return client + + +def build_option_parser(parser): + """Hook to add global options""" + parser.add_argument( + '--os-application-catalog-api-version', + metavar='', + default=utils.env( + 'OS_APPLICATION_CATALOG_API_VERSION', + default=DEFAULT_APPLICATION_CATALOG_API_VERSION), + help=_("Application catalog API version, default={0}" + "(Env:OS_APPLICATION_CATALOG_API_VERSION)").format( + DEFAULT_APPLICATION_CATALOG_API_VERSION)) + return parser diff --git a/muranoclient/tests/unit/osc/__init__.py b/muranoclient/tests/unit/osc/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/muranoclient/tests/unit/osc/test_plugin.py b/muranoclient/tests/unit/osc/test_plugin.py new file mode 100644 index 00000000..56165acb --- /dev/null +++ b/muranoclient/tests/unit/osc/test_plugin.py @@ -0,0 +1,32 @@ +# 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 mock + +from muranoclient.osc import plugin +from muranoclient.tests.unit import base + + +class TestApplicationCatalogPlugin(base.TestCaseShell): + + @mock.patch("muranoclient.v1.client.Client") + def test_make_client(self, p_client): + + instance = mock.Mock() + instance._api_version = {"application_catalog": '1'} + instance._region_name = 'murano_region' + instance.session = 'murano_session' + + plugin.make_client(instance) + p_client.assert_called_with(region_name='murano_region', + session='murano_session', + service_type='application-catalog') diff --git a/releasenotes/notes/enable-openstack-client-support-a273e33d6c31e36e.yaml b/releasenotes/notes/enable-openstack-client-support-a273e33d6c31e36e.yaml new file mode 100644 index 00000000..bde8d27c --- /dev/null +++ b/releasenotes/notes/enable-openstack-client-support-a273e33d6c31e36e.yaml @@ -0,0 +1,4 @@ +--- +features: + - Added python-muranoclient support in openstack-client by setting entry + points and implementing interface functions. diff --git a/requirements.txt b/requirements.txt index 8d2af51e..8083d61f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ pbr>=1.6 # Apache-2.0 PrettyTable<0.8,>=0.7 # BSD python-glanceclient>=1.2.0 # Apache-2.0 python-keystoneclient!=1.8.0,!=2.1.0,>=1.6.0 # Apache-2.0 +python-openstackclient>=2.0.0 # Apache-2.0 httplib2>=0.7.5 # MIT iso8601>=0.1.9 # MIT six>=1.9.0 # MIT diff --git a/setup.cfg b/setup.cfg index 90ce52c3..0d3730fd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,6 +30,9 @@ packages = console_scripts = murano = muranoclient.shell:main +openstack.cli.extension = + application_catalog = muranoclient.osc.plugin + [global] setup-hooks = pbr.hooks.setup_hook