|
|
@@ -83,10 +83,10 @@ async def stop_vm(vm_name: str):
|
|
|
return {"error": str(e)}
|
|
|
|
|
|
@app.post("/vms")
|
|
|
-async def create_vm(name: str, memory: int, disk_size: int, iso: str):
|
|
|
+async def create_vm(name: str, memory: int, disk_size: int, cpus: int = 1, iso: str = ""):
|
|
|
if not iso:
|
|
|
return {"error": "ISO path is required"}
|
|
|
- images_path = os.environ.get('LIBVIRT_IMAGES_PATH', '/mnt/vms/images')
|
|
|
+ images_path = os.environ.get('LIBVIRT_IMAGES_PATH', '/var/lib/libvirt/images')
|
|
|
disk_path = f"{images_path}/{name}.qcow2"
|
|
|
iso_path = iso # iso ya es la ruta completa desde el select
|
|
|
|
|
|
@@ -108,7 +108,7 @@ async def create_vm(name: str, memory: int, disk_size: int, iso: str):
|
|
|
<name>{name}</name>
|
|
|
<memory unit='MiB'>{memory}</memory>
|
|
|
<currentMemory unit='MiB'>{memory}</currentMemory>
|
|
|
- <vcpu placement='static'>1</vcpu>
|
|
|
+ <vcpu placement='static'>{cpus}</vcpu>
|
|
|
<os>
|
|
|
<type arch='x86_64' machine='pc-i440fx-6.2'>hvm</type>
|
|
|
<boot dev='cdrom'/>
|
|
|
@@ -169,7 +169,7 @@ async def create_vm(name: str, memory: int, disk_size: int, iso: str):
|
|
|
try:
|
|
|
domain = conn.defineXML(xml_template)
|
|
|
domain.create()
|
|
|
- return {"message": f"VM {name} created with {memory} MiB memory, {disk_size}G disk, booting from {iso}"}
|
|
|
+ return {"message": f"VM {name} created with {cpus} CPUs, {memory} MiB memory, {disk_size}G disk, booting from {iso}"}
|
|
|
except Exception as e:
|
|
|
return {"error": str(e)}
|
|
|
|
|
|
@@ -239,7 +239,7 @@ async def set_boot_order(vm_name: str, boot_order: BootOrder):
|
|
|
|
|
|
@app.get("/isos")
|
|
|
async def list_isos():
|
|
|
- images_path = os.environ.get('LIBVIRT_IMAGES_PATH', '/mnt/vms/images')
|
|
|
+ images_path = os.environ.get('LIBVIRT_IMAGES_PATH', '/var/lib/libvirt/images')
|
|
|
iso_dir = f"{images_path}/isos"
|
|
|
if os.path.exists(iso_dir):
|
|
|
isos = [{"name": f, "path": os.path.join(iso_dir, f)} for f in os.listdir(iso_dir) if f.endswith('.iso')]
|
|
|
@@ -248,7 +248,7 @@ async def list_isos():
|
|
|
|
|
|
@app.post("/upload-iso")
|
|
|
async def upload_iso(file: UploadFile = File(...)):
|
|
|
- images_path = os.environ.get('LIBVIRT_IMAGES_PATH', '/mnt/vms/images')
|
|
|
+ images_path = os.environ.get('LIBVIRT_IMAGES_PATH', '/var/lib/libvirt/images')
|
|
|
iso_dir = f"{images_path}/isos"
|
|
|
os.makedirs(iso_dir, exist_ok=True)
|
|
|
file_path = os.path.join(iso_dir, file.filename)
|
|
|
@@ -259,7 +259,7 @@ async def upload_iso(file: UploadFile = File(...)):
|
|
|
|
|
|
@app.delete("/isos/{iso_name}")
|
|
|
async def delete_iso(iso_name: str):
|
|
|
- images_path = os.environ.get('LIBVIRT_IMAGES_PATH', '/mnt/vms/images')
|
|
|
+ images_path = os.environ.get('LIBVIRT_IMAGES_PATH', '/var/lib/libvirt/images')
|
|
|
iso_dir = f"{images_path}/isos"
|
|
|
file_path = os.path.join(iso_dir, iso_name)
|
|
|
if os.path.exists(file_path) and iso_name.endswith('.iso'):
|