Split alarm query and alarm list in SDK layer.
As discussed in the review of https://review.openstack.org/#/c/321394/ split alarm query and list in the SDK layer will make the code more easier to understand. Change-Id: Ic1ec81b1e25f6bf3a7913b68310f2fc853fcc5d5
This commit is contained in:
parent
c6b5b0b429
commit
93080b86a1
@ -47,10 +47,10 @@ class AlarmManagerTest(testtools.TestCase):
|
||||
mock_am.assert_called_with('v2/alarms')
|
||||
|
||||
@mock.patch.object(alarm.AlarmManager, '_post')
|
||||
def test_list_with_query(self, mock_am):
|
||||
def test_query(self, mock_am):
|
||||
am = alarm.AlarmManager(self.client)
|
||||
query = '{"=": {"type": "event"}}'
|
||||
am.list(query)
|
||||
am.query(query)
|
||||
url = 'v2/query/alarms'
|
||||
expected_value = ('{"filter": "{\\"=\\": {\\"type\\":'
|
||||
' \\"event\\"}}"}')
|
||||
|
@ -11,6 +11,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from debtcollector import removals
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from aodhclient.v2.alarm_cli import ALARM_TYPES
|
||||
@ -29,30 +30,45 @@ class AlarmManager(base.Manager):
|
||||
urls.append(url)
|
||||
return '&'.join(urls)
|
||||
|
||||
def list(self, query=None, filters=None):
|
||||
@removals.removed_kwarg('query',
|
||||
message='Calling list() with query parameter'
|
||||
'is deprecated, and will be removed'
|
||||
'in python-aodhclient 0.7.0, please '
|
||||
'use query() instead.')
|
||||
def list(self, filters=None, query=None):
|
||||
"""List alarms.
|
||||
|
||||
:param query: A json format complex query expression, like this:
|
||||
'{"=":{"type":"threshold"}}', this expression is used to
|
||||
query all the threshold type alarms.
|
||||
:type query: json
|
||||
:param filters: A dict includes filters parameters, for example,
|
||||
{'type': 'threshold', 'severity': 'low'} represent
|
||||
filters to query alarms with type='threshold' and
|
||||
severity='low'.
|
||||
:type filters: dict
|
||||
:param query: A json format complex query expression, like this:
|
||||
'{"=":{"type":"threshold"}}', this expression is used to
|
||||
query all the threshold type alarms.
|
||||
:type query: js
|
||||
"""
|
||||
if query:
|
||||
query = {'filter': query}
|
||||
url = "v2/query/alarms"
|
||||
return self._post(url,
|
||||
headers={'Content-Type': "application/json"},
|
||||
data=jsonutils.dumps(query)).json()
|
||||
return query(query)
|
||||
else:
|
||||
url = (self.url + '?' + self._filtersdict_to_url(filters) if
|
||||
filters else self.url)
|
||||
return self._get(url).json()
|
||||
|
||||
def query(self, query=None):
|
||||
"""Query alarms.
|
||||
|
||||
:param query: A json format complex query expression, like this:
|
||||
'{"=":{"type":"threshold"}}', this expression is used to
|
||||
query all the threshold type alarms.
|
||||
:type query: json
|
||||
"""
|
||||
query = {'filter': query}
|
||||
url = "v2/query/alarms"
|
||||
return self._post(url,
|
||||
headers={'Content-Type': "application/json"},
|
||||
data=jsonutils.dumps(query)).json()
|
||||
|
||||
def get(self, alarm_id):
|
||||
"""Get an alarm
|
||||
|
||||
|
@ -67,11 +67,10 @@ class CliAlarmList(lister.Lister):
|
||||
if parsed_args.query:
|
||||
query = jsonutils.dumps(
|
||||
utils.search_query_builder(parsed_args.query))
|
||||
alarms = utils.get_client(self).alarm.query(query=query)
|
||||
else:
|
||||
query = None
|
||||
filters = dict(parsed_args.filter) if parsed_args.filter else None
|
||||
alarms = utils.get_client(self).alarm.list(query=query,
|
||||
filters=filters)
|
||||
filters = dict(parsed_args.filter) if parsed_args.filter else None
|
||||
alarms = utils.get_client(self).alarm.list(filters=filters)
|
||||
return utils.list2cols(ALARM_LIST_COLS, alarms)
|
||||
|
||||
|
||||
@ -100,7 +99,7 @@ def _format_alarm(alarm):
|
||||
def _find_alarm_by_name(client, name):
|
||||
# then try to get entity as name
|
||||
query = jsonutils.dumps({"=": {"name": name}})
|
||||
alarms = client.alarm.list(query)
|
||||
alarms = client.alarm.query(query)
|
||||
if len(alarms) > 1:
|
||||
msg = (_("Multiple alarms matches found for '%s', "
|
||||
"use an ID to be more specific.") % name)
|
||||
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
upgrade:
|
||||
- Alarm list and query has been split into two separate functions
|
||||
in the SDK layer( CLI user still uses alarm list with --query
|
||||
or --filter as before).
|
||||
deprecations:
|
||||
- Calling alarm list function with query parameter has been deprecated
|
||||
and will be removed in python-aodhclient 0.7.0, please use alarm query
|
||||
function instead.
|
@ -9,3 +9,4 @@ oslo.serialization>=1.4.0 # Apache-2.0
|
||||
oslo.utils>=2.0.0 # Apache-2.0
|
||||
keystoneauth1>=1.0.0
|
||||
six
|
||||
debtcollector
|
||||
|
Loading…
x
Reference in New Issue
Block a user