summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--saharaclient/api/client.py2
-rw-r--r--saharaclient/api/clusters.py10
-rw-r--r--saharaclient/api/events.py31
-rw-r--r--saharaclient/api/shell.py42
-rw-r--r--saharaclient/tests/unit/test_clusters.py20
5 files changed, 35 insertions, 70 deletions
diff --git a/saharaclient/api/client.py b/saharaclient/api/client.py
index bd20697..61b868d 100644
--- a/saharaclient/api/client.py
+++ b/saharaclient/api/client.py
@@ -21,7 +21,6 @@ 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
@@ -116,7 +115,6 @@ 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/clusters.py b/saharaclient/api/clusters.py
index 4130a21..20af3e4 100644
--- a/saharaclient/api/clusters.py
+++ b/saharaclient/api/clusters.py
@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from six.moves.urllib import parse
+
from saharaclient.api import base
@@ -55,8 +57,12 @@ class ClusterManager(base.ResourceManager):
query = base.get_query_string(search_opts)
return self._list('/clusters%s' % query, 'clusters')
- def get(self, cluster_id):
- return self._get('/clusters/%s' % cluster_id, 'cluster')
+ def get(self, cluster_id, show_progress=False):
+ url = ('/clusters/%(cluster_id)s?%(params)s' %
+ {"cluster_id": cluster_id,
+ "params": parse.urlencode({"show_progress": show_progress})})
+
+ return self._get(url, 'cluster')
def delete(self, cluster_id):
self._delete('/clusters/%s' % cluster_id)
diff --git a/saharaclient/api/events.py b/saharaclient/api/events.py
deleted file mode 100644
index 3421a3e..0000000
--- a/saharaclient/api/events.py
+++ /dev/null
@@ -1,31 +0,0 @@
-# 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 bd94c8e..a350740 100644
--- a/saharaclient/api/shell.py
+++ b/saharaclient/api/shell.py
@@ -110,12 +110,12 @@ def _show_job(job):
utils.print_dict(job._info)
-def _get_by_id_or_name(manager, id=None, name=None):
+def _get_by_id_or_name(manager, id=None, name=None, **kwargs):
if not (name or id):
raise exceptions.CommandError("either NAME or ID is required")
if id:
- return manager.get(id)
- ls = manager.find(name=name)
+ return manager.get(id, **kwargs)
+ ls = manager.find(name=name, **kwargs)
if len(ls) == 0:
raise exceptions.CommandError("%s '%s' not found" %
(manager.resource_class.resource_name,
@@ -272,7 +272,7 @@ def do_image_remove_tag(cs, args):
# ~~~~~~~~
# cluster-list
#
-# cluster-show --name <cluster>|--id <cluster_id> [--json]
+# cluster-show --name <cluster>|--id <cluster_id> [--json] [--show-progress]
#
# cluster-create [--json <file>]
#
@@ -296,13 +296,16 @@ def do_cluster_list(cs, args):
@utils.arg('--id',
metavar='<cluster_id>',
help='ID of the cluster to show.')
+@utils.arg('--show-progress',
+ help='Show provision progress events of the cluster.')
@utils.arg('--json',
action='store_true',
default=False,
help='Print JSON representation of the cluster.')
def do_cluster_show(cs, args):
"""Show details of a cluster."""
- cluster = _get_by_id_or_name(cs.clusters, args.id, args.name)
+ cluster = _get_by_id_or_name(cs.clusters, args.id, args.name,
+ show_progress=args.show_progress)
if args.json:
print(json.dumps(cluster._info))
else:
@@ -796,32 +799,3 @@ 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 <cluster>|--id <cluster_id>
-# [--step <step_id>]
-#
-
-
-@utils.arg('--name',
- metavar='<cluster_name>',
- help='Name of the cluster to show events.')
-@utils.arg('--id',
- metavar='<cluster_id>',
- help='ID of the cluster to show events.')
-@utils.arg('--step',
- metavar='<step_id>',
- 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)
diff --git a/saharaclient/tests/unit/test_clusters.py b/saharaclient/tests/unit/test_clusters.py
index 69683ff..37c49eb 100644
--- a/saharaclient/tests/unit/test_clusters.py
+++ b/saharaclient/tests/unit/test_clusters.py
@@ -26,6 +26,14 @@ class ClusterTest(base.BaseTestCase):
'cluster_template_id': 'id',
}
+ body_with_progress = {
+ 'name': 'name',
+ 'plugin_name': 'fake',
+ 'hadoop_version': '0.1',
+ 'cluster_template_id': 'id',
+ "provision_progress": []
+ }
+
def test_create_cluster_with_template(self,):
url = self.URL + '/clusters'
self.responses.post(url, status_code=202, json={'cluster': self.body})
@@ -65,7 +73,7 @@ class ClusterTest(base.BaseTestCase):
self.assertFields(self.body, resp[0])
def test_clusters_get(self):
- url = self.URL + '/clusters/id'
+ url = self.URL + '/clusters/id?show_progress=False'
self.responses.get(url, json={'cluster': self.body})
resp = self.client.clusters.get('id')
@@ -74,6 +82,16 @@ class ClusterTest(base.BaseTestCase):
self.assertIsInstance(resp, cl.Cluster)
self.assertFields(self.body, resp)
+ def test_clusters_get_with_progress(self):
+ url = self.URL + '/clusters/id?show_progress=True'
+ self.responses.get(url, json={'cluster': self.body_with_progress})
+
+ resp = self.client.clusters.get('id', show_progress=True)
+
+ self.assertEqual(url, self.responses.last_request.url)
+ self.assertIsInstance(resp, cl.Cluster)
+ self.assertFields(self.body, resp)
+
def test_clusters_scale(self):
url = self.URL + '/clusters/id'
self.responses.put(url, status_code=202, json=self.body)