feat: edit nodes, delete, status as separate menu items

This commit is contained in:
admin 2026-08-03 15:41:53 +00:00
parent b981b82c5d
commit 1d4b6c9673

View file

@ -150,7 +150,9 @@ def main():
n += 1 n += 1
if deployed: if deployed:
print(f" [{n}] Manage nodes"); n += 1 print(f" [{n}] Edit nodes"); n += 1
print(f" [{n}] Delete a node"); n += 1
print(f" [{n}] Status"); n += 1
print(f" [{n}] Remote tunnel"); n += 1 print(f" [{n}] Remote tunnel"); n += 1
print(" [q] Quit") print(" [q] Quit")
@ -168,8 +170,12 @@ def main():
str(nc.get("upstream_port","80")), "", str(nc.get("upstream_port","80")), "",
nc.get("mode","monitoring")) nc.get("mode","monitoring"))
deployed.add(name) deployed.add(name)
elif c == str(n-2) and deployed: elif c == str(n-4) and deployed:
manage_nodes() edit_nodes()
elif c == str(n-3) and deployed:
remove_menu()
elif c == str(n-2):
container_status()
elif c == str(n-1): elif c == str(n-1):
start_tunnel() start_tunnel()
elif c.lower() == "q": elif c.lower() == "q":
@ -274,22 +280,39 @@ def start_tunnel():
except Exception as e: except Exception as e:
print(f"Tunnel failed: {e}") print(f"Tunnel failed: {e}")
def manage_nodes(): def edit_nodes():
s = load_state().get("nodes", []) s = load_state().get("nodes", [])
if not s: print("No nodes."); return if not s: print("No nodes."); return
while True: print("\n─── Edit Node ───")
print("\n─── Manage Nodes ───") for i, n in enumerate(s):
for i, n in enumerate(s): r = run(f"docker inspect -f '{{{{.State.Status}}}}' wallarm-{n['name']} 2>/dev/null")
r = run(f"docker inspect -f '{{{{.State.Status}}}}' wallarm-{n['name']} 2>/dev/null") st = "" if r.stdout.strip() == "running" else ""
st = "" if r.stdout.strip() == "running" else "" print(f" [{i+1}] {st} {n['name']} (port {n.get('port','')})")
print(f" [{i+1}] {st} {n['name']} (port {n.get('port','')})") print(" [b] Back")
print(" [r] Restart [d] Delete [b] Back") c = input("\nSelect node: ").strip()
c = input("\nAction: ").strip() if c.lower() == 'b': return
if c.lower() == 'b': break if not c.isdigit(): return
if c == 'r': idx = int(c) - 1
name = input("Node name: ").strip() if idx < 0 or idx >= len(s): return
if name: run(f"docker restart wallarm-{name} 2>/dev/null"); print(f"Restarted {name}") n = s[idx]
elif c == 'd': print(f"\nEditing {n['name']}. Enter to keep current:")
name = input("Node name: ").strip() port = input(f"Port [{n.get('port','')}]: ").strip()
if name: remove_container(name) upstream = input(f"Upstream [{n.get('upstream_ip','')}:{n.get('upstream_port','')}]: ").strip()
s = load_state().get("nodes", []) if port: n['port'] = int(port)
if ':' in upstream:
ip, p = upstream.split(':')
n['upstream_ip'] = ip; n['upstream_port'] = int(p)
save_state({"nodes": s})
print(f"✅ Updated. Restart to apply.")
def remove_menu():
s = load_state().get("nodes", [])
if not s: print("No nodes."); return
print("\n─── Delete Node ───")
for i, n in enumerate(s):
print(f" [{i+1}] {n['name']} (port {n.get('port','')})")
c = input("\nSelect: ").strip()
if not c.isdigit(): return
idx = int(c) - 1
if 0 <= idx < len(s):
remove_container(s[idx]["name"])