ソースを参照

Pongo estado con palabras

Celestino Rey 7 ヶ月 前
コミット
4cc7f3687e
1 ファイル変更14 行追加1 行削除
  1. 14 1
      app/main.py

+ 14 - 1
app/main.py

@@ -10,6 +10,19 @@ app = FastAPI(title="VirtManager API", description="API for managing virtual mac
 
 app.mount("/static", StaticFiles(directory="static"), name="static")
 
+def get_state_string(state_code):
+    states = {
+        0: "no state",
+        1: "running",
+        2: "blocked",
+        3: "paused",
+        4: "shutdown",
+        5: "shut off",
+        6: "crashed",
+        7: "pm suspended"
+    }
+    return states.get(state_code, "unknown")
+
 # Connect to libvirt
 conn = libvirt.open('qemu:///system')
 
@@ -25,7 +38,7 @@ async def list_vms():
         vms.append({
             "id": domain.ID(),
             "name": domain.name(),
-            "state": domain.state()[0]
+            "state": get_state_string(domain.state()[0])
         })
     return {"vms": vms}