Skip to main content

Rent-A-Bot, your automation resource provider.

Project description

Build Status codecov pipeline status coverage report


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 pursue the same objective as Jenkins Lockable Resource Plugin.

This latter works quite well, but only if you use… well… Jenkins.

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

e.g. - Multiple Jenkins application servers - Mixed automation application, gitlab CI + Jenkins - Shared resources between humans and automates.

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 you resources with additional information:

  • Resource description
  • Lock description
  • Endpoint
  • Tags

How to install and run

Clone the repository from GitLab or GitHub

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

Create a virtual env (here using virtualenv wrapper)

mkvirtualenv rent-a-bot
workon rent-a-bot

Install the package

pip install .   # pip install -e . if you want to install it in editable mode

Add Flask environment variables

export FLASK_APP=rentabot

export FLASK_DEBUG=true # If you need the debug mode

And… run!

flask run

How to use it

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

At this stage you can connect to the front end at http://127.0.0.1:5000/ (assuming your flask app listen to the port 500)

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

Populate the database

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

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

Resource descriptor

The resource descriptor is a YAML file. It’s 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 flask application. The web view should be populated with your resources.

RestFul API

List resources

GET /api/v1.0/resources

e.g.

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

Access to a given resource

GET /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.

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 tests

Tests implementation

Unit tests are done using py.test and coverage

How to run unit tests

python setup.py test

Project details


Download files

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

Files for rent-a-bot, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size rent-a-bot-0.0.2.tar.gz (8.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page