mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 22:22:26 +00:00
Add DHCP_hostmacip API view
This commit is contained in:
parent
1f0a3434dd
commit
f5267eae6c
3 changed files with 25 additions and 1 deletions
|
@ -457,3 +457,16 @@ class WhitelistSerializer(NamespacedHMSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = users.Whitelist
|
model = users.Whitelist
|
||||||
fields = ('user', 'raison', 'date_start', 'date_end', 'active', 'api_url')
|
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')
|
||||||
|
|
|
@ -89,5 +89,6 @@ router.register(r'users/whitelists', views.WhitelistViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^', include(router.urls)),
|
url(r'^', include(router.urls)),
|
||||||
|
url(r'^dhcp/hostmacip', views.HostMacIpView.as_view()),
|
||||||
url(r'^token-auth/', views.ObtainExpiringAuthToken.as_view())
|
url(r'^token-auth/', views.ObtainExpiringAuthToken.as_view())
|
||||||
]
|
]
|
||||||
|
|
12
api/views.py
12
api/views.py
|
@ -31,7 +31,7 @@ from django.conf import settings
|
||||||
from rest_framework.authtoken.views import ObtainAuthToken
|
from rest_framework.authtoken.views import ObtainAuthToken
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
from rest_framework.response import Response
|
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 cotisations.models as cotisations
|
||||||
import machines.models as machines
|
import machines.models as machines
|
||||||
|
@ -39,6 +39,8 @@ import preferences.models as preferences
|
||||||
import topologie.models as topologie
|
import topologie.models as topologie
|
||||||
import users.models as users
|
import users.models as users
|
||||||
|
|
||||||
|
from re2o.utils import all_active_interfaces
|
||||||
|
|
||||||
from . import serializers
|
from . import serializers
|
||||||
|
|
||||||
|
|
||||||
|
@ -310,6 +312,14 @@ class WhitelistViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
queryset = users.Whitelist.objects.all()
|
queryset = users.Whitelist.objects.all()
|
||||||
serializer_class = serializers.WhitelistSerializer
|
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
|
# Subclass the standard rest_framework.auth_token.views.ObtainAuthToken
|
||||||
# in order to renew the lease of the token and add expiration time
|
# in order to renew the lease of the token and add expiration time
|
||||||
class ObtainExpiringAuthToken(ObtainAuthToken):
|
class ObtainExpiringAuthToken(ObtainAuthToken):
|
||||||
|
|
Loading…
Reference in a new issue