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
This commit is contained in:
parent
fe73e9c782
commit
052d85eca4
@ -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``
|
@ -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]
|
||||
|
61
troveclient/osc/v1/database_clusters.py
Normal file
61
troveclient/osc/v1/database_clusters.py
Normal file
@ -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
|
@ -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])
|
||||
|
48
troveclient/tests/osc/v1/test_database_clusters.py
Normal file
48
troveclient/tests/osc/v1/test_database_clusters.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user