diff --git a/releasenotes/notes/add-datastore-list-to-osc-007ff4144f630c57.yaml b/releasenotes/notes/add-datastore-list-to-osc-007ff4144f630c57.yaml new file mode 100644 index 00000000..c4c1a70f --- /dev/null +++ b/releasenotes/notes/add-datastore-list-to-osc-007ff4144f630c57.yaml @@ -0,0 +1,4 @@ +--- +features: + - The command ``trove datastore-list`` is now available to use in + the python-openstackclient CLI as ``openstack datastore list`` diff --git a/setup.cfg b/setup.cfg index 37bd1224..73432d5f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,6 +38,7 @@ openstack.database.v1 = database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits database_list = troveclient.osc.v1.databases:ListDatabases database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers + datastore_list = troveclient.osc.v1.datastores:ListDatastores [build_sphinx] diff --git a/troveclient/osc/v1/datastores.py b/troveclient/osc/v1/datastores.py new file mode 100644 index 00000000..eb63dc85 --- /dev/null +++ b/troveclient/osc/v1/datastores.py @@ -0,0 +1,30 @@ +# 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 Datastores action implementations""" + +from osc_lib.command import command +from osc_lib import utils + +from troveclient.i18n import _ + + +class ListDatastores(command.Lister): + + _description = _("List available datastores") + columns = ['ID', 'Name'] + + def take_action(self, parsed_args): + datastore_client = self.app.client_manager.database.datastores + datastores = datastore_client.list() + ds = [utils.get_item_properties(d, self.columns) for d in datastores] + return self.columns, ds diff --git a/troveclient/tests/osc/v1/fakes.py b/troveclient/tests/osc/v1/fakes.py index 0700f337..934ad1c7 100644 --- a/troveclient/tests/osc/v1/fakes.py +++ b/troveclient/tests/osc/v1/fakes.py @@ -18,6 +18,7 @@ from troveclient.tests.osc import utils from troveclient.v1 import backups from troveclient.v1 import clusters from troveclient.v1 import databases +from troveclient.v1 import datastores from troveclient.v1 import flavors from troveclient.v1 import instances from troveclient.v1 import limits @@ -92,3 +93,10 @@ class FakeDatabases(object): def get_databases_1(self): return databases.Database(None, self.fake_databases[0]) + + +class FakeDatastores(object): + fake_datastores = fakes.FakeHTTPClient().get_datastores()[2]['datastores'] + + def get_datastores_d_123(self): + return datastores.Datastore(None, self.fake_datastores[0]) diff --git a/troveclient/tests/osc/v1/test_datastores.py b/troveclient/tests/osc/v1/test_datastores.py new file mode 100644 index 00000000..13e2c2fc --- /dev/null +++ b/troveclient/tests/osc/v1/test_datastores.py @@ -0,0 +1,41 @@ +# 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 datastores +from troveclient.tests.osc.v1 import fakes + + +class TestDatastores(fakes.TestDatabasev1): + fake_datastores = fakes.FakeDatastores() + + def setUp(self): + super(TestDatastores, self).setUp() + self.datastore_client = self.app.client_manager.database.datastores + + +class TestDatastoreList(TestDatastores): + columns = datastores.ListDatastores.columns + values = ('d-123', 'mysql') + + def setUp(self): + super(TestDatastoreList, self).setUp() + self.cmd = datastores.ListDatastores(self.app, None) + data = [self.fake_datastores.get_datastores_d_123()] + self.datastore_client.list.return_value = common.Paginated(data) + + def test_datastore_list_defaults(self): + parsed_args = self.check_parser(self.cmd, [], []) + columns, data = self.cmd.take_action(parsed_args) + self.datastore_client.list.assert_called_once_with() + self.assertEqual(self.columns, columns) + self.assertEqual([self.values], data)