diff --git a/masakariclient/osc/__init__.py b/masakariclient/osc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/masakariclient/osc/v1/__init__.py b/masakariclient/osc/v1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/masakariclient/plugin.py b/masakariclient/plugin.py new file mode 100644 index 0000000..9fec4ee --- /dev/null +++ b/masakariclient/plugin.py @@ -0,0 +1,61 @@ +# Copyright(c) 2016 Nippon Telegraph and Telephone Corporation +# +# 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 logging + +from openstack import connection +from openstack import profile +from osc_lib import utils + +from masakariclient.sdk.vmha import vmha_service + + +LOG = logging.getLogger(__name__) + +DEFAULT_VMHA_API_VERSION = '1' +API_VERSION_OPTION = 'os_vmha_api_version' +API_NAME = 'vmha' +API_VERSIONS = { + '1': 'masakariclient.client.Client', +} + + +def make_client(instance): + """Returns a vmha proxy""" + prof = profile.Profile() + prof._add_service(vmha_service.VMHAService(version="v1")) + prof.set_region(API_NAME, instance.region_name) + prof.set_version(API_NAME, instance._api_version[API_NAME]) + prof.set_interface(API_NAME, instance.interface) + conn = connection.Connection(authenticator=instance.session.auth, + verify=instance.session.verify, + cert=instance.session.cert, + profile=prof) + LOG.debug('Connection: %s', conn) + LOG.debug('masakari client initialized: %s', conn.vmha) + return conn.vmha + + +def build_option_parser(parser): + """Hook to add global options""" + parser.add_argument( + '--os-vmha-api-version', + metavar='', + default=utils.env( + 'OS_VMHA_API_VERSION', + default=DEFAULT_VMHA_API_VERSION), + help='vmha API version, default=' + + DEFAULT_VMHA_API_VERSION + + ' (Env: OS_VMHA_API_VERSION)') + return parser diff --git a/requirements.txt b/requirements.txt index 3b1bdab..cfb2d3a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,6 @@ # process, which may cause wedges in the gate later. openstacksdk>=0.9.7 # Apache-2.0 +osc-lib>=1.2.0 # Apache-2.0 oslo.i18n>=2.1.0 # Apache-2.0 pbr>=1.6 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 5c388ad..c547348 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,6 +23,10 @@ classifier = packages = masakariclient +[entry_points] +openstack.cli.extension = + vmha = masakariclient.plugin + [build_sphinx] source-dir = doc/source build-dir = doc/build @@ -48,4 +52,4 @@ output_file = masakariclient/locale/masakariclient.pot [build_releasenotes] all_files = 1 build-dir = releasenotes/build -source-dir = releasenotes/source \ No newline at end of file +source-dir = releasenotes/source