Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
7028788c
Commit
7028788c
authored
Mar 17, 2018
by
Maël Kervella
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Add support for DHCP
parent
a86369e7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
2 deletions
+55
-2
api/serializers.py
api/serializers.py
+27
-1
api/urls.py
api/urls.py
+3
-0
api/views.py
api/views.py
+25
-1
No files found.
api/serializers.py
View file @
7028788c
...
...
@@ -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'
)
...
...
api/urls.py
View file @
7028788c
...
...
@@ -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
),
...
...
api/views.py
View file @
7028788c
...
...
@@ -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'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment