Use v2 API by default

CloudKitty's v1 API has been deprecated for a while, but the CLI
continued to use that as a default, keeping v2 as optional. This patch
changes that behaviour, switching to use the more modern and currently
maintained v2 as default, while v1 is still available via the
--os-rating-api-version parameter.

Change-Id: I4ca8c4f69b022af53d9f7ec71f3a2efadfc9163e
Signed-off-by: Juan Larriba <jlarriba@redhat.com>
This commit is contained in:
Juan Larriba
2025-12-02 12:31:15 +01:00
parent 59dc73588f
commit 2d965f9459
3 changed files with 23 additions and 15 deletions

View File

@@ -14,7 +14,7 @@
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 = {

View File

@@ -42,17 +42,17 @@ Version
-------
Two versions of the client exist: v1 and v2. The v2 version adds support for
v2 API endpoints. The default API version is 1. You can specify which API
v2 API endpoints. The default API version is 2. You can specify which API
version you want to use via a CLI option:
.. code-block:: shell
# EITHER
cloudkitty --os-rating-api-version 2 summary get
cloudkitty --os-rating-api-version 1 module list
# OR
export OS_RATING_API_VERSION=2
cloudkitty summary get
export OS_RATING_API_VERSION=1
cloudkitty module list
Again, the option can also be provided to the OSC plugin, both via the CLI
flag or the environment variable.
@@ -68,7 +68,7 @@ to use it without keystone authentication, cloudkittyclient provides the
>>> from cloudkittyclient import auth as ck_auth
>>> auth = ck_auth.CloudKittyNoAuthPlugin(endpoint='http://127.0.0.1:8889')
>>> client = ck_client.Client('1', auth=auth)
>>> client = ck_client.Client('2', auth=auth)
>>> client.report.get_summary()
{u'summary': [{u'begin': u'2018-03-01T00:00:00',
u'end': u'2018-04-01T00:00:00',
@@ -95,7 +95,7 @@ Else, use it the same way as any other OpenStack client::
>>> ck_session = session.Session(auth=auth)
>>> c = ck_client.Client('1', session=ck_session)
>>> c = ck_client.Client('2', session=ck_session)
>>> c.report.get_summary()
{u'summary': [{u'begin': u'2018-03-01T00:00:00',
@@ -112,25 +112,25 @@ Else, use it the same way as any other OpenStack client::
and ``cacert``::
>>> client = ck_client.Client(
'1', auth=auth, insecure=False, cacert='/path/to/ca')
'2', auth=auth, insecure=False, cacert='/path/to/ca')
If you want to use the v2 API, you have to specify it at client instanciation
If you want to use the v1 API, you have to specify it at client instanciation
.. code-block:: python
c = ck_client.Client('2', session=session)
c = ck_client.Client('1', session=session)
When using the ``cloudkitty`` CLI client with keystone authentication, the
auth plugin to use should automagically be detected. If not, you can specify
the auth plugin to use with ``--os-auth-type/--os-auth-plugin``::
$ cloudkitty --debug --os-auth-type cloudkitty-noauth summary get
+------------+---------------+------------+---------------------+---------------------+
| Project ID | Resource Type | Rate | Begin Time | End Time |
+------------+---------------+------------+---------------------+---------------------+
| ALL | ALL | 1676.95499 | 2018-03-01T00:00:00 | 2018-04-01T00:00:00 |
+------------+---------------+------------+---------------------+---------------------+
+---------------------------+---------------------------+------------+-------------------+
| Begin | End | Qty | Rate |
+---------------------------+---------------------------+------------+-------------------+
| 2025-12-01T00:00:00+01:00 | 2026-01-01T00:00:00+01:00 | 21662194.0 | 3618130.211340219 |
+---------------------------+---------------------------+------------+-------------------+
CSV report generation

View File

@@ -0,0 +1,8 @@
---
upgrade:
- |
The default API version has been changed from v1 to v2. Users who want
to continue using the v1 API must now explicitly specify the API version
using the ``--os-rating-api-version 1`` CLI option or by setting the
``OS_RATING_API_VERSION=1`` environment variable. If no version is
specified, the client will now use the v2 API by default.