This commit is contained in:
pika 2025-03-30 22:01:42 +02:00
parent be6f7cfcbb
commit 9433d9d235
7 changed files with 189 additions and 84 deletions

View file

@ -10,13 +10,31 @@ bp = Blueprint('api', __name__, url_prefix='/api')
@bp.route('/subnets', methods=['GET'])
def get_subnets():
"""Get all subnets"""
"""Get all subnets grouped by site"""
subnets = Subnet.query.all()
return jsonify([{
'id': subnet.id,
'cidr': subnet.cidr,
'location': subnet.location
} for subnet in subnets])
# Group subnets by location (site)
sites = {}
for subnet in subnets:
location = subnet.location
if location not in sites:
sites[location] = []
sites[location].append({
'id': subnet.id,
'cidr': subnet.cidr,
'location': location
})
# Convert to list of site objects
result = [
{
'name': site_name,
'subnets': subnets
} for site_name, subnets in sites.items()
]
return jsonify(result)
@bp.route('/subnets/<int:subnet_id>', methods=['GET'])
@login_required