summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLingxian Kong <anlin.kong@gmail.com>2021-04-29 11:47:26 +1200
committerLingxian Kong <anlin.kong@gmail.com>2021-04-29 14:17:48 +1200
commite41d08d24325a61a213592934b508bf77ce67dac (patch)
tree0052ccd5e8f0ea311d1b5b1ef42c230d85d9b93d
parent1d533778d7cdc04d6319b7d015571d7b3503b0e1 (diff)
downloadpython-troveclient-e41d08d24325a61a213592934b508bf77ce67dac.tar.gz
Support project name in quota CLI
Change-Id: I9886792f346bbe8d4887539ca69588b4957547e1
-rw-r--r--releasenotes/notes/xena-support-project-name-quota-cli.yaml3
-rw-r--r--requirements.txt3
-rw-r--r--tox.ini2
-rw-r--r--troveclient/osc/v1/database_quota.py34
-rw-r--r--troveclient/utils.py27
5 files changed, 47 insertions, 22 deletions
diff --git a/releasenotes/notes/xena-support-project-name-quota-cli.yaml b/releasenotes/notes/xena-support-project-name-quota-cli.yaml
new file mode 100644
index 0000000..ef4164e
--- /dev/null
+++ b/releasenotes/notes/xena-support-project-name-quota-cli.yaml
@@ -0,0 +1,3 @@
+---
+features:
+ - Support both project name and ID in quota CLI.
diff --git a/requirements.txt b/requirements.txt
index dec3c5f..bd623cd 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,7 +2,7 @@
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
pbr!=2.1.0,>=2.0.0 # Apache-2.0
-PrettyTable<0.8,>=0.7.2 # BSD
+PrettyTable>=0.7.2 # BSD
requests>=2.14.2 # Apache-2.0
simplejson>=3.5.1 # MIT
oslo.i18n>=3.15.3 # Apache-2.0
@@ -11,3 +11,4 @@ keystoneauth1>=3.4.0 # Apache-2.0
python-swiftclient>=3.2.0 # Apache-2.0
python-mistralclient!=3.2.0,>=3.1.0 # Apache-2.0
osc-lib>=1.8.0 # Apache-2.0
+python-openstackclient>=3.12.0 # Apache-2.0
diff --git a/tox.ini b/tox.ini
index ff68682..2e4e9cc 100644
--- a/tox.ini
+++ b/tox.ini
@@ -61,7 +61,7 @@ commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasen
[flake8]
enable-extensions = H106,H203,H904
-ignore = H202,H405,H501,W504
+ignore = H202,H405,H501,W504,H306
show-source = True
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,releasenotes
diff --git a/troveclient/osc/v1/database_quota.py b/troveclient/osc/v1/database_quota.py
index 82e77fc..26b66aa 100644
--- a/troveclient/osc/v1/database_quota.py
+++ b/troveclient/osc/v1/database_quota.py
@@ -12,48 +12,49 @@
"""Database v1 Quota action implementations"""
-from osc_lib.command import command
from osc_lib import utils as osc_utils
+from osc_lib.command import command
from troveclient.i18n import _
+from troveclient import utils
class ShowDatabaseQuota(command.Lister):
-
- _description = _("Show quotas for a tenant.")
+ _description = _("Show quotas for a project.")
columns = ['Resource', 'In Use', 'Reserved', 'Limit']
def get_parser(self, prog_name):
parser = super(ShowDatabaseQuota, self).get_parser(prog_name)
parser.add_argument(
- 'tenant_id',
- metavar='<tenant_id>',
- help=_('Id of tenant for which to show quotas.'),
+ 'project',
+ help=_('Id or name of the project.'),
)
return parser
def take_action(self, parsed_args):
db_quota = self.app.client_manager.database.quota
+ project_id = utils.get_project_id(
+ self.app.client_manager.identity,
+ parsed_args.project
+ )
quota = [osc_utils.get_item_properties(q, self.columns)
- for q in db_quota.show(parsed_args.tenant_id)]
+ for q in db_quota.show(project_id)]
return self.columns, quota
class UpdateDatabaseQuota(command.ShowOne):
-
- _description = _("Update quotas for a tenant.")
+ _description = _("Update quotas for a project.")
def get_parser(self, prog_name):
parser = super(UpdateDatabaseQuota, self).get_parser(prog_name)
parser.add_argument(
- 'tenant_id',
- metavar='<tenant_id>',
- help=_('Id of tenant for which to update quotas.'),
+ 'project',
+ help=_('Id or name of the project.'),
)
parser.add_argument(
'resource',
metavar='<resource>',
- help=_('Id of resource to change.'),
+ help=_('Resource name.'),
)
parser.add_argument(
'limit',
@@ -65,9 +66,12 @@ class UpdateDatabaseQuota(command.ShowOne):
def take_action(self, parsed_args):
db_quota = self.app.client_manager.database.quota
+ project_id = utils.get_project_id(
+ self.app.client_manager.identity,
+ parsed_args.project
+ )
update_params = {
parsed_args.resource: parsed_args.limit
}
- updated_quota = db_quota.update(parsed_args.tenant_id,
- update_params)
+ updated_quota = db_quota.update(project_id, update_params)
return zip(*sorted(updated_quota.items()))
diff --git a/troveclient/utils.py b/troveclient/utils.py
index 28a2537..04645b6 100644
--- a/troveclient/utils.py
+++ b/troveclient/utils.py
@@ -14,15 +14,16 @@
# License for the specific language governing permissions and limitations
# under the License.
-import base64
-import os
-import simplejson as json
-import sys
import uuid
+import base64
+from openstackclient.identity import common as identity_common
+import os
from oslo_utils import encodeutils
from oslo_utils import uuidutils
import prettytable
+import simplejson as json
+import sys
from troveclient.apiclient import exceptions
@@ -225,8 +226,24 @@ def get_resource_id_by_name(manager, name):
return resource.id
+def get_project_id(manager, id_or_name):
+ if not uuidutils.is_uuid_like(id_or_name):
+ try:
+ project = identity_common.find_project(manager, id_or_name)
+ id_or_name = project.id
+ except Exception as e:
+ msg = ("Failed to get project ID for %s, error: %s" %
+ (id_or_name, str(e)))
+ raise exceptions.CommandError(msg)
+
+ return id_or_name
+
+
def find_resource(manager, name_or_id):
- """Helper for the _find_* methods."""
+ """Helper for the _find_* methods.
+
+ This method should be replaced with osc_utils.find_resource()
+ """
# first try to get entity as integer id
# When the 'name_or_id' is int, covert it to string.