def aggregate_destroy(self, context, aggregate_uuid): with _session_for_write(): # First clean up all metadata related to this aggregate aggregate_id = _get_id_from_aggregate(context, aggregate_uuid) metadata_query = model_query( context, models.AggregateMetadata).filter_by( aggregate_uuid=aggregate_id) metadata_query.delete() # Clean up all host related to this aggregate host_query = model_query( context, models.AggregateHosts).filter_by( aggregate_uuid=aggregate_id) host_query.delete() # Then delete the aggregate record query = model_query(context, models.Aggregates) query = add_identity_filter(query, aggregate_uuid) count = query.delete() if count != 1: raise exception.AggregateNotFound( uuid=aggregate_uuid)
def aggregate_get(self, context, aggregate_uuid): query = model_query(context, models.Aggregates).filter_by(uuid=aggregate_uuid) try: return _dict_with_aggregate_fields(query.one()) except NoResultFound: raise exception.AggregateNotFound(uuid=aggregate_uuid)
def aggregate_update(self, context, aggregate_id, values): with _session_for_write(): query = model_query(context, models.Aggregates) query = add_identity_filter(query, aggregate_id) try: ref = query.with_lockmode('update').one() except NoResultFound: raise exception.AggregateNotFound(uuid=aggregate_id) ref.update(values) return ref
def _get_id_from_aggregate(context, aggregate_id): result = _get_id_from_aggregate_query(context, aggregate_id).first() if not result: raise exception.AggregateNotFound(uuid=aggregate_id) return result.uuid