Updated the take_actions for unified limits
When user passes --region None, the find_resource of osc_lib calls get() of region. The get API of region ignores the name param returning all the regions in result. As the find_resource checks many cases against the result returned by get API. The output comes greater than 1, thus returning "More than one region ID exist" which is incorrect. However in case of region which cannot be filtered by name we do not require to check these many cases. The solution is to directly call the get method of APIs and returning No resource name exist with the xyz" on passing invaid parameter. And returning all in case of None. Thus created a new function get_resource which can be used in future too by these types of API's. Change-Id: Ib3f881d34a82af97199ce51bfbefc6f3f08599f1 Closes-bug: #1799153
This commit is contained in:
parent
097b45686e
commit
81fd5c995d
@ -68,6 +68,25 @@ def find_service(identity_client, name_type_or_id):
|
||||
raise exceptions.CommandError(msg % name_type_or_id)
|
||||
|
||||
|
||||
def get_resource(manager, name_type_or_id):
|
||||
# NOTE (vishakha): Due to bug #1799153 and for any another related case
|
||||
# where GET resource API does not support the filter by name,
|
||||
# osc_lib.utils.find_resource() method cannot be used because that method
|
||||
# try to fall back to list all the resource if requested resource cannot
|
||||
# be get via name. Which ends up with NoUniqueMatch error.
|
||||
# This new function is the replacement for osc_lib.utils.find_resource()
|
||||
# for resources does not support GET by name.
|
||||
# For example: identity GET /regions.
|
||||
"""Find a resource by id or name."""
|
||||
|
||||
try:
|
||||
return manager.get(name_type_or_id)
|
||||
except identity_exc.NotFound:
|
||||
# raise NotFound exception
|
||||
msg = _("No resource with name or id of '%s' exists")
|
||||
raise exceptions.CommandError(msg % name_type_or_id)
|
||||
|
||||
|
||||
def _get_token_resource(client, resource, parsed_name, parsed_domain=None):
|
||||
"""Peek into the user's auth token to get resource IDs
|
||||
|
||||
|
@ -78,9 +78,19 @@ class CreateLimit(command.ShowOne):
|
||||
)
|
||||
region = None
|
||||
if parsed_args.region:
|
||||
region = utils.find_resource(
|
||||
identity_client.regions, parsed_args.region
|
||||
)
|
||||
val = getattr(parsed_args, 'region', None)
|
||||
if 'None' not in val:
|
||||
# NOTE (vishakha): Due to bug #1799153 and for any another
|
||||
# related case where GET resource API does not support the
|
||||
# filter by name, osc_lib.utils.find_resource() method cannot
|
||||
# be used because that method try to fall back to list all the
|
||||
# resource if requested resource cannot be get via name. Which
|
||||
# ends up with NoUniqueMatch error.
|
||||
# So osc_lib.utils.find_resource() function cannot be used for
|
||||
# 'regions', using common_utils.get_resource() instead.
|
||||
region = common_utils.get_resource(
|
||||
identity_client.regions, parsed_args.region
|
||||
)
|
||||
|
||||
limit = identity_client.limits.create(
|
||||
project,
|
||||
@ -136,6 +146,19 @@ class ListLimit(command.Lister):
|
||||
region = utils.find_resource(
|
||||
identity_client.regions, parsed_args.region
|
||||
)
|
||||
val = getattr(parsed_args, 'region', None)
|
||||
if 'None' not in val:
|
||||
# NOTE (vishakha): Due to bug #1799153 and for any another
|
||||
# related case where GET resource API does not support the
|
||||
# filter by name, osc_lib.utils.find_resource() method cannot
|
||||
# be used because that method try to fall back to list all the
|
||||
# resource if requested resource cannot be get via name. Which
|
||||
# ends up with NoUniqueMatch error.
|
||||
# So osc_lib.utils.find_resource() function cannot be used for
|
||||
# 'regions', using common_utils.get_resource() instead.
|
||||
region = common_utils.get_resource(
|
||||
identity_client.regions, parsed_args.region
|
||||
)
|
||||
project = None
|
||||
if parsed_args.project:
|
||||
project = utils.find_resource(
|
||||
|
@ -69,9 +69,19 @@ class CreateRegisteredLimit(command.ShowOne):
|
||||
)
|
||||
region = None
|
||||
if parsed_args.region:
|
||||
region = utils.find_resource(
|
||||
identity_client.regions, parsed_args.region
|
||||
)
|
||||
val = getattr(parsed_args, 'region', None)
|
||||
if 'None' not in val:
|
||||
# NOTE (vishakha): Due to bug #1799153 and for any another
|
||||
# related case where GET resource API does not support the
|
||||
# filter by name, osc_lib.utils.find_resource() method cannot
|
||||
# be used because that method try to fall back to list all the
|
||||
# resource if requested resource cannot be get via name. Which
|
||||
# ends up with NoUniqueMatch error.
|
||||
# So osc_lib.utils.find_resource() function cannot be used for
|
||||
# 'regions', using common_utils.get_resource() instead.
|
||||
region = common_utils.get_resource(
|
||||
identity_client.regions, parsed_args.region
|
||||
)
|
||||
|
||||
registered_limit = identity_client.registered_limits.create(
|
||||
service,
|
||||
@ -153,9 +163,19 @@ class ListRegisteredLimit(command.Lister):
|
||||
)
|
||||
region = None
|
||||
if parsed_args.region:
|
||||
region = utils.find_resource(
|
||||
identity_client.regions, parsed_args.region
|
||||
)
|
||||
val = getattr(parsed_args, 'region', None)
|
||||
if 'None' not in val:
|
||||
# NOTE (vishakha): Due to bug #1799153 and for any another
|
||||
# related case where GET resource API does not support the
|
||||
# filter by name, osc_lib.utils.find_resource() method cannot
|
||||
# be used because that method try to fall back to list all the
|
||||
# resource if requested resource cannot be get via name. Which
|
||||
# ends up with NoUniqueMatch error.
|
||||
# So osc_lib.utils.find_resource() function cannot be used for
|
||||
# 'regions', using common_utils.get_resource() instead.
|
||||
region = common_utils.get_resource(
|
||||
identity_client.regions, parsed_args.region
|
||||
)
|
||||
|
||||
registered_limits = identity_client.registered_limits.list(
|
||||
service=service,
|
||||
@ -222,9 +242,19 @@ class SetRegisteredLimit(command.ShowOne):
|
||||
|
||||
region = None
|
||||
if parsed_args.region:
|
||||
region = utils.find_resource(
|
||||
identity_client.regions, parsed_args.region
|
||||
)
|
||||
val = getattr(parsed_args, 'region', None)
|
||||
if 'None' not in val:
|
||||
# NOTE (vishakha): Due to bug #1799153 and for any another
|
||||
# related case where GET resource API does not support the
|
||||
# filter by name, osc_lib.utils.find_resource() method cannot
|
||||
# be used because that method try to fall back to list all the
|
||||
# resource if requested resource cannot be get via name. Which
|
||||
# ends up with NoUniqueMatch error.
|
||||
# So osc_lib.utils.find_resource() function cannot be used for
|
||||
# 'regions', using common_utils.get_resource() instead.
|
||||
region = common_utils.get_resource(
|
||||
identity_client.regions, parsed_args.region
|
||||
)
|
||||
|
||||
registered_limit = identity_client.registered_limits.update(
|
||||
parsed_args.registered_limit_id,
|
||||
|
Loading…
Reference in New Issue
Block a user