R507 is a REST API developed with FastAPI to manage a fleet of computers. It allows you to create, read, update, and delete computers, as well as retrieve their resources (RAM, CPU, OS).
- Add a computer with its specifications (MAC, IP, OS, RAM, etc.)
- Update information for an existing computer
- Delete a computer
- List all computers
- Retrieve memory usage, CPU load, and OS information via SSH (if configured)
- API compatible with unit tests and in-memory cache
- Python 3.12
- FastAPI for the REST API
- SQLModel + SQLite for persistence
- Paramiko for SSH connections
- Uvicorn as the ASGI server
- Poetry for dependency management
- Docker for containerization
Build the Docker image:
docker build -t R507 -f app3.Dockerfile .Run the container:
docker run -d -p 8000:8000 R507Access the API:
- Base URL:
http://localhost:8000 - Interactive Swagger documentation:
http://localhost:8000/docs - ReDoc documentation:
http://localhost:8000/redoc
Install dependencies:
poetry installRun the API locally:
poetry run uvicorn code.main:app --reloadRun unit tests:
poetry run pytestor via bash:
alambic.sh # export db
linter.sh # show if code is well write
lunch.sh # lunch docker and api
test_fonctionnels.sh # test fonctionnels of api
test_unitaires.sh # test unitaires of api| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Welcome message |
| GET | /ordinateurs |
List all computers |
| POST | /add_ordinateur |
Add a computer |
| PUT | /edit_ordinateur |
Update an existing computer |
| DELETE | /delete_ordinateur/{ip} |
Delete a computer by IP |
| GET | /memory/{ip} |
Get free and total memory |
| GET | /cpu_load/{ip} |
Get CPU load |
| GET | /os_release/{ip} |
Get OS information via SSH |
r507/
├─ code/
│ ├─ main.py # FastAPI application
│ ├─ models.py # Pydantic and SQLModel models
│ ├─ db.py # Database and session management
├─ tests/
│ ├─ unit/
│ │ ├─ test_main.py # Unit tests for the API
├─ pyproject.toml # Poetry dependencies
├─ poetry.lock
├─ README.md
└─ app3.Dockerfile # Dockerfile for building the image- The API uses an in-memory cache (
app.state.ordinateurs) to speed up tests. - Unit tests reset the cache on each startup.
- SSH connections are optional but required to retrieve certain system information.
Malo – 126970037+Malaudos35@users.noreply.github.com https://github.com/Malaudos35/R507