Nom libre pour l'agent déployé : étape enter_name + JID suggéré automatiquement

- state machine : nouvelle étape enter_name après choose_agent
- XMPP JID suggéré par défaut : {nom}@xmpp.ovh (modifiable)
- MQTT inbox/service/install_path basés sur le nom libre
- notify_agent1 publie sur agents/register avec le bon format JSON

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-07 17:08:31 +00:00
parent 60099a5125
commit 9c3f24776c
2 changed files with 57 additions and 29 deletions
+12 -8
View File
@@ -48,6 +48,7 @@ def deploy_agent(
host: str,
ssh_user: str,
agent_type: str,
agent_name: str,
xmpp_jid: str,
xmpp_pass: str,
mqtt_host: str,
@@ -57,6 +58,7 @@ def deploy_agent(
) -> tuple[bool, str]:
"""
Déploie un agent sur la machine distante.
agent_name : nom libre choisi par l'utilisateur (ex: trouducul)
progress_cb(msg) : callback appelé à chaque étape pour informer l'utilisateur.
Retourne (succès, message_final).
"""
@@ -65,13 +67,15 @@ def deploy_agent(
return False, "Agent inconnu : {}".format(agent_type)
agent = catalog[agent_type]
install_path = agent["install_path"]
repo_url = agent["repo_url"]
service_name = agent["service_name"]
main_script = agent["main_script"]
deps = " ".join(agent["dependencies"])
mqtt_inbox = agent["mqtt_inbox"]
mqtt_outbox = agent["mqtt_outbox"]
# Le nom libre détermine install_path, service, MQTT
install_path = "/opt/{}".format(agent_name)
service_name = agent_name
mqtt_inbox = "agents/{}/inbox".format(agent_name)
mqtt_outbox = "agents/agent1/inbox"
try:
# ── Connexion SSH ──────────────────────────────────────────────────
@@ -119,7 +123,7 @@ def deploy_agent(
"db_path" : "{}/memory.db".format(install_path),
"mqtt_host" : mqtt_host,
"mqtt_port" : 1883,
"mqtt_client_id": agent_type,
"mqtt_client_id": agent_name,
"mqtt_inbox" : mqtt_inbox,
"mqtt_outbox" : mqtt_outbox,
}
@@ -146,7 +150,7 @@ StandardError=journal
[Install]
WantedBy=multi-user.target
""".format(name=agent_type, path=install_path, script=main_script)
""".format(name=agent_name, path=install_path, script=main_script)
write_remote_file(client,
"/etc/systemd/system/{}.service".format(service_name),
@@ -163,11 +167,11 @@ WantedBy=multi-user.target
client.close()
summary = (
"Déploiement de {} terminé sur {} !\n"
"Déploiement de «{}» ({}) terminé sur {} !\n"
" JID XMPP : {}\n"
" MQTT inbox : {}\n"
" Service : systemctl status {}"
).format(agent_type, host, xmpp_jid, mqtt_inbox, service_name)
).format(agent_name, agent_type, host, xmpp_jid, mqtt_inbox, service_name)
return True, summary