Embed validation data when adding location

Add support for embedding of checksum, os_hash_algo and os_hash_value when
adding a location to an image.

Depends-On: https://review.openstack.org/597648
Change-Id: Ibbe2f2bb226f52cc6b2ab591913b1797d2b086c0
This commit is contained in:
imacdonn
2018-09-14 23:25:11 +00:00
parent a757757a10
commit 3f7171dc14
4 changed files with 46 additions and 10 deletions
+4 -1
View File
@@ -381,7 +381,7 @@ class Controller(object):
data=json.dumps(patch_body))
return (resp, body), resp
def add_location(self, image_id, url, metadata):
def add_location(self, image_id, url, metadata, validation_data=None):
"""Add a new location entry to an image's list of locations.
It is an error to add a URL that is already present in the list of
@@ -390,10 +390,13 @@ class Controller(object):
:param image_id: ID of image to which the location is to be added.
:param url: URL of the location to add.
:param metadata: Metadata associated with the location.
:param validation_data: Validation data for the image.
:returns: The updated image
"""
add_patch = [{'op': 'add', 'path': '/locations/-',
'value': {'url': url, 'metadata': metadata}}]
if validation_data:
add_patch[0]['value']['validation_data'] = validation_data
response = self._send_image_update_request(image_id, add_patch)
# Get request id from the above update request and pass the same to
# following get request
+15 -1
View File
@@ -725,16 +725,30 @@ def do_image_tag_delete(gc, args):
@utils.arg('--metadata', metavar='<STRING>', default='{}',
help=_('Metadata associated with the location. '
'Must be a valid JSON object (default: %(default)s)'))
@utils.arg('--checksum', metavar='<STRING>',
help=_('md5 checksum of image contents'))
@utils.arg('--hash-algo', metavar='<STRING>',
help=_('Multihash algorithm'))
@utils.arg('--hash-value', metavar='<STRING>',
help=_('Multihash value'))
@utils.arg('id', metavar='<IMAGE_ID>',
help=_('ID of image to which the location is to be added.'))
def do_location_add(gc, args):
"""Add a location (and related metadata) to an image."""
validation_data = {}
if args.checksum:
validation_data['checksum'] = args.checksum
if args.hash_algo:
validation_data['os_hash_algo'] = args.hash_algo
if args.hash_value:
validation_data['os_hash_value'] = args.hash_value
try:
metadata = json.loads(args.metadata)
except ValueError:
utils.exit('Metadata is not a valid JSON object.')
else:
image = gc.images.add_location(args.id, args.url, metadata)
image = gc.images.add_location(args.id, args.url, metadata,
validation_data=validation_data)
utils.print_dict(image)