Rework GUI 1/3 (backend) : endpoints plan + instancier
- ecrire_serveurs + POST /api/serveurs (valide via valider_serveurs + nomenclature, ecrit docs/serveurs.yml). - POST /api/instancier : lance scripts/instancier.py appliquer et renvoie ok + sortie (regenere hosts.yml depuis le plan). Permettra a la vue Serveurs d'editer le plan et a un bouton « Appliquer » de regenerer l'inventaire. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
854e324348
commit
6040dfb8ff
1 changed files with 24 additions and 0 deletions
|
|
@ -33,6 +33,7 @@ from inventory_rules import (
|
|||
reconcilier_serveur,
|
||||
valider_applications,
|
||||
valider_bases,
|
||||
valider_serveurs,
|
||||
)
|
||||
|
||||
RACINE = Path(__file__).resolve().parents[1]
|
||||
|
|
@ -240,6 +241,19 @@ def ecrire_applications(path: Path, registre: dict) -> None:
|
|||
fichier, default_flow_style=False, sort_keys=False, allow_unicode=True)
|
||||
|
||||
|
||||
def ecrire_serveurs(path: Path, registre: dict) -> None:
|
||||
entete = (
|
||||
"# Registre des serveurs (VM) du plan Set-OPS.\n"
|
||||
"# Edite par make inventaire-ui ou scripts/serveurs.py.\n"
|
||||
"# VMID/IP/VLAN/passerelle sont DERIVES de la fonction via docs/nomenclature.yml.\n"
|
||||
"---\n"
|
||||
)
|
||||
with path.open("w", encoding="utf-8") as fichier:
|
||||
fichier.write(entete)
|
||||
yaml.safe_dump({"serveurs": registre.get("serveurs", {}) or {}},
|
||||
fichier, default_flow_style=False, sort_keys=False, allow_unicode=True)
|
||||
|
||||
|
||||
def donnees_hote(hote: dict) -> dict:
|
||||
variables: dict = {}
|
||||
for cle, var, typ in CHAMPS_PROVISION:
|
||||
|
|
@ -1512,6 +1526,16 @@ class Gestionnaire(BaseHTTPRequestHandler):
|
|||
valider_applications(donnees, charger_domaines(FICHIER_DOMAINES))
|
||||
ecrire_applications(FICHIER_APPLICATIONS, donnees)
|
||||
self.repondre_json(200, inventaire_api(self.inventaire))
|
||||
elif chemin == "/api/serveurs":
|
||||
valider_serveurs(donnees, charger_nomenclature(FICHIER_NOMENCLATURE))
|
||||
ecrire_serveurs(FICHIER_SERVEURS, donnees)
|
||||
self.repondre_json(200, inventaire_api(self.inventaire))
|
||||
elif chemin == "/api/instancier":
|
||||
resultat = subprocess.run(
|
||||
["python3", str(RACINE / "scripts/instancier.py"), "appliquer"],
|
||||
capture_output=True, text=True, cwd=str(RACINE))
|
||||
self.repondre_json(200, {"ok": resultat.returncode == 0,
|
||||
"sortie": (resultat.stdout + resultat.stderr).strip()})
|
||||
elif chemin == "/api/verifier":
|
||||
self.executer_flux(str(donnees.get("hote", "")), "verifier", donnees.get("vault"))
|
||||
elif chemin == "/api/deployer":
|
||||
|
|
|
|||
Reference in a new issue