Adapt the client for the v2 API
This adds a v2 client class allowing to add support for upcoming v2 API endpoints. The v2 client class implements all v1 endpoints. The cloudkitty API version can be specified with the "--os-rating-api-version" option or the "OS_RATING_API_VERSION" environment variable. Change-Id: If38730da3baed59c93543a08f8a4989f919611db
This commit is contained in:
parent
d77526b42e
commit
d2fb83e64c
|
@ -0,0 +1,44 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2018 Objectif Libre
|
||||
#
|
||||
# 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 keystoneauth1 import adapter
|
||||
from keystoneauth1 import session as ks_session
|
||||
|
||||
|
||||
class BaseClient(object):
|
||||
|
||||
def __init__(self,
|
||||
session=None,
|
||||
adapter_options={},
|
||||
cacert=None,
|
||||
insecure=False,
|
||||
**kwargs):
|
||||
adapter_options.setdefault('service_type', 'rating')
|
||||
|
||||
if insecure:
|
||||
verify_cert = False
|
||||
else:
|
||||
if cacert:
|
||||
verify_cert = cacert
|
||||
else:
|
||||
verify_cert = True
|
||||
|
||||
self.session = session
|
||||
if self.session is None:
|
||||
self.session = ks_session.Session(
|
||||
verify=verify_cert, **kwargs)
|
||||
|
||||
self.api_client = adapter.Adapter(
|
||||
session=self.session, **adapter_options)
|
|
@ -14,11 +14,12 @@
|
|||
|
||||
from osc_lib import utils
|
||||
|
||||
DEFAULT_API_VERSION = '1'
|
||||
DEFAULT_API_VERSION = '2'
|
||||
API_VERSION_OPTION = 'os_rating_api_version'
|
||||
API_NAME = "rating"
|
||||
API_VERSIONS = {
|
||||
"1": "cloudkittyclient.v1.client.Client",
|
||||
"2": "cloudkittyclient.v2.client.Client",
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,4 +41,9 @@ def make_client(instance):
|
|||
|
||||
def build_option_parser(parser):
|
||||
"""Hook to add global options."""
|
||||
parser.add_argument(
|
||||
'--rating-api-version', type=int, default=utils.env(
|
||||
'OS_RATING_API_VERSION',
|
||||
default=DEFAULT_API_VERSION)
|
||||
)
|
||||
return parser
|
||||
|
|
|
@ -22,6 +22,7 @@ import os_client_config
|
|||
from oslo_log import log
|
||||
|
||||
from cloudkittyclient import client
|
||||
from cloudkittyclient.osc import DEFAULT_API_VERSION
|
||||
from cloudkittyclient import utils
|
||||
|
||||
|
||||
|
@ -105,9 +106,6 @@ class CloudKittyShell(cliff.app.App):
|
|||
description,
|
||||
version,
|
||||
argparse_kwargs={'allow_abbrev': False})
|
||||
parser.add_argument(
|
||||
'--ck-api-version', type=int, default=1, dest='ck_version',
|
||||
help='Cloudkitty API version (defaults to 1)')
|
||||
if 'OS_AUTH_TYPE' not in os.environ.keys() \
|
||||
and 'OS_PASSWORD' in os.environ.keys():
|
||||
os.environ['OS_AUTH_TYPE'] = 'password'
|
||||
|
@ -133,9 +131,10 @@ class CloudKittyShell(cliff.app.App):
|
|||
self.options.os_rating_endpoint_override or
|
||||
self.options.os_endpoint_override),
|
||||
)
|
||||
self._client = client.Client(str(self.options.ck_version),
|
||||
session=session,
|
||||
adapter_options=adapter_options)
|
||||
self._client = client.Client(
|
||||
str(self.options.os_rating_api_version or DEFAULT_API_VERSION),
|
||||
session=session,
|
||||
adapter_options=adapter_options)
|
||||
return self._client
|
||||
|
||||
|
||||
|
|
|
@ -13,9 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
from keystoneauth1 import adapter
|
||||
from keystoneauth1 import session as ks_session
|
||||
|
||||
from cloudkittyclient.common import client
|
||||
from cloudkittyclient.v1 import collector
|
||||
from cloudkittyclient.v1 import info
|
||||
from cloudkittyclient.v1 import rating
|
||||
|
@ -23,7 +21,7 @@ from cloudkittyclient.v1 import report
|
|||
from cloudkittyclient.v1 import storage
|
||||
|
||||
|
||||
class Client(object):
|
||||
class Client(client.BaseClient):
|
||||
|
||||
def __init__(self,
|
||||
session=None,
|
||||
|
@ -31,23 +29,14 @@ class Client(object):
|
|||
cacert=None,
|
||||
insecure=False,
|
||||
**kwargs):
|
||||
adapter_options.setdefault('service_type', 'rating')
|
||||
super(Client, self).__init__(
|
||||
session=session,
|
||||
adapter_options=adapter_options,
|
||||
cacert=cacert,
|
||||
insecure=insecure,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
if insecure:
|
||||
verify_cert = False
|
||||
else:
|
||||
if cacert:
|
||||
verify_cert = cacert
|
||||
else:
|
||||
verify_cert = True
|
||||
|
||||
self.session = session
|
||||
if self.session is None:
|
||||
self.session = ks_session.Session(
|
||||
verify=verify_cert, **kwargs)
|
||||
|
||||
self.api_client = adapter.Adapter(
|
||||
session=self.session, **adapter_options)
|
||||
self.info = info.InfoManager(self.api_client)
|
||||
self.collector = collector.CollectorManager(self.api_client)
|
||||
self.rating = rating.RatingManager(self.api_client)
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
#
|
||||
from oslo_log import log
|
||||
|
||||
from cloudkittyclient.common import base
|
||||
from cloudkittyclient import exc
|
||||
from cloudkittyclient.v1 import base
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
from cloudkittyclient.v1 import base
|
||||
from cloudkittyclient.common import base
|
||||
|
||||
|
||||
class InfoManager(base.BaseManager):
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
#
|
||||
from cliff import lister
|
||||
|
||||
from cloudkittyclient.common import base
|
||||
from cloudkittyclient import exc
|
||||
from cloudkittyclient import utils
|
||||
from cloudkittyclient.v1 import base
|
||||
from cloudkittyclient.v1.rating import hashmap
|
||||
from cloudkittyclient.v1.rating import pyscripts
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
from cloudkittyclient.common import base
|
||||
from cloudkittyclient import exc
|
||||
from cloudkittyclient.v1 import base
|
||||
|
||||
|
||||
class HashmapManager(base.BaseManager):
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
from cloudkittyclient.common import base
|
||||
from cloudkittyclient import exc
|
||||
from cloudkittyclient.v1 import base
|
||||
|
||||
|
||||
class PyscriptManager(base.BaseManager):
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#
|
||||
from oslo_log import log
|
||||
|
||||
from cloudkittyclient.v1 import base
|
||||
from cloudkittyclient.common import base
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
from cloudkittyclient.v1 import base
|
||||
from cloudkittyclient.common import base
|
||||
|
||||
|
||||
class StorageManager(base.BaseManager):
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2018 Objectif Libre
|
||||
#
|
||||
# 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 cloudkittyclient.v1 import client
|
||||
|
||||
|
||||
# NOTE(peschk_l) v2 client needs to implement v1 until the v1 API has been
|
||||
# completely ported to v2
|
||||
class Client(client.Client):
|
||||
|
||||
def __init__(self,
|
||||
session=None,
|
||||
adapter_options={},
|
||||
cacert=None,
|
||||
insecure=False,
|
||||
**kwargs):
|
||||
super(Client, self).__init__(
|
||||
session=session,
|
||||
adapter_options=adapter_options,
|
||||
cacert=cacert,
|
||||
insecure=insecure,
|
||||
**kwargs
|
||||
)
|
|
@ -8,6 +8,7 @@ PyYAML==3.12 # MIT
|
|||
jsonpath-rw-ext==1.0 # Apache-2.0
|
||||
six==1.11 # MIT
|
||||
os-client-config==1.29.0 # Apache-2.0
|
||||
osc-lib==1.12.1 # Apache-2.0
|
||||
|
||||
# test-requirements.txt
|
||||
coverage==4.0 # Apache-2.0
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
upgrade:
|
||||
- |
|
||||
The client has been adapted to allow adding support for v2 API
|
||||
endpoints. The v2 client class implements all v1 endpoints, but v1
|
||||
endpoints ported to v2 will be overriden. The API version to use can be
|
||||
specified through the ``--os-rating-api-version`` option or the
|
||||
``OS_RATING_API_VERSION``.
|
|
@ -11,3 +11,4 @@ PyYAML>=3.12 # MIT
|
|||
jsonpath-rw-ext>=1.0 # Apache-2.0
|
||||
six>=1.11 # MIT
|
||||
os-client-config>=1.29.0 # Apache-2.0
|
||||
osc-lib>=1.12.1 # Apache-2.0
|
||||
|
|
55
setup.cfg
55
setup.cfg
|
@ -84,6 +84,61 @@ openstack.rating.v1 =
|
|||
rating_pyscript_update = cloudkittyclient.v1.rating.pyscripts_cli:CliUpdateScript
|
||||
rating_pyscript_delete = cloudkittyclient.v1.rating.pyscripts_cli:CliDeleteScript
|
||||
|
||||
openstack.rating.v2 =
|
||||
rating_total_get = cloudkittyclient.v1.report_cli:CliTotalGet
|
||||
rating_summary_get = cloudkittyclient.v1.report_cli:CliSummaryGet
|
||||
rating_report_tenant_list = cloudkittyclient.v1.report_cli:CliTenantList
|
||||
|
||||
rating_module_get = cloudkittyclient.v1.rating:CliModuleGet
|
||||
rating_module_list = cloudkittyclient.v1.rating:CliModuleList
|
||||
rating_module_enable = cloudkittyclient.v1.rating:CliModuleEnable
|
||||
rating_module_disable = cloudkittyclient.v1.rating:CliModuleDisable
|
||||
rating_module_set_priority = cloudkittyclient.v1.rating:CliModuleSetPriority
|
||||
|
||||
rating_info_config_get = cloudkittyclient.v1.info_cli:CliInfoConfigGet
|
||||
rating_info_metric_get = cloudkittyclient.v1.info_cli:CliInfoMetricGet
|
||||
rating_info_metric_list = cloudkittyclient.v1.info_cli:CliInfoMetricList
|
||||
|
||||
rating_hashmap_mapping-types_list = cloudkittyclient.v1.rating.hashmap_cli:CliGetMappingTypes
|
||||
rating_hashmap_service_get = cloudkittyclient.v1.rating.hashmap_cli:CliGetService
|
||||
rating_hashmap_service_list = cloudkittyclient.v1.rating.hashmap_cli:CliListService
|
||||
rating_hashmap_service_create = cloudkittyclient.v1.rating.hashmap_cli:CliCreateService
|
||||
rating_hashmap_service_delete = cloudkittyclient.v1.rating.hashmap_cli:CliDeleteService
|
||||
rating_hashmap_field_get = cloudkittyclient.v1.rating.hashmap_cli:CliGetField
|
||||
rating_hashmap_field_list = cloudkittyclient.v1.rating.hashmap_cli:CliListField
|
||||
rating_hashmap_field_create = cloudkittyclient.v1.rating.hashmap_cli:CliCreateField
|
||||
rating_hashmap_field_delete = cloudkittyclient.v1.rating.hashmap_cli:CliDeleteField
|
||||
rating_hashmap_mapping_get = cloudkittyclient.v1.rating.hashmap_cli:CliGetMapping
|
||||
rating_hashmap_mapping_list = cloudkittyclient.v1.rating.hashmap_cli:CliListMapping
|
||||
rating_hashmap_mapping_create = cloudkittyclient.v1.rating.hashmap_cli:CliCreateMapping
|
||||
rating_hashmap_mapping_delete = cloudkittyclient.v1.rating.hashmap_cli:CliDeleteMapping
|
||||
rating_hashmap_mapping_update = cloudkittyclient.v1.rating.hashmap_cli:CliUpdateMapping
|
||||
rating_hashmap_group_list = cloudkittyclient.v1.rating.hashmap_cli:CliListGroup
|
||||
rating_hashmap_group_create = cloudkittyclient.v1.rating.hashmap_cli:CliCreateGroup
|
||||
rating_hashmap_group_delete = cloudkittyclient.v1.rating.hashmap_cli:CliDeleteGroup
|
||||
rating_hashmap_group_mappings_get = cloudkittyclient.v1.rating.hashmap_cli:CliGetGroupMappings
|
||||
rating_hashmap_group_thresholds_get = cloudkittyclient.v1.rating.hashmap_cli:CliGetGroupThresholds
|
||||
rating_hashmap_threshold_get = cloudkittyclient.v1.rating.hashmap_cli:CliGetThreshold
|
||||
rating_hashmap_threshold_list = cloudkittyclient.v1.rating.hashmap_cli:CliListThreshold
|
||||
rating_hashmap_threshold_create = cloudkittyclient.v1.rating.hashmap_cli:CliCreateThreshold
|
||||
rating_hashmap_threshold_delete = cloudkittyclient.v1.rating.hashmap_cli:CliDeleteThreshold
|
||||
rating_hashmap_threshold_update = cloudkittyclient.v1.rating.hashmap_cli:CliUpdateThreshold
|
||||
|
||||
rating_collector-mapping_get = cloudkittyclient.v1.collector_cli:CliCollectorMappingGet
|
||||
rating_collector-mapping_list = cloudkittyclient.v1.collector_cli:CliCollectorMappingList
|
||||
rating_collector-mapping_create = cloudkittyclient.v1.collector_cli:CliCollectorMappingCreate
|
||||
rating_collector-mapping_delete = cloudkittyclient.v1.collector_cli:CliCollectorMappingDelete
|
||||
rating_collector_state_get = cloudkittyclient.v1.collector_cli:CliCollectorGetState
|
||||
rating_collector_enable = cloudkittyclient.v1.collector_cli:CliCollectorEnable
|
||||
rating_collector_disable = cloudkittyclient.v1.collector_cli:CliCollectorDisable
|
||||
rating_dataframes_get = cloudkittyclient.v1.storage_cli:CliGetDataframes
|
||||
|
||||
rating_pyscript_create = cloudkittyclient.v1.rating.pyscripts_cli:CliCreateScript
|
||||
rating_pyscript_list = cloudkittyclient.v1.rating.pyscripts_cli:CliListScripts
|
||||
rating_pyscript_get = cloudkittyclient.v1.rating.pyscripts_cli:CliGetScript
|
||||
rating_pyscript_update = cloudkittyclient.v1.rating.pyscripts_cli:CliUpdateScript
|
||||
rating_pyscript_delete = cloudkittyclient.v1.rating.pyscripts_cli:CliDeleteScript
|
||||
|
||||
|
||||
cloudkittyclient =
|
||||
total_get = cloudkittyclient.v1.report_cli:CliTotalGet
|
||||
|
|
Loading…
Reference in New Issue