API for managing virtual machines on Ubuntu using FastAPI and libvirt.
Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate
Install dependencies:
pip install -r requirements.txt
Ensure libvirt is installed on the system:
sudo apt install libvirt-daemon-system libvirt-dev pkg-config
Set the environment variable for the images path if needed (default is /var/lib/libvirt/images):
export LIBVIRT_IMAGES_PATH=/path/to/images
source venv/bin/activate
uvicorn app.main:app --reload --host 0.0.0.0
The API will be available at http://0.0.0.0:8000
Access the interactive documentation at http://0.0.0.0:8000/docs
VM templates are XML files stored in the templates/ directory. Each template defines the base configuration for a VM. When creating a VM, the name in the XML is replaced with the provided name, and the disk file path is set using the LIBVIRT_IMAGES_PATH environment variable (default: /var/lib/libvirt/images) plus the provided disk name.
Example template: templates/ubuntu.xml