8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Add DHCP_hostmacip API view

This commit is contained in:
Maël Kervella 2018-05-24 23:07:23 +00:00
parent 1f0a3434dd
commit f5267eae6c
3 changed files with 25 additions and 1 deletions

View file

@ -457,3 +457,16 @@ class WhitelistSerializer(NamespacedHMSerializer):
class Meta:
model = users.Whitelist
fields = ('user', 'raison', 'date_start', 'date_end', 'active', 'api_url')
# DHCP
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')

View file

@ -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())
]

View file

@ -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):