From b98d88ff9216387d7a8f28dc1f6b1d47ff4654eb Mon Sep 17 00:00:00 2001 From: Vitaly Gridnev Date: Thu, 20 Nov 2014 16:36:18 +0300 Subject: [PATCH] Add ability to get events from saharaclient Change-Id: I01a0612ccc912249e01f12cd51181a79f3a155af Implements: blueprint event-log --- saharaclient/api/client.py | 2 ++ saharaclient/api/events.py | 31 +++++++++++++++++++++++++++++++ saharaclient/api/shell.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 saharaclient/api/events.py diff --git a/saharaclient/api/client.py b/saharaclient/api/client.py index 931502d6..7558bcb0 100644 --- a/saharaclient/api/client.py +++ b/saharaclient/api/client.py @@ -20,6 +20,7 @@ from keystoneclient.v3 import client as keystone_client_v3 from saharaclient.api import cluster_templates from saharaclient.api import clusters from saharaclient.api import data_sources +from saharaclient.api import events from saharaclient.api import httpclient from saharaclient.api import images from saharaclient.api import job_binaries @@ -97,6 +98,7 @@ class Client(object): self.job_binary_internals = ( job_binary_internals.JobBinaryInternalsManager(client) ) + self.events = events.ClusterEventManager(client) def get_keystone_client(self, username=None, api_key=None, auth_url=None, token=None, project_id=None, project_name=None): diff --git a/saharaclient/api/events.py b/saharaclient/api/events.py new file mode 100644 index 00000000..3421a3e6 --- /dev/null +++ b/saharaclient/api/events.py @@ -0,0 +1,31 @@ +# Copyright (c) 2014 Mirantis Inc. +# +# 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 saharaclient.api import base + + +class ClusterEvent(base.Resource): + resource_name = 'ClusterEvent' + + +class ClusterEventManager(base.ResourceManager): + resource_class = ClusterEvent + + def list(self, cluster_id, provision_step=None): + if provision_step: + return self._list('/clusters/%s/progress?provision_step=%s' + % (cluster_id, provision_step), 'events') + else: + return self._list('/clusters/%s/progress' % cluster_id, 'events') diff --git a/saharaclient/api/shell.py b/saharaclient/api/shell.py index ec420da8..bd94c8e0 100644 --- a/saharaclient/api/shell.py +++ b/saharaclient/api/shell.py @@ -796,3 +796,32 @@ def do_job_delete(cs, args): """Delete a job.""" cs.job_executions.delete(args.id) # TODO(mattf): No indication of result + +# +# Events +# ~~~~~~~~ +# events-list --name |--id +# [--step ] +# + + +@utils.arg('--name', + metavar='', + help='Name of the cluster to show events.') +@utils.arg('--id', + metavar='', + help='ID of the cluster to show events.') +@utils.arg('--step', + metavar='', + default=None, + help='ID of provision step to show events.') +def do_event_list(cs, args): + """Show events of a cluster.""" + cluster = _get_by_id_or_name(cs.clusters, args.id, args.name) + if args.step: + events = cs.events.list(cluster.id, args.step) + else: + events = cs.events.list(cluster.id) + columns = ('node_group_id', 'instance_name', + 'event_info', 'successful', 'step_id') + utils.print_list(events, columns)