emulator_engine.services.api package
Interfaces primarily related to IP block emulator APIs.
- class emulator_engine.services.api.RouterClient(bitstream_emulator_id: str, ip_block_id: str = '', *args, **kwargs)[source]
Bases:
LoggingBaseAPI client class which sets up an API router and common routes for an IP block emulator.
- Parameters:
- get_rpc_response(request_body: InternalRestRequest) InternalRestResponse[source]
Sends an RPC request via RabbitMQ, then waits for and returns the response.
- property router: APIRouter
The FastAPI Router used by this client.
- Type:
APIRouter
- class emulator_engine.services.api.RouterImpl(*args, **kwargs)[source]
Bases:
LoggingBaseAPI class which serves as a base for IP block emulator API implementations.
This class is designed to internally process requests forwarded from the respective Client via RPC.
- call(method_name: str, **kwargs) InternalRestResponse[source]
Call a method of this instance by name and return its result.
This method allows for a method name to be provided in an RPC request so that the client request may be mapped to the correct implementation.
- Parameters:
method_name (
str) – The method name to call.**kwargs – Arbitrary keyword arguments.
- Returns:
InternalRestResponseThe response from the called method.
- error_catcher() Callable[source]
Decorator which converts Python errors into API responses.
This decorator wraps implementation methods to catch all unhandled exceptions and wraps the exception messages in a 500 (Internal Server Error) API response to allow for graceful failures in the event of an error instead of hanging the entire application.
- Parameters:
fn (
Callable) – The method to wrap.- Returns:
CallableThe wrapped method.
- class emulator_engine.services.api.SubcontrollerRouterImpl(subcontroller: EmulatorSubcontroller)[source]
Bases:
RouterImplAPI class which contains implementations of common endpoints for all IP block emulators.
Subclass of
RouterImpl.- Parameters:
subcontroller (
EmulatorSubcontroller) – The emulator subcontroller to process API calls for.