def get_reservation_unit(self, *, caller: AuthToken, uid: ID, id_token: str = None) -> ResultUnitsAvro: result = ResultUnitsAvro() result.status = ResultAvro() if caller is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message( ErrorCodes.ErrorInvalidArguments.interpret()) return result try: AccessChecker.check_access(action_id=ActionId.query, resource_type=ResourceType.sliver, token=id_token, logger=self.logger, actor_type=self.actor.get_type()) units_list = None try: unit = self.db.get_unit(uid=uid) units_list = [unit] except Exception as e: self.logger.error( "get_reservation_unit:db access {}".format(e)) result.status.set_code(ErrorCodes.ErrorDatabaseError.value) result.status.set_message( ErrorCodes.ErrorDatabaseError.interpret(exception=e)) result.status = ManagementObject.set_exception_details( result=result.status, e=e) return result if units_list is not None: result.units = Converter.fill_units(unit_list=units_list) except Exception as e: self.logger.error("get_reservation_unit: {}".format(e)) result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message( ErrorCodes.ErrorInvalidArguments.interpret()) result.status = ManagementObject.set_exception_details( result=result.status, e=e) return result
def get_reservation_units(self, *, caller: AuthToken, rid: ID, id_token: str = None) -> ResultUnitsAvro: result = ResultUnitsAvro() result.status = ResultAvro() if caller is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message( ErrorCodes.ErrorInvalidArguments.interpret()) return result try: units_list = None try: units_list = self.db.get_units(rid=rid) except Exception as e: self.logger.error( "get_reservation_units:db access {}".format(e)) result.status.set_code(ErrorCodes.ErrorDatabaseError.value) result.status.set_message( ErrorCodes.ErrorDatabaseError.interpret(exception=e)) result.status = ManagementObject.set_exception_details( result=result.status, e=e) return result if units_list is not None: result.result = Converter.fill_units(unit_list=units_list) except Exception as e: self.logger.error("get_reservation_units: {}".format(e)) result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message( ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details( result=result.status, e=e) return result