From 052d85eca42760efe836d417a8f97647b447f777 Mon Sep 17 00:00:00 2001 From: Trevor McCasland Date: Tue, 17 Jan 2017 13:18:43 -0600 Subject: [PATCH] Add cluster-list to OSC This change adds database support to the python-openstackclient project for the cluster-list command. The trove command cluster-list is now: openstack database cluster list Change-Id: I06b398190930db459ef8739685548263499f0d3c Partially-Implements: trove-support-in-python-openstackclient --- ...-cluster-list-to-osc-93532b79db906a14.yaml | 5 ++ setup.cfg | 1 + troveclient/osc/v1/database_clusters.py | 61 +++++++++++++++++++ troveclient/tests/osc/v1/fakes.py | 8 +++ .../tests/osc/v1/test_database_clusters.py | 48 +++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 releasenotes/notes/add-cluster-list-to-osc-93532b79db906a14.yaml create mode 100644 troveclient/osc/v1/database_clusters.py create mode 100644 troveclient/tests/osc/v1/test_database_clusters.py diff --git a/releasenotes/notes/add-cluster-list-to-osc-93532b79db906a14.yaml b/releasenotes/notes/add-cluster-list-to-osc-93532b79db906a14.yaml new file mode 100644 index 00000000..7cdf0560 --- /dev/null +++ b/releasenotes/notes/add-cluster-list-to-osc-93532b79db906a14.yaml @@ -0,0 +1,5 @@ +--- +features: + - The command ``trove cluster-list`` is now available to use in + the python-openstackclient CLI as ``openstack database cluster + list`` diff --git a/setup.cfg b/setup.cfg index 188ee4ae..758deef7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,6 +31,7 @@ openstack.cli.extension = openstack.database.v1 = database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups + database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors [build_sphinx] diff --git a/troveclient/osc/v1/database_clusters.py b/troveclient/osc/v1/database_clusters.py new file mode 100644 index 00000000..13bad6cc --- /dev/null +++ b/troveclient/osc/v1/database_clusters.py @@ -0,0 +1,61 @@ +# 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. + +"""Database v1 Clusters action implementations""" + +from osc_lib.command import command +from osc_lib import utils + +from troveclient.i18n import _ + + +class ListDatabaseClusters(command.Lister): + + _description = _("List database clusters") + columns = ['ID', 'Name', 'Datastore', 'Datastore Version', + 'Task Name'] + + def get_parser(self, prog_name): + parser = super(ListDatabaseClusters, self).get_parser(prog_name) + parser.add_argument( + '--limit', + dest='limit', + metavar='', + type=int, + default=None, + help=_('Limit the number of results displayed.') + ) + parser.add_argument( + '--marker', + dest='marker', + metavar='', + type=str, + default=None, + help=_('Begin displaying the results for IDs greater than the' + ' specified marker. When used with :option:`--limit,` set' + ' this to the last ID displayed in the previous run.') + ) + return parser + + def take_action(self, parsed_args): + database_clusters = self.app.client_manager.database.clusters + clusters = database_clusters.list(limit=parsed_args.limit, + marker=parsed_args.marker) + for cluster in clusters: + setattr(cluster, 'datastore_version', + cluster.datastore['version']) + setattr(cluster, 'datastore', cluster.datastore['type']) + setattr(cluster, 'task_name', cluster.task['name']) + + clusters = [utils.get_item_properties(c, self.columns) + for c in clusters] + return self.columns, clusters diff --git a/troveclient/tests/osc/v1/fakes.py b/troveclient/tests/osc/v1/fakes.py index 9df54b20..079dd1ed 100644 --- a/troveclient/tests/osc/v1/fakes.py +++ b/troveclient/tests/osc/v1/fakes.py @@ -16,6 +16,7 @@ import mock from troveclient.tests import fakes from troveclient.tests.osc import utils from troveclient.v1 import backups +from troveclient.v1 import clusters from troveclient.v1 import flavors @@ -37,3 +38,10 @@ class FakeBackups(object): def get_backup_bk_1234(self): return backups.Backup(None, self.fake_backups[0]) + + +class FakeClusters(object): + fake_clusters = fakes.FakeHTTPClient().get_clusters()[2]['clusters'] + + def get_clusters_cls_1234(self): + return clusters.Cluster(None, self.fake_clusters[0]) diff --git a/troveclient/tests/osc/v1/test_database_clusters.py b/troveclient/tests/osc/v1/test_database_clusters.py new file mode 100644 index 00000000..abd4bcfc --- /dev/null +++ b/troveclient/tests/osc/v1/test_database_clusters.py @@ -0,0 +1,48 @@ +# 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 troveclient import common +from troveclient.osc.v1 import database_clusters +from troveclient.tests.osc.v1 import fakes + + +class TestClusters(fakes.TestDatabasev1): + fake_clusters = fakes.FakeClusters() + + def setUp(self): + super(TestClusters, self).setUp() + self.mock_client = self.app.client_manager.database + self.cluster_client = self.app.client_manager.database.clusters + + +class TestClusterList(TestClusters): + + defaults = { + 'limit': None, + 'marker': None + } + + columns = database_clusters.ListDatabaseClusters.columns + values = ('cls-1234', 'test-clstr', 'vertica', '7.1', 'NONE') + + def setUp(self): + super(TestClusterList, self).setUp() + self.cmd = database_clusters.ListDatabaseClusters(self.app, None) + data = [self.fake_clusters.get_clusters_cls_1234()] + self.cluster_client.list.return_value = common.Paginated(data) + + def test_cluster_list_defaults(self): + parsed_args = self.check_parser(self.cmd, [], []) + columns, data = self.cmd.take_action(parsed_args) + self.cluster_client.list.assert_called_once_with(**self.defaults) + self.assertEqual(self.columns, columns) + self.assertEqual([self.values], data)