Commit 7028788c authored by Maël Kervella's avatar Maël Kervella

API: Add support for DHCP

parent a86369e7
......@@ -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 (
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
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):
def get_interface_extension(self, obj):
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),
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),
......@@ -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(
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)
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(
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment