説明なし

Celestino Rey 153a5fab91 Se puede elegir el nombre del disco 7 ヶ月 前
.github 23108c30f6 Primer commit 7 ヶ月 前
app 153a5fab91 Se puede elegir el nombre del disco 7 ヶ月 前
templates 153a5fab91 Se puede elegir el nombre del disco 7 ヶ月 前
.gitignore 23108c30f6 Primer commit 7 ヶ月 前
README.md 153a5fab91 Se puede elegir el nombre del disco 7 ヶ月 前
pyproject.toml 23108c30f6 Primer commit 7 ヶ月 前
requirements.txt 45033affaf Api funcionando con listar y start y stop solo mock 7 ヶ月 前

README.md

VirtManager

API for managing virtual machines on Ubuntu using FastAPI and libvirt.

Installation

  1. Create and activate a virtual environment:

    python3 -m venv venv
    source venv/bin/activate
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Ensure libvirt is installed on the system:

    sudo apt install libvirt-daemon-system libvirt-dev pkg-config
    

Running the API

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

Endpoints

  • GET / : Root message
  • GET /vms : List all VMs
  • POST /vms?name={name}&template={template}&disk={disk} : Create a new VM from a template with custom disk name
  • GET /vms/{vm_id}/start : Start a VM by ID
  • GET /vms/{vm_id}/stop : Stop a VM by ID
  • DELETE /vms/{vm_name} : Delete a VM by name

Templates

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