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:

Attributes Summary

image_service

Global image service, from the ProcessContext.

lab_manager

Global lab manager, from the ProcessContext.

prepuller

Global prepuller, from the ProcessContext.

Methods Summary

aclose()

Shut down the factory.

create_docker_storage()

Create a Docker storage client.

create_gafaelfawr_client()

Create client to look up users in Gafaelfawr.

create_lab_builder()

Create builder service for user labs.

create_lab_storage()

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_background_services()

Start global background services managed by the process context.

stop_background_services()

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. :rtype: None

create_docker_storage()#

Create a Docker storage client.

Only used by the test suite.

Returns:

Newly-created Docker storage client.

Return type:

DockerStorageClient

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:

GafaelfawrStorageClient

create_lab_builder()#

Create builder service for user labs.

Only used by the test suite.

Returns:

Newly-created lab builder.

Return type:

LabBuilder

create_lab_storage()#

Create Kubernetes storage object for user labs.

Only used by the test suite.

Returns:

Newly-created lab storage.

Return type:

LabStorage

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:

None

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. :rtype: None

async stop_background_services()#

Stop global background services managed by the process context.

These are normally stopped when closing down the global context, but the test suite may want to stop and start them independently.

Only used by the test suite. :rtype: None