Support easier query usage for alarm history search

Use utils.search_query_builder to provide easier
query usage for alarm history search CLI.

Change-Id: Ie49b28b43e230a3d18adbf7734db23ce2aae3927
This commit is contained in:
Kevin_Zheng
2016-03-23 10:27:26 +08:00
parent 0b284f86b0
commit 5e110e32f7
3 changed files with 12 additions and 4 deletions

View File

@@ -65,7 +65,7 @@ class AlarmHistoryTest(base.ClientTestBase):
# SEARCH
result = self.aodh('alarm-history',
params=("search --query "
"'{\"=\": {\"alarm_id\": \"%s\"}}'"
"alarm_id=%s"
% ALARM_ID))
history = self.parser.listing(result)[0]
self.assertEqual(ALARM_ID, history["alarm_id"])

View File

@@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from cliff import lister
from oslo_serialization import jsonutils
from aodhclient import utils
@@ -22,11 +23,18 @@ class CliAlarmHistorySearch(lister.Lister):
def get_parser(self, prog_name):
parser = super(CliAlarmHistorySearch, self).get_parser(prog_name)
parser.add_argument("--query", help="Query"),
parser.add_argument("--query",
help="Rich query supported by aodh, "
"e.g. project_id!=my-id "
"user_id=foo or user_id=bar"),
return parser
def take_action(self, parsed_args):
history = self.app.client.alarm_history.search(query=parsed_args.query)
query = None
if parsed_args.query:
query = jsonutils.dumps(
utils.search_query_builder(parsed_args.query))
history = self.app.client.alarm_history.search(query=query)
return utils.list2cols(self.COLS, history)

View File

@@ -83,5 +83,5 @@ Show an alarm's history::
Search alarm history data::
aodh alarm-history search --query '{">":{"timestamp":"2016-03-09T01:22:35.434961"}}'
aodh --debug alarm-history search --query 'timestamp>"2016-03-09T01:22:35"'