Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

r2lab-api

REST API for the R2lab wireless testbed: it manages users, slices, leases, and registrations. The code is in https://github.com/fit-r2lab/r2lab-api; it is built with FastAPI + SQLModel + PostgreSQL.

For authentication, day-to-day operations, database backups and upgrades, see the operating guide.

Development

git clone git@github.com:fit-r2lab/r2lab-api.git
cd r2lab-api
uv venv && uv sync
cp deploy/.env.example .env    # edit as needed (set R2LAB_MAIL_MODE=console for dev)
alembic upgrade head
uvicorn r2lab_api.app:app --reload --port 9999

API docs at https://r2labapi.inria.fr/docs

Tests

pytest

Tests use an in-memory SQLite database — no PostgreSQL needed.

Deployment

The API runs on a Fedora VM (r2labapi.inria.fr) as a systemd service. The code lives in /root/r2lab-api/ (git clone, no RPM).

First-time setup

ssh root@r2labapi.inria.fr
git clone https://github.com/fit-r2lab/r2lab-api.git /root/r2lab-api
cd /root/r2lab-api
deploy/setup.sh path/to/r2lab.pgdump

This installs PostgreSQL, Python, creates the venv, restores the database, and enables the systemd services.

After setup, review and adjust /root/r2lab-api/.env (see .env.example for reference).

Deploying code updates

Normally there is nothing to do: auto-update pulls the repo and runs deploy/update.sh, which syncs the venv and restarts the service; database migrations are applied when the service starts. By hand:

cd /root/r2lab-api
git pull
.venv/bin/alembic upgrade head   # only if there are new migrations
systemctl restart r2lab-api

Files in deploy/

FileWhat it does
r2lab-api.serviceSystemd unit for the API (uvicorn on local port 9999)
r2lab-backup.serviceOneshot that runs pg_dump
r2lab-backup.timerTriggers the backup every hour
r2lab-slice-warning.serviceOneshot that warns members of soon-to-expire slices
r2lab-slice-warning.timerTriggers the slice-expiry warning once a day
.env.exampleTemplate for production configuration
setup.shFirst-time setup script
restore-db.shRestore database from a pgdump file
pg-upgrade.shDump/restore helper for PostgreSQL major upgrades