Remove dict-compat from the image object
This patch removes the need of having dictcompat from the image object. Luckily we have around 5 objects in zun that would need this changes. DictCompat is not really needed, since that's the old way of referencing an object field just like a dictionary object in python. Currently a better way needs to be implemented to avoid conversion of the image object to a dict back and forth. This could be achieved if we implement the API validation blueprint. Change-Id: Ia0f5a4415b70934e7d47d77594f0d43ae6cb65bc Partially-Implements: blueprint rm-object-dict-compat
This commit is contained in:
parent
7489bb6430
commit
60d4d58d99
@ -117,7 +117,10 @@ class ImageCollection(collection.Collection):
|
|||||||
def convert_with_links(rpc_images, limit, url=None,
|
def convert_with_links(rpc_images, limit, url=None,
|
||||||
expand=False, **kwargs):
|
expand=False, **kwargs):
|
||||||
collection = ImageCollection()
|
collection = ImageCollection()
|
||||||
collection.images = [Image.convert_with_links(p, expand)
|
# TODO(sbiswas7): This is the ugly part of the deal.
|
||||||
|
# We need to convert this p thing below as dict for now
|
||||||
|
# Removal of dict-compat lead to this change.
|
||||||
|
collection.images = [Image.convert_with_links(p.as_dict(), expand)
|
||||||
for p in rpc_images]
|
for p in rpc_images]
|
||||||
collection.next = collection.get_next(limit, url=url, **kwargs)
|
collection.next = collection.get_next(limit, url=url, **kwargs)
|
||||||
return collection
|
return collection
|
||||||
@ -195,4 +198,6 @@ class ImagesController(rest.RestController):
|
|||||||
# Set the HTTP Location Header
|
# Set the HTTP Location Header
|
||||||
pecan.response.location = link.build_url('images', new_image.uuid)
|
pecan.response.location = link.build_url('images', new_image.uuid)
|
||||||
pecan.response.status = 202
|
pecan.response.status = 202
|
||||||
return Image.convert_with_links(new_image)
|
# TODO(sbiswas7): Schema validation is a better approach than
|
||||||
|
# back n forth conversion into dicts and objects.
|
||||||
|
return Image.convert_with_links(new_image.as_dict())
|
||||||
|
@ -17,8 +17,7 @@ from zun.objects import base
|
|||||||
|
|
||||||
|
|
||||||
@base.ZunObjectRegistry.register
|
@base.ZunObjectRegistry.register
|
||||||
class Image(base.ZunPersistentObject, base.ZunObject,
|
class Image(base.ZunPersistentObject, base.ZunObject):
|
||||||
base.ZunObjectDictCompat):
|
|
||||||
# Version 1.0: Initial version
|
# Version 1.0: Initial version
|
||||||
VERSION = '1.0'
|
VERSION = '1.0'
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ class Image(base.ZunPersistentObject, base.ZunObject,
|
|||||||
def _from_db_object(image, db_image):
|
def _from_db_object(image, db_image):
|
||||||
"""Converts a database entity to a formal object."""
|
"""Converts a database entity to a formal object."""
|
||||||
for field in image.fields:
|
for field in image.fields:
|
||||||
image[field] = db_image[field]
|
setattr(image, field, db_image[field])
|
||||||
|
|
||||||
image.obj_reset_changes()
|
image.obj_reset_changes()
|
||||||
return image
|
return image
|
||||||
|
Loading…
x
Reference in New Issue
Block a user