def event_create(values): values = values.copy() event = models.Event() event.update(values) session = get_session() with session.begin(): try: event.save(session=session) except common_db_exc.DBDuplicateEntry as e: # raise exception about duplicated columns (e.columns) raise db_exc.BlazarDBDuplicateEntry(model=event.__class__.__name__, columns=e.columns) return event_get(event.id)
def lease_create(values): values = values.copy() lease = models.Lease() reservations = values.pop("reservations", []) events = values.pop("events", []) lease.update(values) session = get_session() with session.begin(): try: lease.save(session=session) except common_db_exc.DBDuplicateEntry as e: # raise exception about duplicated columns (e.columns) raise db_exc.BlazarDBDuplicateEntry(model=lease.__class__.__name__, columns=e.columns) try: for r in reservations: reservation = models.Reservation() reservation.update({"lease_id": lease.id}) reservation.update(r) reservation.save(session=session) except common_db_exc.DBDuplicateEntry as e: # raise exception about duplicated columns (e.columns) raise db_exc.BlazarDBDuplicateEntry( model=reservation.__class__.__name__, columns=e.columns) try: for e in events: event = models.Event() event.update({"lease_id": lease.id}) event.update(e) event.save(session=session) except common_db_exc.DBDuplicateEntry as e: # raise exception about duplicated columns (e.columns) raise db_exc.BlazarDBDuplicateEntry(model=event.__class__.__name__, columns=e.columns) return lease_get(lease.id)