wip
This commit is contained in:
parent
f939933a7c
commit
be6f7cfcbb
35 changed files with 1897 additions and 733 deletions
|
@ -9,23 +9,14 @@ import ipaddress
|
|||
bp = Blueprint('api', __name__, url_prefix='/api')
|
||||
|
||||
@bp.route('/subnets', methods=['GET'])
|
||||
@login_required
|
||||
def get_subnets():
|
||||
"""Get all subnets"""
|
||||
subnets = Subnet.query.all()
|
||||
result = []
|
||||
|
||||
for subnet in subnets:
|
||||
result.append({
|
||||
'id': subnet.id,
|
||||
'cidr': subnet.cidr,
|
||||
'location': subnet.location,
|
||||
'used_ips': subnet.used_ips,
|
||||
'auto_scan': subnet.auto_scan,
|
||||
'created_at': subnet.created_at.strftime('%Y-%m-%d %H:%M:%S')
|
||||
})
|
||||
|
||||
return jsonify({'subnets': result})
|
||||
return jsonify([{
|
||||
'id': subnet.id,
|
||||
'cidr': subnet.cidr,
|
||||
'location': subnet.location
|
||||
} for subnet in subnets])
|
||||
|
||||
@bp.route('/subnets/<int:subnet_id>', methods=['GET'])
|
||||
@login_required
|
||||
|
@ -306,4 +297,14 @@ def delete_port(port_id):
|
|||
db.session.delete(port)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({'success': True})
|
||||
return jsonify({'success': True})
|
||||
|
||||
@bp.route('/subnets/<int:subnet_id>/servers', methods=['GET'])
|
||||
def get_subnet_servers(subnet_id):
|
||||
"""Get all servers for a specific subnet"""
|
||||
servers = Server.query.filter_by(subnet_id=subnet_id).all()
|
||||
return jsonify([{
|
||||
'id': server.id,
|
||||
'hostname': server.hostname,
|
||||
'ip_address': server.ip_address
|
||||
} for server in servers])
|
Loading…
Add table
Add a link
Reference in a new issue