Factory¶
- class controller.factory.Factory(context, logger)¶
Bases:
object
Build lab controller components.
Uses the contents of a
ProcessContext
to construct the components of the application on demand.- Parameters:
context (
ProcessContext
) – Shared process context.logger (
BoundLogger
) – Logger to use for messages.
Attributes Summary
Global image service, from the
ProcessContext
.Global lab manager, from the
ProcessContext
.Global prepuller, from the
ProcessContext
.Methods Summary
aclose
()Shut down the factory.
Create a Docker storage client.
Create client to look up users in Gafaelfawr.
Create builder service for user labs.
Create Kubernetes storage object for user labs.
set_logger
(logger)Replace the internal logger.
standalone
(cls, config)Async context manager for lab controller components.
Start global background services managed by the process context.
Stop global background services managed by the process context.
Attributes Documentation
- image_service¶
Global image service, from the
ProcessContext
.Only used by tests; handlers have access to the image service via the request context.
- lab_manager¶
Global lab manager, from the
ProcessContext
.Only used by tests; handlers have access to the lab manager via the request context.
- prepuller¶
Global prepuller, from the
ProcessContext
.Only used by tests; handlers don’t need access to the prepuller.
Methods Documentation
- async aclose()¶
Shut down the factory.
After this method is called, the factory object is no longer valid and must not be used.
- Return type:
- create_docker_storage()¶
Create a Docker storage client.
Only used by the test suite.
- Returns:
Newly-created Docker storage client.
- Return type:
- Raises:
NotConfiguredError – Raised if the image source is not configured to use Docker.
- create_gafaelfawr_client()¶
Create client to look up users in Gafaelfawr.
- Returns:
Newly-created Gafaelfawr client.
- Return type:
- create_lab_builder()¶
Create builder service for user labs.
Only used by the test suite.
- Returns:
Newly-created lab builder.
- Return type:
- create_lab_storage()¶
Create Kubernetes storage object for user labs.
Only used by the test suite.
- Returns:
Newly-created lab storage.
- Return type:
- set_logger(logger)¶
Replace the internal logger.
Used by the context dependency to update the logger for all newly-created components when it’s rebound with additional context.
- Parameters:
logger (
BoundLogger
) – New logger.- Return type:
- classmethod standalone(cls, config)¶
Async context manager for lab controller components.
Intended for background jobs or the test suite.
- Parameters:
config (
Config
) – Lab controller configuration- Yields:
Factory – Newly-created factory. Must be used as a context manager.
- Return type:
AsyncIterator
[Self
]
- async start_background_services()¶
Start global background services managed by the process context.
These are normally started by the context dependency when running as a FastAPI app, but the test suite may want the background processes running while testing with only a factory.
Only used by the test suite.
- Return type: