Merge "identity: Extract info from created limit"

This commit is contained in:
Zuul 2024-12-18 17:23:46 +00:00 committed by Gerrit Code Review
commit 05af1aa04c

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from openstack import exceptions
from openstack import resource
@ -63,3 +64,69 @@ class Limit(resource.Resource):
# request body for creating limit is a list instead of dict.
body = {self.resources_key: [body]}
return body
def _translate_response(
self,
response,
has_body=None,
error_message=None,
*,
resource_response_key='limits',
):
"""Given a KSA response, inflate this instance with its data
DELETE operations don't return a body, so only try to work
with a body when has_body is True.
This method updates attributes that correspond to headers
and body on this instance and clears the dirty set.
"""
if has_body is None:
has_body = self.has_body
exceptions.raise_from_response(response, error_message=error_message)
if has_body:
try:
body = response.json()
if resource_response_key and resource_response_key in body:
body = body[resource_response_key]
elif self.resource_key and self.resource_key in body:
body = body[self.resource_key]
# Keystone support bunch create for unified limit. So the
# response body for creating limit is a list instead of dict.
if isinstance(body, list):
body = body[0]
# Do not allow keys called "self" through. Glance chose
# to name a key "self", so we need to pop it out because
# we can't send it through cls.existing and into the
# Resource initializer. "self" is already the first
# argument and is practically a reserved word.
body.pop("self", None)
body_attrs = self._consume_body_attrs(body)
if self._allow_unknown_attrs_in_body:
body_attrs.update(body)
self._unknown_attrs_in_body.update(body)
elif self._store_unknown_attrs_as_properties:
body_attrs = self._pack_attrs_under_properties(
body_attrs, body
)
self._body.attributes.update(body_attrs)
self._body.clean()
if self.commit_jsonpatch or self.allow_patch:
# We need the original body to compare against
self._original_body = body_attrs.copy()
except ValueError:
# Server returned not parse-able response (202, 204, etc)
# Do simply nothing
pass
headers = self._consume_header_attrs(response.headers)
self._header.attributes.update(headers)
self._header.clean()
self._update_location()
dict.update(self, self.to_dict())