Merge "Add cluster-show to OSC"
This commit is contained in:
commit
22ae4cf937
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
features:
|
||||
- The command ``trove cluster-show`` is now available to use in
|
||||
the python-openstackclient CLI as ``openstack database cluster
|
||||
show``
|
|
@ -33,6 +33,7 @@ openstack.database.v1 =
|
|||
database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups
|
||||
database_backup_show = troveclient.osc.v1.database_backups:ShowDatabaseBackup
|
||||
database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters
|
||||
database_cluster_show = troveclient.osc.v1.database_clusters:ShowDatabaseCluster
|
||||
database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations
|
||||
database_configuration_show = troveclient.osc.v1.database_configurations:ShowDatabaseConfiguration
|
||||
database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors
|
||||
|
|
|
@ -14,10 +14,29 @@
|
|||
|
||||
from osc_lib.command import command
|
||||
from osc_lib import utils
|
||||
import six
|
||||
|
||||
from troveclient.i18n import _
|
||||
|
||||
|
||||
def set_attributes_for_print_detail(cluster):
|
||||
info = cluster._info.copy()
|
||||
if hasattr(cluster, 'datastore'):
|
||||
info['datastore'] = cluster.datastore['type']
|
||||
info['datastore_version'] = cluster.datastore['version']
|
||||
if hasattr(cluster, 'task'):
|
||||
info['task_description'] = cluster.task['description']
|
||||
info['task_name'] = cluster.task['name']
|
||||
info.pop('task', None)
|
||||
if hasattr(cluster, 'ip'):
|
||||
info['ip'] = ', '.join(cluster.ip)
|
||||
instances = info.pop('instances', None)
|
||||
if instances:
|
||||
info['instance_count'] = len(instances)
|
||||
info.pop('links', None)
|
||||
return info
|
||||
|
||||
|
||||
class ListDatabaseClusters(command.Lister):
|
||||
|
||||
_description = _("List database clusters")
|
||||
|
@ -59,3 +78,22 @@ class ListDatabaseClusters(command.Lister):
|
|||
clusters = [utils.get_item_properties(c, self.columns)
|
||||
for c in clusters]
|
||||
return self.columns, clusters
|
||||
|
||||
|
||||
class ShowDatabaseCluster(command.ShowOne):
|
||||
_description = _("Shows details of a database cluster")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowDatabaseCluster, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'cluster',
|
||||
metavar='<cluster>',
|
||||
help=_('ID or name of the cluster'),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
database_clusters = self.app.client_manager.database.clusters
|
||||
cluster = utils.find_resource(database_clusters, parsed_args.cluster)
|
||||
cluster = set_attributes_for_print_detail(cluster)
|
||||
return zip(*sorted(six.iteritems(cluster)))
|
||||
|
|
|
@ -46,3 +46,34 @@ class TestClusterList(TestClusters):
|
|||
self.cluster_client.list.assert_called_once_with(**self.defaults)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual([self.values], data)
|
||||
|
||||
|
||||
class TestClusterShow(TestClusters):
|
||||
|
||||
values = ('2015-05-02T10:37:04', 'vertica', '7.1', 'cls-1234', 2,
|
||||
'test-clstr', 'No tasks for the cluster.', 'NONE',
|
||||
'2015-05-02T11:06:19')
|
||||
|
||||
def setUp(self):
|
||||
super(TestClusterShow, self).setUp()
|
||||
self.cmd = database_clusters.ShowDatabaseCluster(self.app, None)
|
||||
self.data = self.fake_clusters.get_clusters_cls_1234()
|
||||
self.cluster_client.get.return_value = self.data
|
||||
self.columns = (
|
||||
'created',
|
||||
'datastore',
|
||||
'datastore_version',
|
||||
'id',
|
||||
'instance_count',
|
||||
'name',
|
||||
'task_description',
|
||||
'task_name',
|
||||
'updated',
|
||||
)
|
||||
|
||||
def test_show(self):
|
||||
args = ['cls-1234']
|
||||
parsed_args = self.check_parser(self.cmd, args, [])
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.values, data)
|
||||
|
|
Loading…
Reference in New Issue