fix(servers/edit): retire le push iTop sur changement application (etait bloquant 10s+ si iTop injoignable) - update local seulement, push iTop dedie via endpoint async a faire si besoin
This commit is contained in:
parent
4b2a4cb8f2
commit
c19309fec2
@ -176,39 +176,20 @@ async def server_update(request: Request, server_id: int, db=Depends(get_db),
|
||||
}
|
||||
update_server(db, server_id, data, user.get("sub"))
|
||||
|
||||
# Application (changement manuel SecOps) — update + push iTop
|
||||
# Application (changement manuel SecOps) — update local seulement.
|
||||
# Le push iTop est désactivé ici (peut bloquer 10s si iTop injoignable).
|
||||
# Si besoin de pousser vers iTop, utiliser un endpoint dédié async.
|
||||
if application_id is not None:
|
||||
app_id_val = int(application_id) if application_id and application_id.strip().isdigit() else None
|
||||
app_itop_id = None
|
||||
app_name = None
|
||||
if app_id_val:
|
||||
row = db.execute(text("SELECT itop_id, nom_court FROM applications WHERE id=:id"),
|
||||
row = db.execute(text("SELECT nom_court FROM applications WHERE id=:id"),
|
||||
{"id": app_id_val}).fetchone()
|
||||
if row:
|
||||
app_itop_id = row.itop_id
|
||||
app_name = row.nom_court
|
||||
db.execute(text("""UPDATE servers SET application_id=:aid, application_name=:an, updated_at=NOW()
|
||||
WHERE id=:sid"""), {"aid": app_id_val, "an": app_name, "sid": server_id})
|
||||
db.commit()
|
||||
# Push iTop (best effort)
|
||||
try:
|
||||
from ..services.itop_service import ITopClient
|
||||
from ..services.secrets_service import get_secret
|
||||
srv_row = db.execute(text("SELECT hostname FROM servers WHERE id=:id"), {"id": server_id}).fetchone()
|
||||
if srv_row:
|
||||
url = get_secret(db, "itop_url")
|
||||
u = get_secret(db, "itop_user")
|
||||
p = get_secret(db, "itop_pass")
|
||||
if url and u and p:
|
||||
client = ITopClient(url, u, p)
|
||||
r = client._call("core/get", **{"class": "VirtualMachine",
|
||||
"key": f'SELECT VirtualMachine WHERE name = "{srv_row.hostname}"', "output_fields": "name"})
|
||||
if r.get("objects"):
|
||||
vm_id = list(r["objects"].values())[0]["key"]
|
||||
new_list = [{"applicationsolution_id": int(app_itop_id)}] if app_itop_id else []
|
||||
client.update("VirtualMachine", vm_id, {"applicationsolution_list": new_list})
|
||||
except Exception as e:
|
||||
logger.warning(f"Erreur non bloquante: {e}")
|
||||
|
||||
s = get_server_full(db, server_id)
|
||||
tags = get_server_tags(db, s.qid)
|
||||
|
||||
@ -71,7 +71,7 @@
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-500">Solution applicative (iTop) <span class="text-gray-600">— modifie aussi iTop</span></label>
|
||||
<label class="text-xs text-gray-500">Solution applicative <span class="text-gray-600">— modif locale uniquement</span></label>
|
||||
<select name="application_id" class="w-full">
|
||||
<option value="">-- Aucune --</option>
|
||||
{% for a in applications %}<option value="{{ a.id }}" {% if a.id == s.application_id %}selected{% endif %}>{{ a.nom_court }}</option>{% endfor %}
|
||||
@ -114,7 +114,7 @@
|
||||
<button type="button" class="btn-sm bg-cyber-border text-gray-300 px-4 py-2" hx-get="/servers/{{ s.id }}/detail" hx-target="#detail-panel" hx-swap="innerHTML">Annuler</button>
|
||||
</div>
|
||||
<div id="edit-indicator" class="htmx-indicator text-xs text-cyber-yellow pt-1">
|
||||
⏳ Sauvegarde en cours… (push iTop possible jusqu'à ~10s si réseau lent)
|
||||
⏳ Sauvegarde en cours…
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user