mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 23:43:47 +00:00
API: Add support for DHCP
This commit is contained in:
parent
a86369e7c8
commit
7028788cf2
3 changed files with 55 additions and 2 deletions
|
@ -24,7 +24,10 @@ Serializers for the API app
|
|||
|
||||
from rest_framework import serializers
|
||||
from users.models import Club, Adherent
|
||||
from machines.models import Service_link
|
||||
from machines.models import (
|
||||
Interface,
|
||||
Service_link,
|
||||
)
|
||||
|
||||
|
||||
class ServiceLinkSerializer(serializers.ModelSerializer):
|
||||
|
@ -49,6 +52,29 @@ class MailingMemberSerializer(serializers.ModelSerializer):
|
|||
fields = ('email', 'name', 'surname', 'pseudo',)
|
||||
|
||||
|
||||
class InterfaceSerializer(serializers.ModelSerializer):
|
||||
"""Serialisation d'une interface, ipv4, domain et extension sont
|
||||
des foreign_key, on les override et on les evalue avec des fonctions
|
||||
get_..."""
|
||||
ipv4 = IpListSerializer(read_only=True)
|
||||
mac_address = serializers.SerializerMethodField('get_macaddress')
|
||||
domain = serializers.SerializerMethodField('get_dns')
|
||||
extension = serializers.SerializerMethodField('get_interface_extension')
|
||||
|
||||
class Meta:
|
||||
model = Interface
|
||||
fields = ('ipv4', 'mac_address', 'domain', 'extension')
|
||||
|
||||
def get_dns(self, obj):
|
||||
return obj.domain.name
|
||||
|
||||
def get_interface_extension(self, obj):
|
||||
return obj.domain.extension.name
|
||||
|
||||
def get_macaddress(self, obj):
|
||||
return str(obj.mac_address)
|
||||
|
||||
|
||||
class ServicesSerializer(serializers.ModelSerializer):
|
||||
"""Evaluation d'un Service, et serialisation"""
|
||||
server = serializers.SerializerMethodField('get_server_name')
|
||||
|
|
|
@ -35,6 +35,9 @@ urlpatterns = [
|
|||
url(r'^services/(?P<server_name>\w+)/(?P<service_name>\w+)/regen/$', views.services_server_service_regen),
|
||||
url(r'^services/(?P<server_name>\w+)/$', views.services_server),
|
||||
|
||||
# DHCP
|
||||
url(r'^dhcp/mac-ip/$', views.dhcp_mac_ip),
|
||||
|
||||
# Mailings
|
||||
url(r'^mailing/standard/$', views.mailing_standard),
|
||||
url(r'^mailing/standard/(?P<ml_name>\w+)/members/$', views.mailing_standard_ml_members),
|
||||
|
|
26
api/views.py
26
api/views.py
|
@ -27,7 +27,7 @@ HTML pages such as the login and index pages for a better integration.
|
|||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from re2o.utils import all_has_access
|
||||
from re2o.utils import all_has_access, all_active_assigned_interfaces
|
||||
|
||||
from users.models import Club
|
||||
from machines.models import Service_link, Service, Interface, Domain
|
||||
|
@ -114,6 +114,30 @@ def services_server(request, server_name):
|
|||
return JSONSuccess(seria.data)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
@accept_method(['GET'])
|
||||
def dhcp_mac_ip(request):
|
||||
"""The list of all active interfaces with all the associated infos
|
||||
(MAC, IP, IpType, DNS name and associated zone extension)
|
||||
|
||||
Returns:
|
||||
GET:
|
||||
A JSON Success response with a field `data` containing:
|
||||
* a list of dictionnaries (one for each interface) containing:
|
||||
* a field `ipv4` containing:
|
||||
* a field `ipv4`: the ip for this interface
|
||||
* a field `ip_type`: the name of the IpType of this interface
|
||||
* a field `mac_address`: the MAC of this interface
|
||||
* a field `domain`: the DNS name for this interface
|
||||
* a field `extension`: the extension for the DNS zone of this interface
|
||||
"""
|
||||
interfaces = all_active_assigned_interfaces()
|
||||
seria = InterfaceSerializer(interfaces, many=True)
|
||||
return JSONSuccess(seria.data)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
@permission_required('machines.serveur')
|
||||
|
|
Loading…
Reference in a new issue