Debian Codegraph @

aodhclient/v2/alarm_history_cli.py

raw
1 #
2 # Licensed under the Apache License, Version 2.0 (the "License"); you may
3 # not use this file except in compliance with the License. You may obtain
4 # a copy of the License at
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11 # License for the specific language governing permissions and limitations
12 # under the License.
13 from cliff import lister
14 from oslo_serialization import jsonutils
15
16 from aodhclient import utils
17
18
19 class CliAlarmHistorySearch(lister.Lister):
20 """Show history for all alarms based on query"""
21
22 COLS = ('alarm_id', 'timestamp', 'type', 'detail')
23
24 def get_parser(self, prog_name):
25 parser = super().get_parser(prog_name)
26 parser.add_argument("--query",
27 help="Rich query supported by aodh, "
28 "e.g. project_id!=my-id "
29 "user_id=foo or user_id=bar"),
30 return parser
31
32 def take_action(self, parsed_args):
33 query = None
34 if parsed_args.query:
35 query = jsonutils.dumps(
36 utils.search_query_builder(parsed_args.query))
37 history = utils.get_client(self).alarm_history.search(
38 query=query)
39 return utils.list2cols(self.COLS, history)
40
41
42 class CliAlarmHistoryShow(lister.Lister):
43 """Show history for an alarm"""
44
45 COLS = ('timestamp', 'type', 'detail', 'event_id')
46
47 def get_parser(self, prog_name):
48 parser = super().get_parser(prog_name)
49 parser.add_argument("alarm_id", metavar="<alarm-id>",
50 help="ID of an alarm")
51 parser.add_argument("--limit", type=int, metavar="<LIMIT>",
52 help="Number of resources to return "
53 "(Default is server default)")
54 parser.add_argument("--marker", metavar="<MARKER>",
55 help="Last item of the previous listing. "
56 "Return the next results after this value,"
57 "the supported marker is event_id.")
58 parser.add_argument("--sort", action="append",
59 metavar="<SORT_KEY:SORT_DIR>",
60 help="Sort of resource attribute. "
61 "e.g. timestamp:desc")
62 return parser
63
64 def take_action(self, parsed_args):
65 history = utils.get_client(self).alarm_history.get(
66 alarm_id=parsed_args.alarm_id, sorts=parsed_args.sort,
67 limit=parsed_args.limit, marker=parsed_args.marker)
68 return utils.list2cols(self.COLS, history)