summaryrefslogtreecommitdiffstats
path: root/moonclient/moonclient/logs.py
diff options
context:
space:
mode:
authorWuKong <rebirthmonkey@gmail.com>2015-07-01 09:01:11 +0200
committerWuKong <rebirthmonkey@gmail.com>2015-07-01 09:01:11 +0200
commit96b35f38008c73c70fb598d29515a4cce5e48edc (patch)
treed24795c0a917ec7dab59389f5fce8cdfb9c85dfc /moonclient/moonclient/logs.py
parent03bf0c32a0c656d4b91bebedc87a005e6d7563bb (diff)
migrate moonclient from github to opnfv
Change-Id: I024ad1136f50d1c2898d30e05be48131d02b6932 Signed-off-by: WuKong <rebirthmonkey@gmail.com>
Diffstat (limited to 'moonclient/moonclient/logs.py')
-rw-r--r--moonclient/moonclient/logs.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/moonclient/moonclient/logs.py b/moonclient/moonclient/logs.py
new file mode 100644
index 00000000..03c16128
--- /dev/null
+++ b/moonclient/moonclient/logs.py
@@ -0,0 +1,67 @@
+# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
+# This software is distributed under the terms and conditions of the 'Apache-2.0'
+# license which can be found in the file 'LICENSE' in this package distribution
+# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
+
+import logging
+
+from cliff.lister import Lister
+from cliff.command import Command
+from cliff.show import ShowOne
+
+
+class LogsList(Lister):
+ """List all aggregation algorithms."""
+
+ log = logging.getLogger(__name__)
+
+ def get_parser(self, prog_name):
+ parser = super(LogsList, self).get_parser(prog_name)
+ parser.add_argument(
+ '--filter',
+ metavar='<filter-str>',
+ help='Filter strings (example: "OK" or "authz")',
+ )
+ parser.add_argument(
+ '--fromdate',
+ metavar='<from-date-str>',
+ help='Filter logs by date (example: "2015-04-15-13:45:20")',
+ )
+ parser.add_argument(
+ '--todate',
+ metavar='<to-date-str>',
+ help='Filter logs by date (example: "2015-04-15-13:45:20")',
+ )
+ parser.add_argument(
+ '--number',
+ metavar='<number-int>',
+ help='Show only <number-int> logs',
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ filter_str = parsed_args.filter
+ from_date = parsed_args.fromdate
+ to_date = parsed_args.todate
+ number = parsed_args.number
+ options = list()
+ if filter_str:
+ options.append("filter={}".format(filter_str))
+ if from_date:
+ options.append("from={}".format(from_date))
+ if to_date:
+ options.append("to={}".format(to_date))
+ if number:
+ options.append("event_number={}".format(number))
+ if len(options) > 0:
+ url = "/v3/OS-MOON/logs/{}".format(",".join(options))
+ else:
+ url = "/v3/OS-MOON/logs"
+ data = self.app.get_url(url, authtoken=True)
+ if "logs" not in data:
+ raise Exception("Error in command {}: {}".format("LogsList", data))
+ return (
+ ("Logs",),
+ ((log, ) for log in data["logs"])
+ )
+