This commit is contained in:
pika 2025-04-03 14:45:45 +02:00
parent 67dae6f5e4
commit 2b36992be1
3 changed files with 65 additions and 2 deletions

View file

@ -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,

View file

@ -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/<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
)

View file

@ -49,7 +49,7 @@
{% if subnet.location %}
<small class="text-muted ms-2">({{ subnet.location }})</small>
{% endif %}
{% if subnet.description %}
{% if subnet.description is defined and subnet.description %}
<small class="text-muted ms-2">{{ subnet.description }}</small>
{% endif %}
</h4>