-
Notifications
You must be signed in to change notification settings - Fork 21
Dev: Duffy Components
Duffy contains several “runnable“ components with differing sets of dependencies, which are encoded as package extras of the duffy
Python package.
The Duffy core contains the code to run the CLI program duffy
and to read and validate YAML-encoded configuration files.
Duffy packages and modules
-
duffy.api_models
: Pydantic models specifying API valid requests and responses -
duffy.cli
: Theduffy
CLI program -
duffy.configuration
: Code to read and validate YAML configuration files -
duffy.exceptions
: Custom exception types -
duffy.misc
: Custom Pydantic types used in configuration and the API -
duffy.util
: Miscellaneous helper code -
duffy.version
: Extract the Duffy version from Python package metadata
Dependencies
- Python 3.8 or later
-
PyYAML
: To read YAML configuration files -
click
: To define the CLI commands and options/arguments -
pydantic
: To specify the configuration file and API structures
The main purpose of the Duffy API web app is to manage node sessions. Tenants request what types and numbers of nodes they need in a session, the web app looks up in the database if the request can be served – i.e. if enough nodes of the requested type(s) are available – and if so, allocate the nodes into the session, installs the tenant’s SSH key onto the nodes and return information about the nodes to the tenant so they can use them. When tenants are done using the nodes, they retire the session, and the web app tells the backend task workers to deprovision the nodes.
Duffy packages and modules
-
duffy.app
: The web app -
duffy.database
: The SQLAlchemy database model -
duffy.nodes.context
: To (de)contextualize nodes, i.e. install tenants’ SSH keys onto them and remove them again -
duffy.nodes.pools
: To provide information about configured node pools -
duffy.tasks
: The backend tasks called from the web app
Dependencies
-
SQLAlchemy
: To actually talk to the database -
alembic
: To migrate database schemas and contents -
bcrypt
: To store only hashes of API keys and validate them -
fastapi
: High performance asynchronous web framework -
uvicorn
: ASGI web server -
celery
: To communicate with backend task workers -
aiodns
*: To asynchronously look up host names from DNS -
ansible-runner
*: To run Ansible playbooks -
Jinja2
*: To expand templates in configuration -
jmespath
*: To enable thejson_query
filter in Jinja templates -
pottery
*: To lock critical sections of backend tasks
*: This dependency is pulled in by importing duffy.tasks
which is needed to communicate with backend task workers.
This web app sits between legacy API clients and the current API, serving the former and acting as a client to the latter. Its purpose is to translate back and forth between the legacy and current protocols.
Duffy packages and modules
-
duffy.legacy
: Pydantic models specifying API valid requests and responses
Dependencies
-
httpx
: To asynchronously communicate with the current API over HTTP -
Jinja2
: To enable Jinja macros and filters in pool mapping configuration
The Celery task workers perform background work that a) potentially takes longer (like provisioning and deprovisioning nodes) and/or b) needs to be done on a regular basis (like expiring sessions past their configured lifetime).
Duffy packages and modules
-
duffy.tasks
: The backend tasks called from the web app -
duffy.nodes.pools
,duffy.nodes.mechanisms
: To maintain configured fill levels of nodes pools by provisioning new nodes into them when already provisioned ones are put into use
Dependencies
-
celery
: To define remotely callable tasks -
aiodns
: To asynchronously look up host names from DNS -
ansible-runner
: To run Ansible playbooks -
Jinja2
: To expand templates in configuration -
jmespath
: To enable thejson_query
filter in Jinja templates -
pottery
: To lock critical sections of backend tasks
The duffy client
CLI application lets users run commonly used functions of the API from the command line. It can format output as JSON, YAML or “flat“, which lends itself well for processing from shell scripts.
Duffy packages and modules
-
duffy.client
: TheDuffyClient
class wrapping access to the API -
duffy.client.formatters
: Classes implementing different result formatting options
Dependencies
-
httpx
: To communicate with the Duffy API over HTTP