Add datastore-list to OSC

This change adds database support to the python-openstackclient
project for the datastore-list command.

The trove command datastore-list is now:
    openstack datastore list

Change-Id: I4804e6deae350f05abdb66a6d8813e5581f2b22c
Partially-Implements: trove-support-in-python-openstackclient
This commit is contained in:
Trevor McCasland 2017-01-17 15:58:42 -06:00 committed by Amrith Kumar
parent 29bdd7f5cb
commit 8b945cf5eb
5 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
features:
- The command ``trove datastore-list`` is now available to use in
the python-openstackclient CLI as ``openstack datastore list``

View File

@ -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]

View File

@ -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

View File

@ -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])

View File

@ -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)