Support project name in quota CLI
Change-Id: I9886792f346bbe8d4887539ca69588b4957547e1
This commit is contained in:
parent
1d533778d7
commit
e41d08d243
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Support both project name and ID in quota CLI.
|
@ -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
|
||||
|
2
tox.ini
2
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
|
||||
|
||||
|
@ -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()))
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user