Example #1
0
    def add_reservation(self, *, reservation: ABCReservationMixin):
        try:
            self.lock.acquire()
            self.logger.debug("Adding reservation {} to slice {}".format(
                reservation.get_reservation_id(), reservation.get_slice()))
            properties = pickle.dumps(reservation)
            oidc_claim_sub = None
            email = None
            if reservation.get_slice() is not None and reservation.get_slice(
            ).get_owner() is not None:
                oidc_claim_sub = reservation.get_slice().get_owner(
                ).get_oidc_sub_claim()
                email = reservation.get_slice().get_owner().get_email()

            self.db.add_reservation(
                slc_guid=str(reservation.get_slice_id()),
                rsv_resid=str(reservation.get_reservation_id()),
                rsv_category=reservation.get_category().value,
                rsv_state=reservation.get_state().value,
                rsv_pending=reservation.get_pending_state().value,
                rsv_joining=reservation.get_join_state().value,
                properties=properties,
                rsv_graph_node_id=reservation.get_graph_node_id(),
                oidc_claim_sub=oidc_claim_sub,
                email=email)
            self.logger.debug("Reservation {} added to slice {}".format(
                reservation.get_reservation_id(), reservation.get_slice()))
        finally:
            self.lock.release()
Example #2
0
 def update_reservation(self, *, reservation: ABCReservationMixin):
     # Update the reservation only when there are changes to be reflected in database
     if not reservation.is_dirty():
         return
     reservation.clear_dirty()
     try:
         self.lock.acquire()
         self.logger.debug("Updating reservation {} in slice {}".format(
             reservation.get_reservation_id(), reservation.get_slice()))
         properties = pickle.dumps(reservation)
         self.db.update_reservation(
             slc_guid=str(reservation.get_slice_id()),
             rsv_resid=str(reservation.get_reservation_id()),
             rsv_category=reservation.get_category().value,
             rsv_state=reservation.get_state().value,
             rsv_pending=reservation.get_pending_state().value,
             rsv_joining=reservation.get_join_state().value,
             properties=properties,
             rsv_graph_node_id=reservation.get_graph_node_id())
     finally:
         self.lock.release()