|
@@ -4,27 +4,44 @@ API for managing virtual machines on Ubuntu using FastAPI and libvirt.
|
|
|
|
|
|
|
|
## Installation
|
|
## Installation
|
|
|
|
|
|
|
|
-1. Install dependencies:
|
|
|
|
|
|
|
+1. Create and activate a virtual environment:
|
|
|
```bash
|
|
```bash
|
|
|
- pip install -e .
|
|
|
|
|
|
|
+ python3 -m venv venv
|
|
|
|
|
+ source venv/bin/activate
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-2. Ensure libvirt is installed on the system:
|
|
|
|
|
|
|
+2. Install dependencies:
|
|
|
```bash
|
|
```bash
|
|
|
- sudo apt install libvirt-daemon-system
|
|
|
|
|
|
|
+ pip install -r requirements.txt
|
|
|
|
|
+ ```
|
|
|
|
|
+
|
|
|
|
|
+3. Ensure libvirt is installed on the system:
|
|
|
|
|
+ ```bash
|
|
|
|
|
+ sudo apt install libvirt-daemon-system libvirt-dev pkg-config
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
## Running the API
|
|
## Running the API
|
|
|
|
|
|
|
|
```bash
|
|
```bash
|
|
|
-uvicorn app.main:app --reload
|
|
|
|
|
|
|
+source venv/bin/activate
|
|
|
|
|
+uvicorn app.main:app --reload --host 0.0.0.0
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-The API will be available at http://127.0.0.1:8000
|
|
|
|
|
|
|
+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
|
|
## Endpoints
|
|
|
|
|
|
|
|
- GET / : Root message
|
|
- GET / : Root message
|
|
|
- GET /vms : List all VMs
|
|
- GET /vms : List all VMs
|
|
|
-- POST /vms/{vm_id}/start : Start a VM
|
|
|
|
|
-- POST /vms/{vm_id}/stop : Stop a VM
|
|
|
|
|
|
|
+- POST /vms?name={name}&template={template} : Create a new VM from a template
|
|
|
|
|
+- 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.
|
|
|
|
|
+
|
|
|
|
|
+Example template: `templates/ubuntu.xml`
|