def _delete_inventory_from_provider(conn, rp, to_delete):
 allocation_query = sa.select([_ALLOC_TBL.c.resource_class_id.label('resource_class')]).where(sa.and_((_ALLOC_TBL.c.resource_provider_id == rp.id), _ALLOC_TBL.c.resource_class_id.in_(to_delete))).group_by(_ALLOC_TBL.c.resource_class_id)
 allocations = conn.execute(allocation_query).fetchall()
 if allocations:
  resource_classes = ', '.join([_RC_CACHE.string_from_id(alloc[0]) for alloc in allocations])
  raise exception.InventoryInUse(resource_classes=resource_classes, resource_provider=rp.uuid)
 del_stmt = _INV_TBL.delete().where(sa.and_((_INV_TBL.c.resource_provider_id == rp.id), _INV_TBL.c.resource_class_id.in_(to_delete)))
 res = conn.execute(del_stmt)
 return res.rowcount

def _delete_inventory_from_provider ( conn , rp , to_delete ) : allocation_query = sa . select ( [ _ALLOC_TBL . c . resource_class_id . label ( 'resource_class' ) ] ) . where ( sa . and_ ( ( _ALLOC_TBL . c . resource_provider_id == rp . id ) , _ALLOC_TBL . c . resource_class_id . in_ ( to_delete ) ) ) . group_by ( _ALLOC_TBL . c . resource_class_id ) allocations = conn . execute ( allocation_query ) . fetchall ( ) if allocations : resource_classes = ', ' . join ( [ _RC_CACHE . string_from_id ( alloc [ 0 ] ) for alloc in allocations ] ) raise exception . InventoryInUse ( resource_classes = resource_classes , resource_provider = rp . uuid ) del_stmt = _INV_TBL . delete ( ) . where ( sa . and_ ( ( _INV_TBL . c . resource_provider_id == rp . id ) , _INV_TBL . c . resource_class_id . in_ ( to_delete ) ) ) res = conn . execute ( del_stmt ) return res . rowcount
deletes any inventory records from the supplied provider and set() of resource class identifiers .