summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-11 18:41:41 +0000
committerGerrit Code Review <review@openstack.org>2017-06-11 18:41:41 +0000
commitc8c083db383573196929c2fd8ddb867c0e7d10f8 (patch)
tree7e5a3ab098e95da17d81160e51c133c28446d3dc
parenta5b7be4bed27bf5b9b2466b79cb73ac95665a8a1 (diff)
parent09b5f9fa5e265a2521c2d97f9a47a06714224bdb (diff)
downloadpython-troveclient-c8c083db383573196929c2fd8ddb867c0e7d10f8.tar.gz
Merge "Add list to OSC"
-rw-r--r--releasenotes/notes/add-instance-list-to-osc-05714dfce947a57e.yaml4
-rw-r--r--setup.cfg2
-rw-r--r--troveclient/osc/v1/database_instances.py83
-rw-r--r--troveclient/tests/osc/v1/fakes.py8
-rw-r--r--troveclient/tests/osc/v1/test_database_instances.py49
5 files changed, 146 insertions, 0 deletions
diff --git a/releasenotes/notes/add-instance-list-to-osc-05714dfce947a57e.yaml b/releasenotes/notes/add-instance-list-to-osc-05714dfce947a57e.yaml
new file mode 100644
index 0000000..e8898bc
--- /dev/null
+++ b/releasenotes/notes/add-instance-list-to-osc-05714dfce947a57e.yaml
@@ -0,0 +1,4 @@
+---
+features:
+ - The command ``trove list`` is now available to use in
+ the python-openstackclient CLI as ``openstack database instance list``
diff --git a/setup.cfg b/setup.cfg
index fa5dfb3..956a424 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -34,9 +34,11 @@ openstack.database.v1 =
database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters
database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations
database_flavor_list = troveclient.osc.v1.database_flavors:ListDatabaseFlavors
+ database_instance_list = troveclient.osc.v1.database_instances:ListDatabaseInstances
database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers
+
[build_sphinx]
all_files = 1
source-dir = doc/source
diff --git a/troveclient/osc/v1/database_instances.py b/troveclient/osc/v1/database_instances.py
new file mode 100644
index 0000000..43a8353
--- /dev/null
+++ b/troveclient/osc/v1/database_instances.py
@@ -0,0 +1,83 @@
+# 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 Instances action implementations"""
+
+from osc_lib.command import command
+from osc_lib import utils as osc_utils
+
+from troveclient.i18n import _
+
+
+def set_attributes_for_print(instances):
+ for instance in instances:
+ setattr(instance, 'flavor_id', instance.flavor['id'])
+ if hasattr(instance, 'volume'):
+ setattr(instance, 'size', instance.volume['size'])
+ else:
+ setattr(instance, 'size', '-')
+ if hasattr(instance, 'datastore'):
+ if instance.datastore.get('version'):
+ setattr(instance, 'datastore_version',
+ instance.datastore['version'])
+ setattr(instance, 'datastore', instance.datastore['type'])
+ return instances
+
+
+class ListDatabaseInstances(command.Lister):
+
+ _description = _("List database instances")
+ columns = ['ID', 'Name', 'Datastore', 'Datastore Version', 'Status',
+ 'Flavor ID', 'Size', 'Region']
+
+ def get_parser(self, prog_name):
+ parser = super(ListDatabaseInstances, self).get_parser(prog_name)
+ parser.add_argument(
+ '--limit',
+ dest='limit',
+ metavar='<limit>',
+ 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.')
+ )
+ parser.add_argument(
+ '--include_clustered', '--include-clustered',
+ dest='include_clustered',
+ action="store_true",
+ default=False,
+ help=_("Include instances that are part of a cluster "
+ "(default %(default)s). --include-clustered may be "
+ "deprecated in the future, retaining just "
+ "--include_clustered.")
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ db_instances = self.app.client_manager.database.instances
+ instances = db_instances.list(limit=parsed_args.limit,
+ marker=parsed_args.marker,
+ include_clustered=(parsed_args.
+ include_clustered))
+ if instances:
+ instances = set_attributes_for_print(instances)
+ instances = [osc_utils.get_item_properties(i, self.columns)
+ for i in instances]
+ return self.columns, instances
diff --git a/troveclient/tests/osc/v1/fakes.py b/troveclient/tests/osc/v1/fakes.py
index 1cdff6f..4f43ed1 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 flavors
+from troveclient.v1 import instances
from troveclient.v1 import limits
from troveclient.v1 import users
@@ -76,3 +77,10 @@ class FakeUsers(object):
def get_instances_1234_users_harry(self):
return users.User(None, self.fake_users[2])
+
+
+class FakeInstances(object):
+ fake_instances = (fakes.FakeHTTPClient().get_instances()[2]['instances'])
+
+ def get_instances_1234(self):
+ return instances.Instance(None, self.fake_instances[0])
diff --git a/troveclient/tests/osc/v1/test_database_instances.py b/troveclient/tests/osc/v1/test_database_instances.py
new file mode 100644
index 0000000..d05abf7
--- /dev/null
+++ b/troveclient/tests/osc/v1/test_database_instances.py
@@ -0,0 +1,49 @@
+# 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_instances
+from troveclient.tests.osc.v1 import fakes
+
+
+class TestInstances(fakes.TestDatabasev1):
+ fake_instances = fakes.FakeInstances()
+
+ def setUp(self):
+ super(TestInstances, self).setUp()
+ self.instance_client = self.app.client_manager.database.instances
+
+
+class TestInstanceList(TestInstances):
+
+ defaults = {
+ 'include_clustered': False,
+ 'limit': None,
+ 'marker': None
+ }
+
+ columns = database_instances.ListDatabaseInstances.columns
+ values = ('1234', 'test-member-1', 'mysql', '5.6', 'ACTIVE', '02', 2,
+ 'regionOne')
+
+ def setUp(self):
+ super(TestInstanceList, self).setUp()
+ self.cmd = database_instances.ListDatabaseInstances(self.app, None)
+ self.data = [self.fake_instances.get_instances_1234()]
+ self.instance_client.list.return_value = common.Paginated(self.data)
+
+ def test_instance_list_defaults(self):
+ parsed_args = self.check_parser(self.cmd, [], [])
+ columns, data = self.cmd.take_action(parsed_args)
+ self.instance_client.list.assert_called_once_with(**self.defaults)
+ self.assertEqual(self.columns, columns)
+ self.assertEqual([self.values], data)