Useful tools to interact with Resource Locker Project
Project description
Useful tools to work with Rlocker project API
Quick Start
Normal installation
pip install rlockertools
Setup
git clone https://github.com/red-hat-storage/rlockertools.git
cd rlockertools
python -m venv venv
source venv/bin/activate
pip install ./
rlock --help
usage: rlock [-h] --server-url SERVER_URL --token TOKEN [--release] [--lock] [--resume-on-connection-error] [--signoff SIGNOFF] [--priority PRIORITY] [--search-string SEARCH_STRING] [--link LINK] [--interval INTERVAL] [--attempts ATTEMPTS]
optional arguments: -h, --help show this help message and exit --server-url SERVER_URL The URL of the Resource Locker Server --token TOKEN Token of the user that creates API calls --release Use this argument to release a resource --lock Use this argument to lock a resource --resume-on-connection-error Use this argument in case you don't want to break queue execution in the middle of waiting for queue status being FINISHED --signoff SIGNOFF Use this when lock=True, locking a resource requires signoff --priority PRIORITY Use this when lock=True, specify the level of priority the resource should be locked --search-string SEARCH_STRING Use this when lock=True, specify the lable or the name of the lockable resource --link LINK Use this when lock=True, specify the link of the CI/CD pipeline that locks the resource --interval INTERVAL Use this when lock=True, how many seconds to wait between each call while checking for a free resource --attempts ATTEMPTS Use this when lock=True, how many times to create an API call that will check for a free resource
## Usage Examples
### To add a queue for locking a resource
```bash
rlock --lock --server-url=your.rlocker.instance.com --token=YOURTOKEN --search-string=nameorlabel --signoff=YOURUNIQUESIGNOFF --priority=3 --interval=15 --attempts=15
To release a locked resource (filtration by signoff only)
rlock --release --server-url=your.rlocker.instance.com --token=YOURTOKEN --signoff=YOURUNIQUESIGNOFF
Logging Configuration
The rlockertools library uses Python's standard logging module. By default, logging is disabled (NullHandler). To enable logging output, configure it in your application:
Basic Configuration
import logging
# Configure logging at the start of your application
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
Advanced Configuration
import logging
# Create a logger for rlockertools
logger = logging.getLogger('rlockertools')
logger.setLevel(logging.DEBUG)
# Create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
# Create formatter and add it to the handler
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
# Add the handler to the logger
logger.addHandler(ch)
Log Levels
DEBUG: Detailed information, typically for diagnosing problems (includes API responses)INFO: General informational messages (connection status, resource operations)WARNING: Warning messages (retries, timeouts)ERROR: Error messages (failures, connection errors)
Change log
[0.3.8] - 2021-03-15
Initial build
[0.3.9] - 2021-07-15
Move to new repo + bug fix
[0.3.10] - 2021-07-15
Fix build issue
[0.3.11] - 2021-07-19
Suppress the logs Show safe errors when beating a queue returns !=200 status code
[0.4] - 2022-04-12
Allow **datakwargs in the change queue method. This is necessary to allow modification of the data section once a queue is changing
[0.4.1] - 2022-04-13
Show more output in get_queue method in case of non 200 status code
[0.4.2] - 2022-04-17
Address item assignment for str, should be fixed to a dictionary in change queue method
[0.4.3] - 2022-04-28
Adding log file in order to track after the queue id number once executing from the rlock entrypoint. Reason: In order to to API calls about the queue, we need to save it in some readable location
[0.4.4] - 2022-06-09
Adding support for --check argument which will return if the given --search-string has available resources
by label or a name. Commit number: #15
Usage example:
rlock --check --search-string=aws-east-2 --token=$token --server-url=$SERVER_URL
[0.4.5] - 2022-07-26
Fixing JSON parsing for the data section in a queue, which was not fixed totally in 0.4.2
[0.4.6] - 2026-02-18
Limit the output from rlock when waiting for resource
[0.4.7] - 2026-04-16
update intervals when waiting for resource, use python logging module instead of direct print
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file rlockertools-0.4.7.tar.gz.
File metadata
- Download URL: rlockertools-0.4.7.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
683ff075f9bd7c68a7a77af9f7dbb35755ae56c3ddcf912a7f8944556a2f2605
|
|
| MD5 |
892666bf01a0b64f2289960934abba18
|
|
| BLAKE2b-256 |
467e52a1b9114e32a3a300453e80277a97dd858318edde8c09fa77a187ec9683
|