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
This commit is contained in:
enthurohini 2016-01-12 00:56:34 +05:30
parent 0691ecf8be
commit 534b108504
7 changed files with 96 additions and 0 deletions

View File

View File

@ -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='<application-catalog-api-version>',
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

View File

View File

@ -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')

View File

@ -0,0 +1,4 @@
---
features:
- Added python-muranoclient support in openstack-client by setting entry
points and implementing interface functions.

View File

@ -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

View File

@ -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