Adapter

To use this library you need adapter classes. Adapter classes are used to connect the lab orchestrator lib to your database.

Take a look at the controller references to see which adapters you need when you want to use only a few controllers. But to use all features of the library you need to implement all adapters:

Note

When you use django there is already one library that contains all adapters to use the lab orchestrator lib with django: LabOrchestratorLib-DjangoAdapter. This library also contains an example Django API. On how to use this adapter take a look at the documentation in the link.

Note

The LabOrchestratorLib-FlaskSQLAlchemyAdapter project is not maintained and not working, but if you need an adapter for Flask-SQLAlchemy you can base them on this project.

After implementing the adapters you can create a controller collection by passing instances of the adapters to the lab_orchestrator_lib.controllers.controller_collection.create_controller_collection(...) function. This function takes all adapters, one api registry and a secret key. More about this is part of Controller documentation.

User Adapter Interface

class lab_orchestrator_lib.database.adapter.UserAdapterInterface

Adapter that is used to connect the user model to the database.

Contains only get methods, because the lab_controller_lib won’t create or delete users.

Methods

get(identifier)

Gives a specific user.

Parameters

identifier (Union[str, int]) – The identifier of the user.

Return type

User

Returns

A specific user.

Raises

NotImplementedError – Method needs to be implemented.

get_all()

Gives a list of all users.

Return type

List[User]

Returns

A list of all users.

Raises

NotImplementedError – Method needs to be implemented.

Docker Image Adapter Interface

class lab_orchestrator_lib.database.adapter.DockerImageAdapterInterface

Adapter that is used to connect the docker image model to the database.

Methods

create(name, description, url)

Creates a docker image and saves it to the database.

Parameters
  • name (str) – Name of the docker image.

  • description (str) – Description of the docker image.

  • url (str) – Url of the docker image.

Return type

DockerImage

Returns

A newly added docker image.

Raises

NotImplementedError – Method needs to be implemented.

delete(identifier)

Deletes a specific docker image.

Parameters

identifier (Union[str, int]) – The identifier of the docker image.

Return type

None

Returns

None

Raises

NotImplementedError – Method needs to be implemented.

filter(**kwargs)

Filters the docker images and returns all docker images that matches the filter criteria.

The database should be filtered by the attributes and belonging values that are given in the kwargs dictionary.

Parameters

kwargs (Dict[str, Any]) – A dictionary with filters.

Return type

List[DockerImage]

Returns

All docker images that matches the filters.

Raises

NotImplementedError – Method needs to be implemented.

get(identifier)

Gives a specific docker image.

Parameters

identifier (Union[str, int]) – The identifier of the docker image.

Return type

DockerImage

Returns

The specific docker image.

Raises

NotImplementedError – Method needs to be implemented.

get_all()

Gives all docker images.

Return type

List[DockerImage]

Returns

A list of all docker images.

Raises

NotImplementedError – Method needs to be implemented.

save(obj)

Saves changes of the docker image to the database.

Parameters

obj (DockerImage) – The docker image object that contains changes.

Return type

DockerImage

Returns

The docker image.

Raises

NotImplementedError – Method needs to be implemented.

Lab Docker Image Adapter Interface

class lab_orchestrator_lib.database.adapter.LabDockerImageAdapterInterface

Adapter that is used to connect the lab docker image model to the database.

Methods

create(lab_id, docker_image_id, docker_image_name)

Creates a lab docker image and saves it to the database.

Parameters
  • lab_id (Union[str, int]) – Id of the lab.

  • docker_image_id (Union[str, int]) – Id of the docker image.

  • docker_image_name (str) – Name of the VM.

Return type

LabDockerImage

Returns

A newly added lab docker image.

Raises

NotImplementedError – Method needs to be implemented.

delete(identifier)

Deletes a specific lab docker image.

Parameters

identifier (Union[str, int]) – The identifier of the lab docker image.

Return type

None

Returns

None

Raises

NotImplementedError – Method needs to be implemented.

filter(**kwargs)

Filters the lab docker images and returns all lab docker images that matches the filter criteria.

The database should be filtered by the attributes and belonging values that are given in the kwargs dictionary.

Parameters

kwargs (Dict[str, Any]) – A dictionary with filters.

Return type

List[LabDockerImage]

Returns

All lab docker images that matches the filters.

Raises

NotImplementedError – Method needs to be implemented.

get(identifier)

Gives a specific lab docker image.

Parameters

identifier (Union[str, int]) – The identifier of the lab docker image.

Return type

LabDockerImage

Returns

The specific lab docker image.

Raises

NotImplementedError – Method needs to be implemented.

get_all()

Gives all lab docker images.

Return type

List[LabDockerImage]

Returns

A list of all lab docker images.

Raises

NotImplementedError – Method needs to be implemented.

save(obj)

Saves changes of the lab docker image to the database.

Parameters

obj (LabDockerImage) – The lab docker image object that contains changes.

Return type

LabDockerImage

Returns

The lab docker image.

Raises

NotImplementedError – Method needs to be implemented.

Lab Adapter Interface

class lab_orchestrator_lib.database.adapter.LabAdapterInterface

Adapter that is used to connect the lab model to the database.

Methods

create(name, namespace_prefix, description)

Creates a lab and saves it to the database.

Parameters
  • name (str) – Name of the lab.

  • namespace_prefix (str) – Namespace prefix of the lab.

  • description (str) – Description of the lab.

Return type

Lab

Returns

A newly added lab.

Raises

NotImplementedError – Method needs to be implemented.

delete(identifier)

Deletes a specific lab.

Parameters

identifier (Union[str, int]) – The identifier of the lab.

Return type

None

Returns

None

Raises

NotImplementedError – Method needs to be implemented.

filter(**kwargs)

Filters the labs and returns all labs that matches the filter criteria.

The database should be filtered by the attributes and belonging values that are given in the kwargs dictionary.

Parameters

kwargs (Dict[str, Any]) – A dictionary with filters.

Return type

List[Lab]

Returns

All labs that matches the filters.

Raises

NotImplementedError – Method needs to be implemented.

get(identifier)

Gives a specific lab.

Parameters

identifier (Union[str, int]) – The identifier of the lab.

Return type

Lab

Returns

The specific lab.

Raises

NotImplementedError – Method needs to be implemented.

get_all()

Gives all labs.

Return type

List[Lab]

Returns

A list of all labs.

Raises

NotImplementedError – Method needs to be implemented.

save(obj)

Saves changes of the lab to the database.

Parameters

obj (Lab) – The lab object that contains changes.

Return type

Lab

Returns

The lab.

Raises

NotImplementedError – Method needs to be implemented.

Lab Instance Adapter Interface

class lab_orchestrator_lib.database.adapter.LabInstanceAdapterInterface

Adapter that is used to connect the lab instance model to the database.

Methods

create(lab_id, user_id)

Creates a lab instance and saves it to the database.

Parameters
  • lab_id (Union[str, int]) – Lab id of the lab instance.

  • user_id (Union[str, int]) – User id of the lab instance.

Return type

LabInstance

Returns

A newly added lab instance.

Raises

NotImplementedError – Method needs to be implemented.

delete(identifier)

Deletes a specific lab instance.

Parameters

identifier (Union[str, int]) – The identifier of the lab instance.

Return type

None

Returns

None

Raises

NotImplementedError – Method needs to be implemented.

filter(**kwargs)

Filters the lab instances and returns all lab instances that matches the filter criteria.

The database should be filtered by the attributes and belonging values that are given in the kwargs dictionary.

Parameters

kwargs (Dict[str, Any]) – A dictionary with filters.

Return type

List[LabInstance]

Returns

All lab instances that matches the filters.

Raises

NotImplementedError – Method needs to be implemented.

get(identifier)

Gives a specific lab instance.

Parameters

identifier (Union[str, int]) – The identifier of the lab instance.

Return type

LabInstance

Returns

The specific lab instance.

Raises

NotImplementedError – Method needs to be implemented.

get_all()

Gives all lab instances.

Return type

List[LabInstance]

Returns

A list of all lab instances.

Raises

NotImplementedError – Method needs to be implemented.

save(obj)

Saves changes of the lab instance to the database.

Parameters

obj (LabInstance) – The lab instance object that contains changes.

Return type

LabInstance

Returns

The lab instance.

Raises

NotImplementedError – Method needs to be implemented.