def _normalize_image_location_for_db(image_data):
 if (('locations' not in image_data) and ('location_data' not in image_data)):
  image_data['locations'] = None
  return image_data
 locations = image_data.pop('locations', [])
 location_data = image_data.pop('location_data', [])
 location_data_dict = {}
 for l in locations:
  location_data_dict[l] = {}
 for l in location_data:
  location_data_dict[l['url']] = {'metadata': l['metadata'], 'status': l['status'], 'id': (l['id'] if ('id' in l) else None)}
 ordered_keys = locations[:]
 for ld in location_data:
  if (ld['url'] not in ordered_keys):
   ordered_keys.append(ld['url'])
 location_data = []
 for loc in ordered_keys:
  data = location_data_dict[loc]
  if data:
   location_data.append({'url': loc, 'metadata': data['metadata'], 'status': data['status'], 'id': data['id']})
  else:
   location_data.append({'url': loc, 'metadata': {}, 'status': 'active', 'id': None})
 image_data['locations'] = location_data
 return image_data

def _normalize_image_location_for_db ( image_data ) : if ( ( 'locations' not in image_data ) and ( 'location_data' not in image_data ) ) : image_data [ 'locations' ] = None return image_data locations = image_data . pop ( 'locations' , [ ] ) location_data = image_data . pop ( 'location_data' , [ ] ) location_data_dict = { } for l in locations : location_data_dict [ l ] = { } for l in location_data : location_data_dict [ l [ 'url' ] ] = { 'metadata' : l [ 'metadata' ] , 'status' : l [ 'status' ] , 'id' : ( l [ 'id' ] if ( 'id' in l ) else None ) } ordered_keys = locations [ : ] for ld in location_data : if ( ld [ 'url' ] not in ordered_keys ) : ordered_keys . append ( ld [ 'url' ] ) location_data = [ ] for loc in ordered_keys : data = location_data_dict [ loc ] if data : location_data . append ( { 'url' : loc , 'metadata' : data [ 'metadata' ] , 'status' : data [ 'status' ] , 'id' : data [ 'id' ] } ) else : location_data . append ( { 'url' : loc , 'metadata' : { } , 'status' : 'active' , 'id' : None } ) image_data [ 'locations' ] = location_data return image_data
this function takes the legacy locations field and the newly added location_data field from the image_data values dictionary which flows over the wire between the registry and api servers and converts it into the location_data format only which is then consumable by the image object .