@db_api.api_context_manager.writer
def _set_inventory(context, rp, inv_list):
 _ensure_rc_cache(context)
 conn = context.session.connection()
 existing_resources = _get_current_inventory_resources(conn, rp)
 these_resources = set([_RC_CACHE.id_from_string(r.resource_class) for r in inv_list.objects])
 to_add = (these_resources - existing_resources)
 to_delete = (existing_resources - these_resources)
 to_update = (these_resources & existing_resources)
 exceeded = []
 with conn.begin():
  if to_delete:
   _delete_inventory_from_provider(conn, rp, to_delete)
  if to_add:
   _add_inventory_to_provider(conn, rp, inv_list, to_add)
  if to_update:
   exceeded = _update_inventory_for_provider(conn, rp, inv_list, to_update)
  rp.generation = _increment_provider_generation(conn, rp)
 return exceeded

@ db_api . api_context_manager . writer def _set_inventory ( context , rp , inv_list ) : _ensure_rc_cache ( context ) conn = context . session . connection ( ) existing_resources = _get_current_inventory_resources ( conn , rp ) these_resources = set ( [ _RC_CACHE . id_from_string ( r . resource_class ) for r in inv_list . objects ] ) to_add = ( these_resources - existing_resources ) to_delete = ( existing_resources - these_resources ) to_update = ( these_resources & existing_resources ) exceeded = [ ] with conn . begin ( ) : if to_delete : _delete_inventory_from_provider ( conn , rp , to_delete ) if to_add : _add_inventory_to_provider ( conn , rp , inv_list , to_add ) if to_update : exceeded = _update_inventory_for_provider ( conn , rp , inv_list , to_update ) rp . generation = _increment_provider_generation ( conn , rp ) return exceeded
given an inventorylist object .