Add limit-list to OSC

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

The trove command limit-list is now:
    openstack database limit list

Change-Id: I534d30022cbfef4ae596077f604e2a305dbe3146
Partially-Implements: trove-support-in-python-openstackclient
This commit is contained in:
Trevor McCasland 2017-02-02 17:27:42 -06:00 committed by Amrith Kumar
parent 1abc33cedc
commit 6626ef7bbb
4 changed files with 92 additions and 0 deletions

View File

@ -34,6 +34,7 @@ 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_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
[build_sphinx]
all_files = 1

View File

@ -0,0 +1,34 @@
# 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 Limits action implementations"""
from osc_lib.command import command
from osc_lib import utils as osc_utils
from troveclient.i18n import _
from troveclient import utils
class ListDatabaseLimits(command.Lister):
_description = _("List database limits")
columns = ['Value', 'Verb', 'Remaining', 'Unit']
def take_action(self, parsed_args):
database_limits = self.app.client_manager.database.limits
limits = database_limits.list()
# Pop the first one, its absolute limits
utils.print_dict(limits.pop(0)._info)
limits = [osc_utils.get_item_properties(i, self.columns)
for i in limits]
return self.columns, limits

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 flavors
from troveclient.v1 import limits
class TestDatabasev1(utils.TestCommand):
@ -53,3 +54,17 @@ class FakeConfigurations(object):
def get_configurations_c_123(self):
return flavors.Flavor(None, self.fake_config[0])
class FakeLimits(object):
fake_limits = fakes.FakeHTTPClient().get_limits()[2]['limits']
def get_absolute_limits(self):
return limits.Limit(None, self.fake_limits[0])
def get_non_absolute_limits(self):
return limits.Limit(None,
{'value': 200,
'verb': 'DELETE',
'remaining': 200,
'unit': 'MINUTE'})

View File

@ -0,0 +1,42 @@
# 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_limits
from troveclient.tests.osc.v1 import fakes
class TestLimits(fakes.TestDatabasev1):
fake_limits = fakes.FakeLimits()
def setUp(self):
super(TestLimits, self).setUp()
self.limit_client = self.app.client_manager.database.limits
class TestLimitList(TestLimits):
columns = database_limits.ListDatabaseLimits.columns
non_absolute_values = (200, 'DELETE', 200, 'MINUTE')
def setUp(self):
super(TestLimitList, self).setUp()
self.cmd = database_limits.ListDatabaseLimits(self.app, None)
data = [self.fake_limits.get_absolute_limits(),
self.fake_limits.get_non_absolute_limits()]
self.limit_client.list.return_value = common.Paginated(data)
def test_limit_list_defaults(self):
parsed_args = self.check_parser(self.cmd, [], [])
columns, data = self.cmd.take_action(parsed_args)
self.limit_client.list.assert_called_once_with()
self.assertEqual(self.columns, columns)
self.assertEqual([self.non_absolute_values], data)