summaryrefslogtreecommitdiff
path: root/ceilometerclient/v2/shell.py
diff options
context:
space:
mode:
authorAngus Salkeld <asalkeld@redhat.com>2013-02-25 20:59:27 +1100
committerAngus Salkeld <asalkeld@redhat.com>2013-02-25 20:59:27 +1100
commita7fba2cb63489d35344b3f8a055aa3fe2fa49193 (patch)
tree9882cd2783945e9eaeb62c5ddf2e3041164e823d /ceilometerclient/v2/shell.py
parentd740e3767219e6dd980fc10005ef110752ec406a (diff)
downloadpython-ceilometerclient-a7fba2cb63489d35344b3f8a055aa3fe2fa49193.tar.gz
Add shell.py so we can do v2 shell commands
ceilometer --ceilometer-api-version 2 sample-list -m <meter> fixes bug #1132633 Signed-off-by: Angus Salkeld <asalkeld@redhat.com> Change-Id: I177c2f759b9b07b44dcd6dd20f457cefd036d0b9
Diffstat (limited to 'ceilometerclient/v2/shell.py')
-rw-r--r--ceilometerclient/v2/shell.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py
new file mode 100644
index 0000000..524d46a
--- /dev/null
+++ b/ceilometerclient/v2/shell.py
@@ -0,0 +1,66 @@
+#
+# Copyright © 2013 Red Hat
+#
+# Author: Angus Salkeld <asalkeld@redhat.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from ceilometerclient.common import utils
+import ceilometerclient.exc as exc
+
+
+@utils.arg('-q', '--query', metavar='<QUERY>',
+ help='key[op]value; list.')
+@utils.arg('-m', '--meter', metavar='<NAME>',
+ help='Name of meter to show samples for.')
+def do_statistics(cc, args):
+ '''List the statistics for this meters'''
+ fields = {'meter_name': args.meter,
+ 'q': args.query}
+ if args.meter is None:
+ raise exc.CommandError('Meter name not provided (-m <meter name>)')
+ try:
+ statistics = cc.statistics.list(**fields)
+ except exc.HTTPNotFound:
+ raise exc.CommandError('Samples not found: %s' % args.meter)
+ else:
+ field_labels = ['Period', 'Period Start', 'Period End',
+ 'Count', 'Min', 'Max', 'Sum', 'Avg',
+ 'Duration', 'Duration Start', 'Duration End']
+ fields = ['period', 'period_start', 'period_end',
+ 'count', 'min', 'max', 'sum', 'avg',
+ 'duration', 'duration_start', 'duration_end']
+ utils.print_list(statistics, fields, field_labels)
+
+
+@utils.arg('-q', '--query', metavar='<QUERY>',
+ help='key[op]value; list.')
+@utils.arg('-m', '--meter', metavar='<NAME>',
+ help='Name of meter to show samples for.')
+def do_sample_list(cc, args):
+ '''List the samples for this meters'''
+ fields = {'meter_name': args.meter,
+ 'q': args.query}
+ if args.meter is None:
+ raise exc.CommandError('Meter name not provided (-m <meter name>)')
+ try:
+ samples = cc.samples.list(**fields)
+ except exc.HTTPNotFound:
+ raise exc.CommandError('Samples not found: %s' % args.meter)
+ else:
+ field_labels = ['Resource ID', 'Name', 'Type', 'Volume', 'Unit',
+ 'Timestamp']
+ fields = ['resource_id', 'counter_name', 'counter_type',
+ 'counter_volume', 'counter_unit', 'timestamp']
+ utils.print_list(samples, fields, field_labels,
+ sortby=0)