Newer
Older
# -*- coding: utf-8 -*-
"""
app.api.network
~~~~~~~~~~~~~~~
This module implements the network API.
:copyright: (c) 2017 European Spallation Source ERIC
:license: BSD 2-Clause, see LICENSE for more details.
"""
from .utils import get_generic_model, create_generic_model
@bp.route('/scopes')
@jwt_required
def get_scopes():
order_by=models.NetworkScope.name)
@bp.route('/scopes', methods=['POST'])
@jwt_required
@jwt_groups_accepted('admin')
def create_scope():
"""Create a new network scope"""
return create_generic_model(models.NetworkScope, mandatory_fields=(
'name', 'first_vlan', 'last_vlan', 'supernet'))
@bp.route('/networks')
@jwt_required
def get_networks():
@bp.route('/networks', methods=['POST'])
@jwt_required
@jwt_groups_accepted('admin')
def create_network():
"""Create a new network"""
return create_generic_model(models.Network, mandatory_fields=(
'vlan_name', 'vlan_id', 'address', 'first_ip', 'last_ip', 'scope'))
@bp.route('/interfaces')
@jwt_required
def get_interfaces():
@bp.route('/interfaces', methods=['POST'])
@jwt_required
@jwt_groups_accepted('admin', 'create')
def create_interface():
"""Create a new interface"""
return create_generic_model(models.Interface, mandatory_fields=('network', 'ip', 'name'))
@bp.route('/macs')
@jwt_required
def get_macs():
order_by=models.Mac.address)
@bp.route('/macs', methods=['POST'])
@jwt_required
@jwt_groups_accepted('admin', 'create')
def create_macs():
return create_generic_model(models.Mac,
mandatory_fields=('address',))