Skip to content

Commit f4b1a3f

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add support for v2/rating/modules endpoints"
2 parents 9424e67 + e599ac9 commit f4b1a3f

6 files changed

Lines changed: 131 additions & 0 deletions

File tree

cloudkittyclient/tests/unit/v2/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15+
1516
from cloudkittyclient.tests import utils
1617
from cloudkittyclient.v2 import dataframes
18+
from cloudkittyclient.v2.rating import modules
1719
from cloudkittyclient.v2 import scope
1820
from cloudkittyclient.v2 import summary
1921

@@ -26,3 +28,4 @@ def setUp(self):
2628
self.dataframes = dataframes.DataframesManager(self.api_client)
2729
self.scope = scope.ScopeManager(self.api_client)
2830
self.summary = summary.SummaryManager(self.api_client)
31+
self.rating = modules.RatingManager(self.api_client)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2019 Objectif Libre
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#
15+
16+
from cloudkittyclient.tests.unit.v2 import base
17+
18+
19+
class TestRating(base.BaseAPIEndpointTestCase):
20+
21+
def test_get_modules(self):
22+
self.rating.get_module()
23+
self.api_client.get.assert_called_once_with('/v2/rating/modules')
24+
25+
def test_get_one_module(self):
26+
self.rating.get_module(module_id="moduleidtest")
27+
self.api_client.get.assert_called_once_with(
28+
'/v2/rating/modules/moduleidtest')
29+
30+
def test_update_one_module(self):
31+
self.rating.update_module(module_id="moduleidtest",
32+
enabled=False, priority=42)
33+
self.api_client.put.assert_called_once_with(
34+
'/v2/rating/modules/moduleidtest',
35+
json={
36+
'enabled': False,
37+
'priority': 42,
38+
})

cloudkittyclient/v2/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616
from cloudkittyclient.v1 import client
1717
from cloudkittyclient.v2 import dataframes
18+
from cloudkittyclient.v2.rating import modules
1819
from cloudkittyclient.v2 import scope
1920
from cloudkittyclient.v2 import summary
2021

@@ -40,3 +41,4 @@ def __init__(self,
4041
self.dataframes = dataframes.DataframesManager(self.api_client)
4142
self.scope = scope.ScopeManager(self.api_client)
4243
self.summary = summary.SummaryManager(self.api_client)
44+
self.rating = modules.RatingManager(self.api_client)

cloudkittyclient/v2/rating/__init__.py

Whitespace-only changes.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
# Copyright 2019 Objectif Libre
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
#
16+
from cloudkittyclient import exc
17+
from cloudkittyclient.v1.client import rating
18+
19+
20+
class RatingManager(rating.RatingManager):
21+
"""Class used to handle /v2/rating/modules endpoint"""
22+
23+
url = '/v2/rating/modules'
24+
25+
def get_module(self, **kwargs):
26+
"""Returns the given module.
27+
28+
If module_id is not specified, returns the list of loaded modules.
29+
30+
:param module_id: ID of the module on which you want information.
31+
:type module_id: str
32+
"""
33+
module_id = kwargs.get('module_id', None)
34+
if module_id is not None:
35+
url = "{}/{}".format(self.url, module_id)
36+
else:
37+
url = self.url
38+
return self.api_client.get(url).json()
39+
40+
def update_module(self, **kwargs):
41+
"""Update the given module.
42+
43+
:param module_id: Id of the module to update.
44+
:type module_id: str
45+
:param enabled: Set to True to enable the module, False to disable it.
46+
:type enabled: bool
47+
:param priority: New priority of the module.
48+
:type priority: int
49+
"""
50+
if not kwargs.get('module_id', None):
51+
raise exc.ArgumentRequired("'module_id' argument is required.")
52+
mutable_fields = ['enabled', 'priority']
53+
changes = {}
54+
for key, value in kwargs.items():
55+
if value is not None and key in mutable_fields:
56+
changes[key] = value
57+
self.api_client.put("{}/{}".format(self.url, kwargs['module_id']),
58+
json=changes)
59+
return self.get_module(**kwargs)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2019 Objectif Libre
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
#
15+
from cliff import lister
16+
17+
from cloudkittyclient import utils
18+
19+
20+
class CliModuleList(lister.Lister):
21+
"""Get loaded rating modules list"""
22+
23+
def get_parser(self, prog_name):
24+
parser = super(CliModuleList, self).get_parser(prog_name)
25+
return parser
26+
27+
def take_action(self, parsed_args):
28+
resp = utils.get_client_from_osc(self).ratingmodules.get_modules_list()
29+
return resp['modules']

0 commit comments

Comments
 (0)