Skip to main content

Rent-A-Bot, your automation resource provider.

Project description

Rent-A-Bot

Rent-a-bot, your automation resource provider.

Exclusive access to a static resource is a common problem in automation. Rent-a-bot allows you to abstract your resources and lock them to prevent any concurrent access.

Purpose

Rent-a-bot pursues the same objective as Jenkins Lockable Resource Plugin.

The plugin works quite well, but only if you use... well... Jenkins.

Rent-A-Bot's purpose is to fill the same needs in an environment where multiple automation applications exist.

Examples:

  • Multiple Jenkins application servers
  • Mixed automation applications (e.g., GitHub Actions + Jenkins)
  • Shared resources between humans and automation systems

What is a resource?

A resource is defined by a name and the existence of a lock token indicating if the resource is locked.

Optional available fields help you customize your resources with additional information:

  • Resource description
  • Lock description
  • Endpoint
  • Tags

How to install and run

Prerequisites

This project uses uv for fast, reliable Python package management.

Install uv:

curl -LsSf https://astral.sh/uv/install.sh | sh

Or on macOS:

brew install uv

Installation

Clone the repository from GitHub:

git clone git@github.com:cpoisson/rent-a-bot.git

Navigate to the project directory:

cd rentabot

Install the package and dependencies using uv:

uv sync              # Install dependencies and create virtual environment
uv pip install -e .  # Install the package in editable mode

How to run

Using the CLI (recommended)

The easiest way to run Rent-A-Bot is using the built-in CLI:

# Run directly with uvx (no installation needed)
uvx rentabot

# Or install and run
uv pip install -e .
rentabot

CLI Options:

rentabot --help                           # Show help
rentabot --version                        # Show version
rentabot --config path/to/config.yaml     # Use specific config file
rentabot --host 0.0.0.0 --port 8080       # Custom host and port
rentabot --reload                         # Enable auto-reload for development
rentabot --log-level debug                # Set log level

Configuration File Discovery:

The CLI automatically searches for configuration files in this order:

  1. Explicit --config argument
  2. ./.rentabot.yaml or ./rentabot.yaml in current directory
  3. ~/.rentabot/config.yaml in home directory
  4. RENTABOT_RESOURCE_DESCRIPTOR environment variable
  5. No config (starts with empty resources)

Using uvicorn directly

You can also start the FastAPI server directly:

# With environment variable
RENTABOT_RESOURCE_DESCRIPTOR="path/to/config.yaml" uvicorn rentabot.main:app --reload --port 8000

# Or with uv
uv run uvicorn rentabot.main:app --reload --port 8000

The API will be available at:

How to use it

Alright, rent-a-bot is up and running.

At this stage you can connect to the web interface at http://127.0.0.1:8000/ or explore the interactive API documentation at http://127.0.0.1:8000/docs.

You will notice that the resource list is empty (dang...), let's populate it.

Populate the resources

You will need a resource descriptor file to populate the resources at startup.

RENTABOT_RESOURCE_DESCRIPTOR="/absolute/path/to/your/resource/descriptor.yml"

Resource descriptor

The resource descriptor is a YAML file. Its purpose is to declare the resources you want to make available on rent-a-bot.

# Resources Description
# This file describes resources to populate in the database at rent-a-bot startup

coffee-machine:
    description: "Kitchen coffee machine"
    endpoint: "tcp://192.168.1.50"
    tags: "coffee kitchen food"

3d-printer-1:
    description: "Basement 3d printer 1"
    endpoint: "tcp://192.168.1.60"
    tags: "3d-printer basement tool"

another-resource:
    description: "yet another resource"
    endpoint: ""
    tags: ""

Once set, (re)start the application with the environment variable:

RENTABOT_RESOURCE_DESCRIPTOR=/path/to/your/resources.yaml uvicorn rentabot.main:app --reload --port 8000

The web view should be populated with your resources.

RESTful API

List resources

GET /rentabot/api/v1.0/resources

e.g.

curl -X GET -i http://localhost:8000/rentabot/api/v1.0/resources

Access to a given resource

GET /rentabot/api/v1.0/resources/{resource_id}

e.g.

curl -X GET -i http://localhost:5000/rentabot/api/v1.0/resources/2

Lock a resource

POST /api/v1.0/resources/{resource_id}/lock

e.g.

curl -X POST -i http://localhost:5000/rentabot/api/v1.0/resources/6/lock

Note: If the resource is available, a lock-token will be returned. Otherwise an error code is returned.

Lock a resource using it's resource id (rid), name (name) or tag (tag).

POST /api/v1.0/resources/lock

e.g.

curl -X POST -i http://localhost:5000/rentabot/api/v1.0/resources/lock\?rid\=6
curl -X POST -i http://localhost:5000/rentabot/api/v1.0/resources/lock\?name\=coffee-maker
curl -X POST -i http://localhost:5000/rentabot/api/v1.0/resources/lock\?tag\=coffee\&tag\=kitchen

Notes:

  • If multiple available resources match the criteria, the first available will be returned.
  • If criteria types are exclusive, resource id is prioritized over the name and tags, and name is prioritized over tags.

Unlock a resource

POST /api/v1.0/resources/{resource_id}/unlock?lock-token={resource/lock/token}

curl -X POST -i http://localhost:5000/rentabot/api/v1.0/resources/6/unlock\?lock-token\={resource/lock/token}

Note: If the resource is already unlocked or the lock-token is not valid, an error code is returned.

How to test

Test implementation

Unit tests are done using pytest and coverage.

How to run unit tests

uv run pytest

Or with the virtual environment activated:

source .venv/bin/activate
pytest

Helpful documentation used to design this application

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rentabot-0.3.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rentabot-0.3.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file rentabot-0.3.0.tar.gz.

File metadata

  • Download URL: rentabot-0.3.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for rentabot-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b8b1bccb32f8789ba4b6eaa29099718e2a4db2867435d0894e19083c0efd6696
MD5 fc1e1e6dac1806a11921494e6ba99fb4
BLAKE2b-256 933c84fca1ff9f3e393275c4ddb38001113a0084166ec27626504eac095a4185

See more details on using hashes here.

File details

Details for the file rentabot-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: rentabot-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for rentabot-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86af0a1cc1546332b9a5c19ea9926643424cf5ecdf24217968ff93b1da17e5a4
MD5 6cce6c0037ba3bbb2cf8b79e799a32b5
BLAKE2b-256 c81fd43969e1c22e6cab23ec405b4548acd6f9b004ec7c7c25e086392d949995

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page