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: LoggingBase

API client class which sets up an API router and common routes for an IP block emulator.

Parameters:
  • bitstream_emulator_id (str) – The unique ID of the bitstream emulator to generate an API router for.

  • ip_block_id (str) – The unique ID of the IP block to generate an API router for. Default is the empty string (i.e. this client is for a top-level controller).

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: LoggingBase

API 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:

InternalRestResponse The 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:

Callable The wrapped method.

class emulator_engine.services.api.SubcontrollerRouterImpl(subcontroller: EmulatorSubcontroller)[source]

Bases: RouterImpl

API 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.