summaryrefslogtreecommitdiff
path: root/ceilometerclient/v1/shell.py
diff options
context:
space:
mode:
authorAngus Salkeld <asalkeld@redhat.com>2012-11-09 23:31:27 +1100
committerAngus Salkeld <asalkeld@redhat.com>2012-11-09 23:31:27 +1100
commit635bc921dbf0fe0c65d5ec84a6cd327e83550e40 (patch)
tree3ec4b1bd30536a4447a1df7509ae72867f765ac7 /ceilometerclient/v1/shell.py
parent098f944eda406a2741c8d0f3546ea318421340bf (diff)
downloadpython-ceilometerclient-635bc921dbf0fe0c65d5ec84a6cd327e83550e40.tar.gz
Add basic functionality
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
Diffstat (limited to 'ceilometerclient/v1/shell.py')
-rw-r--r--ceilometerclient/v1/shell.py109
1 files changed, 109 insertions, 0 deletions
diff --git a/ceilometerclient/v1/shell.py b/ceilometerclient/v1/shell.py
new file mode 100644
index 0000000..a8e7c62
--- /dev/null
+++ b/ceilometerclient/v1/shell.py
@@ -0,0 +1,109 @@
+# Copyright 2012 OpenStack LLC.
+# All Rights Reserved.
+#
+# 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.
+
+import json
+
+from ceilometerclient.common import utils
+import ceilometerclient.exc as exc
+
+
+@utils.arg('-s', '--source', metavar='<SOURCE>',
+ help='ID of the resource to show events for.')
+@utils.arg('-r', '--resource_id', metavar='<RESOURCE_ID>',
+ help='ID of the resource to show events for.')
+@utils.arg('-u', '--user_id', metavar='<USER_ID>',
+ help='ID of the user to show events for.')
+@utils.arg('-p', '--project_id', metavar='<PROJECT_ID>',
+ help='ID of the project to show events for.')
+@utils.arg('-c', '--counter_name', metavar='<NAME>',
+ help='Name of meter to show events for.')
+def do_event_list(cc, args):
+ '''List the events for this meters'''
+ fields = {'counter_name': args.counter_name,
+ 'resource_id': args.resource_id,
+ 'user_id': args.user_id,
+ 'project_id': args.project_id,
+ 'source': args.source}
+ try:
+ events = cc.events.list(**fields)
+ except exc.HTTPNotFound:
+ raise exc.CommandError('Events not found: %s' % args.counter_name)
+ else:
+ json_format = lambda js: json.dumps(js, indent=2)
+ formatters = {
+ 'metadata': json_format,
+ }
+ for e in events:
+ utils.print_dict(e.to_dict(), formatters=formatters)
+
+
+@utils.arg('-s', '--source', metavar='<SOURCE>',
+ help='ID of the resource to show events for.')
+@utils.arg('-r', '--resource_id', metavar='<RESOURCE_ID>',
+ help='ID of the resource to show events for.')
+@utils.arg('-u', '--user_id', metavar='<USER_ID>',
+ help='ID of the user to show events for.')
+@utils.arg('-p', '--project_id', metavar='<PROJECT_ID>',
+ help='ID of the project to show events for.')
+def do_metric_list(cc, args={}):
+ '''List the user's metrices'''
+ fields = {'resource_id': args.resource_id,
+ 'user_id': args.user_id,
+ 'project_id': args.project_id,
+ 'source': args.source}
+ metrics = cc.meters.list(**fields)
+ field_labels = ['Name', 'Resource ID', 'User ID']
+ fields = ['counter_name', 'resource_id', 'user_id']
+ utils.print_list(metrics, fields, field_labels,
+ sortby=0)
+
+
+def do_user_list(cc, args={}):
+ '''List the users'''
+ kwargs = {}
+ users = cc.users.list(**kwargs)
+ field_labels = ['User ID']
+ fields = ['user_id']
+ utils.print_list(users, fields, field_labels,
+ sortby=0)
+
+
+@utils.arg('-s', '--source', metavar='<SOURCE>',
+ help='ID of the resource to show events for.')
+@utils.arg('-u', '--user_id', metavar='<USER_ID>',
+ help='ID of the user to show events for.')
+def do_resource_list(cc, args={}):
+ '''List the users'''
+ kwargs = {'source': args.source,
+ 'user_id': args.user_id}
+ resources = cc.resources.list(**kwargs)
+
+ field_labels = ['Resource ID', 'Source', 'User ID', 'Project ID']
+ fields = ['resource_id', 'source', 'user_id', 'project_id']
+ utils.print_list(resources, fields, field_labels,
+ sortby=1)
+
+
+@utils.arg('-s', '--source', metavar='<SOURCE>',
+ help='ID of the resource to show events for.')
+def do_project_list(cc, args={}):
+ '''List the projects'''
+ kwargs = {'source': args.source}
+ projects = cc.projects.list(**kwargs)
+
+ field_labels = ['Project ID']
+ fields = ['project_id']
+ utils.print_list(projects, fields, field_labels,
+ sortby=0)