Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit f5267eae authored by Maël Kervella's avatar Maël Kervella

Add DHCP_hostmacip API view

parent 1f0a3434
......@@ -457,3 +457,16 @@ class WhitelistSerializer(NamespacedHMSerializer):
class Meta:
model = users.Whitelist
fields = ('user', 'raison', 'date_start', 'date_end', 'active', 'api_url')
class HostMacIpSerializer(serializers.ModelSerializer):
hostname = serializers.CharField(source='domain.name', read_only=True)
extension = serializers.CharField(source='domain.extension.name', read_only=True)
ipv4 = serializers.CharField(source='ipv4.ipv4', read_only=True)
class Meta:
model = machines.Interface
fields = ('hostname', 'extension', 'mac_address', 'ipv4')
......@@ -89,5 +89,6 @@ router.register(r'users/whitelists', views.WhitelistViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^dhcp/hostmacip', views.HostMacIpView.as_view()),
url(r'^token-auth/', views.ObtainExpiringAuthToken.as_view())
......@@ -31,7 +31,7 @@ from django.conf import settings
from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.authtoken.models import Token
from rest_framework.response import Response
from rest_framework import viewsets, status
from rest_framework import viewsets, status, generics
import cotisations.models as cotisations
import machines.models as machines
......@@ -39,6 +39,8 @@ import preferences.models as preferences
import topologie.models as topologie
import users.models as users
from re2o.utils import all_active_interfaces
from . import serializers
......@@ -310,6 +312,14 @@ class WhitelistViewSet(viewsets.ReadOnlyModelViewSet):
queryset = users.Whitelist.objects.all()
serializer_class = serializers.WhitelistSerializer
# DHCP views
class HostMacIpView(generics.ListAPIView):
queryset = all_active_interfaces()
serializer_class = serializers.HostMacIpSerializer
# Subclass the standard rest_framework.auth_token.views.ObtainAuthToken
# in order to renew the lease of the token and add expiration time
class ObtainExpiringAuthToken(ObtainAuthToken):
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