This project, named "Broker", is a command-line tool written in Python. It acts as an infrastructure middleman, providing a common interface to provision and manage virtual machines and containers across various services like Ansible Tower, Beaker, Docker, Podman, and OpenStack. The tool is built using the click library for its command-line interface and dynaconf for configuration management.
The core logic resides in the Broker class (broker/broker.py), which manages the lifecycle of hosts (VMs or containers). It supports checking out, checking in, extending leases, and executing arbitrary actions on these hosts. The application is designed to be extensible, with a provider-based architecture that allows for adding new services easily.
The project uses uv for dependency management. The core dependencies are listed in pyproject.toml and include click, dynaconf, logzero, requests, rich, rich_click, and ruamel.yaml. Optional dependencies for specific providers are also defined.
To install the project and its development dependencies, run the following command:
uv pip install "broker[dev] @ ."The main entry point for the CLI is broker.commands:cli. After installation, the tool can be run using the broker command:
broker --helpThis project has strict code quality and formatting standards. Each change you make should ensure conformity by running the pre-commit checks.
# ensure you're in the virtual environment
source .venv/bin/activate
# run pre-commit
pre-commit run --all-filesThe project uses pytest for testing. The tests are located in the tests/ directory. To run the unit tests, use the following command:
pytest -v tests/ --ignore tests/functional --ignore tests/test_ssh.pySSH tests should only be executed when a change is made that could impact the behavior of all or a specific ssh backend (underlying ssh library; hussh, ssh2-python, paramiko). Before running the ssh-specific tests, make sure the correct dependency is installed.
uv pip install "broker[hussh] @ ."Then use the following command to run the tests, targeting the specific ssh backend.
BROKER_SSH__BACKEND=hussh pytest -v tests/test_ssh.pyTox is likely the best way to run the tests for this project, since it handles everything for you.
# General unit tests across all supported python versions
tox
# Quick tests that also do linting
tox -e quick
# Functional tests for satlab (AnsibleTower)
tox -e func-satlab
# Tests for a specific ssh backend
tox -e ssh-hussh
# Run all ssh backend tests sequentially
tox -m ssh- Linting: The project uses
rufffor linting. The configuration is inpyproject.toml. - Pre-commit Hooks: The project uses
pre-committo run checks before committing. The configuration is in.pre-commit-config.yaml. - Configuration: The application uses a
broker_settings.yamlfile for configuration. An example file is provided asbroker_settings.yaml.example. - Providers: The provider-specific logic is located in the
broker/providers/directory. Each provider is a class that inherits from a base provider class and implements methods for actions likecheckout,checkin, etc. - CLI: The command-line interface is defined in
broker/commands.pyusingrich_click. Commands are organized into groups for better usability.