diff --git a/p4tenant/src/p4tenant/tenant.py b/p4tenant/src/p4tenant/tenant.py index ad24c6f..e27656e 100644 --- a/p4tenant/src/p4tenant/tenant.py +++ b/p4tenant/src/p4tenant/tenant.py @@ -353,15 +353,18 @@ def get_tenant_info(self, username: str) -> dict | None: all_srv_vms = srv_data.get("vms", []) in_vms_list = any(vm in all_srv_vms for vm in user_vms) - # Aggregate IPs from all user's VMs + # Aggregate IPs from all user's VMs (both flat list and grouped by VM) ips = [] + vm_ip_map = {} # Map of vm_name -> list of IPs has_host_vars = False for vm_name in user_vms: host_vars_path = get_host_vars_path(vm_name) if host_vars_path.exists(): has_host_vars = True hv_data = load_yaml(host_vars_path) - ips.extend(hv_data.get("dataplane_ipv4", [])) + vm_ips = hv_data.get("dataplane_ipv4", []) + ips.extend(vm_ips) + vm_ip_map[vm_name] = vm_ips # Check inventory inv_data = load_yaml(INVENTORY_FILE) @@ -380,6 +383,7 @@ def get_tenant_info(self, username: str) -> dict | None: "vm_name": primary_vm, "vm_names": user_vms, "ips": ips, + "vm_ip_map": vm_ip_map, # Map of vm_name -> list of IPs for proper alignment "in_restart_users": in_restart_users, "in_vms_list": in_vms_list, "in_inventory": in_inventory, diff --git a/p4tenant/src/p4tenant/ui.py b/p4tenant/src/p4tenant/ui.py index 1133987..eb812e0 100644 --- a/p4tenant/src/p4tenant/ui.py +++ b/p4tenant/src/p4tenant/ui.py @@ -89,14 +89,40 @@ def create_tenant_table(tenants: list[dict]) -> Table: status_parts.append("[red]\u2717 host[/red]") status = " ".join(status_parts) - ips = "\n".join(tenant.get("ips", [])) - # Show VM names (or count if multiple) + # Get VM names and IP mapping vm_names = tenant.get("vm_names", []) + vm_ip_map = tenant.get("vm_ip_map", {}) + + # Build aligned VM and IP displays if len(vm_names) <= 1: + # Single VM - simple display vms_display = tenant.get("vm_name", "") + ips = "\n".join(tenant.get("ips", [])) else: - vms_display = "\n".join(vm_names) + # Multiple VMs - align IPs with their VMs + vm_lines = [] + ip_lines = [] + + for vm_name in vm_names: + vm_ips = vm_ip_map.get(vm_name, []) + + if vm_ips: + # First line: VM name and first IP + vm_lines.append(vm_name) + ip_lines.append(vm_ips[0]) + + # Remaining IPs for this VM: blank VM name, show IP + for ip in vm_ips[1:]: + vm_lines.append("") + ip_lines.append(ip) + else: + # No IPs for this VM + vm_lines.append(vm_name) + ip_lines.append("") + + vms_display = "\n".join(vm_lines) + ips = "\n".join(ip_lines) table.add_row( tenant.get("username", ""),