From 7ee601983172faff016e189d6ee7fa793adfa009 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 9 Mar 2026 18:30:24 +1300 Subject: [PATCH] Collect child VM servers when refreshing a single host --- app/app.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/app.py b/app/app.py index 0ef81ae..a8e977c 100644 --- a/app/app.py +++ b/app/app.py @@ -447,7 +447,7 @@ def api_refresh_stream(): @app.route('/api/servers//refresh/stream') def api_refresh_one_stream(server_id): - """SSE endpoint: collect a single server with progress updates.""" + """SSE endpoint: collect a single server (and its child VMs) with progress updates.""" def generate(): with app.app_context(): server = Server.query.get(server_id) @@ -462,6 +462,15 @@ def api_refresh_one_stream(server_id): 'hostname': server.hostname, 'url': server.url, } + # Find child VMs configured under this host + children = Server.query.filter_by(parent_hostname=hostname).all() + child_entries = [{ + 'id': c.id, + 'group': c.group_name, + 'username': c.username, + 'hostname': c.hostname, + 'url': c.url, + } for c in children] try: ssh_key = load_ssh_key() @@ -470,6 +479,7 @@ def api_refresh_one_stream(server_id): yield f"data: [DONE]\n\n" return + # Collect the host yield f"data: Connecting to {hostname}...\n\n" result = collect_one(entry, ssh_key) @@ -490,6 +500,26 @@ def api_refresh_one_stream(server_id): else: yield f"data: {hostname} - offline: {result.get('error', 'unknown')}\n\n" + # Collect child VMs + for child_entry in child_entries: + child_host = child_entry['hostname'] + yield f"data: Connecting to {child_host}...\n\n" + child_result = collect_one(child_entry, ssh_key) + + with app.app_context(): + child_server = Server.query.get(child_entry['id']) + _update_server_from_result(child_server, child_entry, child_result) + db.session.commit() + + if child_result.get('is_online'): + child_ct = len(child_result.get('container', [])) + msg = f"{child_host} - online" + if child_ct: + msg += f", {child_ct} containers" + yield f"data: {msg}\n\n" + else: + yield f"data: {child_host} - offline: {child_result.get('error', 'unknown')}\n\n" + yield f"data: [DONE]\n\n" return Response(stream_with_context(generate()),