summaryrefslogtreecommitdiff
path: root/troveclient
diff options
context:
space:
mode:
authorTrevor McCasland <TM2086@att.com>2017-01-17 13:18:43 -0600
committerAmrith Kumar <amrith@amrith.org>2017-06-10 21:30:59 -0400
commit052d85eca42760efe836d417a8f97647b447f777 (patch)
tree009404775a0d1d7ee944aa7142332e11a202092e /troveclient
parentfe73e9c782590afac50dbb891aa1777da1b04181 (diff)
downloadpython-troveclient-052d85eca42760efe836d417a8f97647b447f777.tar.gz
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
Diffstat (limited to 'troveclient')
-rw-r--r--troveclient/osc/v1/database_clusters.py61
-rw-r--r--troveclient/tests/osc/v1/fakes.py8
-rw-r--r--troveclient/tests/osc/v1/test_database_clusters.py48
3 files changed, 117 insertions, 0 deletions
diff --git a/troveclient/osc/v1/database_clusters.py b/troveclient/osc/v1/database_clusters.py
new file mode 100644
index 0000000..13bad6c
--- /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='<limit>',
+ type=int,
+ default=None,
+ help=_('Limit the number of results displayed.')
+ )
+ parser.add_argument(
+ '--marker',
+ dest='marker',
+ metavar='<ID>',
+ 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 9df54b2..079dd1e 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 0000000..abd4bcf
--- /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)