vm management

This commit is contained in:
Mateusz Gruszczyński
2025-10-17 16:27:03 +02:00
parent b9586a3517
commit d53860a9c3
2 changed files with 23 additions and 3 deletions

4
app.py
View File

@@ -21,11 +21,11 @@ app = Flask(__name__, template_folder="templates", static_folder="static")
def run(cmd: List[str], timeout: int = 25) -> subprocess.CompletedProcess:
return subprocess.run(cmd, check=False, text=True, capture_output=True, timeout=timeout)
def get_text(cmd: List[str]) -> str:
def get_text(cmd: List[str], timeout: Optional[int] = None) -> str:
r = run(cmd, timeout=timeout or 25)
return r.stdout if r.returncode == 0 else ""
def get_json(cmd: List[str]) -> Any:
def get_json(cmd: List[str], timeout: Optional[int] = None) -> Any:
if cmd and cmd[0] == "pvesh" and "--output-format" not in cmd:
cmd = cmd + ["--output-format", "json"]
r = run(cmd, timeout=timeout or 25)