From 23ab27ad38b81a5e374ba7f7c8cadb83932701ab Mon Sep 17 00:00:00 2001 From: Omer Anson Date: Sun, 19 Nov 2017 23:50:42 +0200 Subject: [PATCH] Add initial 'trace list' command This is an initial trace list command, which acts both as a starting-point, as well as an immediate solution for anyone who needs the basic functionality of this feature. Change-Id: I99ad62103914b047cfc3c33e50ae98b6a0d01d6d Related-Bug: #1733232 --- osprofiler/cmd/commands.py | 26 ++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 27 insertions(+) diff --git a/osprofiler/cmd/commands.py b/osprofiler/cmd/commands.py index 67aaa43..870b653 100644 --- a/osprofiler/cmd/commands.py +++ b/osprofiler/cmd/commands.py @@ -15,7 +15,10 @@ import json import os +import prettytable +import six +from oslo_utils import encodeutils from oslo_utils import uuidutils from osprofiler.cmd import cliutils @@ -150,3 +153,26 @@ class TraceCommands(BaseCommand): _create_sub_graph(trace) return dot + + @cliutils.arg("--connection-string", dest="conn_str", + default=(cliutils.env("OSPROFILER_CONNECTION_STRING")), + required=True, + help="Storage driver's connection string. Defaults to " + "env[OSPROFILER_CONNECTION_STRING] if set") + def list(self, args): + try: + engine = base.get_driver(args.conn_str, **args.__dict__) + except Exception as e: + raise exc.CommandError(e.message) + + fields = ("base_id", "timestamp") + pretty_table = prettytable.PrettyTable(fields) + pretty_table.align = "l" + traces = engine.list_traces({}, fields) + for trace in traces: + row = [trace[field] for field in fields] + pretty_table.add_row(row) + if six.PY3: + print(encodeutils.safe_encode(pretty_table.get_string()).decode()) + else: + print(encodeutils.safe_encode(pretty_table.get_string())) diff --git a/requirements.txt b/requirements.txt index 29c9200..0a26c58 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ requests>=2.10.0 # Apache-2.0 netaddr>=0.7.13,!=0.7.16 # BSD oslo.concurrency>=3.8.0 # Apache-2.0 oslo.serialization>=2.18.0,!=2.19.1 # Apache-2.0 +PrettyTable>=0.7.1,<0.8 # BSD