From 2b36992be172a312e93116a1fa05a416c724db38 Mon Sep 17 00:00:00 2001 From: pika Date: Thu, 3 Apr 2025 14:45:45 +0200 Subject: [PATCH] wip --- app/routes/dashboard.py | 5 ++- app/routes/ipam.py | 60 +++++++++++++++++++++++++++ app/templates/dashboard/overview.html | 2 +- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/app/routes/dashboard.py b/app/routes/dashboard.py index 517ee5a..6c52add 100644 --- a/app/routes/dashboard.py +++ b/app/routes/dashboard.py @@ -552,11 +552,14 @@ def overview(): subnet_data = { 'id': subnet.id, 'cidr': subnet.cidr, - 'description': subnet.description, 'location': subnet.location, 'servers': [] } + # Only add description if it exists as an attribute + if hasattr(subnet, 'description'): + subnet_data['description'] = subnet.description + for server in subnet.servers: server_data = { 'id': server.id, diff --git a/app/routes/ipam.py b/app/routes/ipam.py index a188470..be0b07a 100644 --- a/app/routes/ipam.py +++ b/app/routes/ipam.py @@ -265,3 +265,63 @@ def subnet_create_ajax(): except Exception as e: db.session.rollback() return jsonify({"success": False, "error": str(e)}) + + +@bp.route("/location/") +@login_required +def location_overview(location): + """View all subnets and servers in a specific location""" + # Get all subnets in this location + subnets = Subnet.query.filter_by(location=location).all() + + # Get servers in these subnets + servers = [] + for subnet in subnets: + subnet_servers = Server.query.filter_by(subnet_id=subnet.id).all() + servers.extend(subnet_servers) + + # Create a hierarchical structure + hierarchy = { + 'subnets': [], + 'standalone_servers': [] + } + + # Organize subnets and their servers + for subnet in subnets: + subnet_data = { + 'id': subnet.id, + 'cidr': subnet.cidr, + 'location': subnet.location, + 'servers': [] + } + + # Only add description if it exists as an attribute + if hasattr(subnet, 'description'): + subnet_data['description'] = subnet.description + + for server in subnet.servers: + server_data = { + 'id': server.id, + 'hostname': server.hostname, + 'ip_address': server.ip_address, + 'apps': [] + } + + for app in server.apps: + app_data = { + 'id': app.id, + 'name': app.name, + 'ports': app.ports + } + server_data['apps'].append(app_data) + + subnet_data['servers'].append(server_data) + + hierarchy['subnets'].append(subnet_data) + + return render_template( + "dashboard/overview.html", + title=f"{location} Overview", + hierarchy=hierarchy, + location=location + ) diff --git a/app/templates/dashboard/overview.html b/app/templates/dashboard/overview.html index 6db57d8..e01bf6e 100644 --- a/app/templates/dashboard/overview.html +++ b/app/templates/dashboard/overview.html @@ -49,7 +49,7 @@ {% if subnet.location %} ({{ subnet.location }}) {% endif %} - {% if subnet.description %} + {% if subnet.description is defined and subnet.description %} {{ subnet.description }} {% endif %}