Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[change!] Modified API endpoints #106 #107

Merged
merged 2 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Returns the next available IP address under a subnet.

.. code-block:: text

/api/v1/subnet/<subnet_id>/get-next-available-ip/
/api/v1/ipam/subnet/<subnet_id>/get-next-available-ip/

Request IP
^^^^^^^^^^
Expand All @@ -216,7 +216,7 @@ Creates a record for next available IP address and returns JSON data of that rec

.. code-block:: text

POST /api/v1/subnet/<subnet_id>/request-ip/
POST /api/v1/ipam/subnet/<subnet_id>/request-ip/

=========== ========================================
Param Description
Expand All @@ -240,7 +240,7 @@ Response
IpAddress-Subnet List and Create View
=====================================

An api enpoint to retrieve or create IP addresses under a specific subnet.
An api endpoint to retrieve or create IP addresses under a specific subnet.

GET
---
Expand All @@ -249,7 +249,7 @@ Returns the list of IP addresses under a particular subnet.

.. code-block:: text

/api/v1/subnet/<subnet_id>/ip-address/
/api/v1/ipam/subnet/<subnet_id>/ip-address/

POST
----
Expand All @@ -258,7 +258,7 @@ Create a new ``IP Address``.

.. code-block:: text

/api/v1/subnet/<subnet_id>/ip-address/
/api/v1/ipam/subnet/<subnet_id>/ip-address/

=========== ========================================
Param Description
Expand All @@ -280,7 +280,7 @@ Returns the list of ``Subnet`` instances.

.. code-block:: text

/api/v1/subnet/
/api/v1/ipam/subnet/

POST
----
Expand All @@ -289,7 +289,7 @@ Create a new ``Subnet``.

.. code-block:: text

/api/v1/subnet/
/api/v1/ipam/subnet/

============= ========================================
Param Description
Expand All @@ -311,7 +311,7 @@ Get details of a ``Subnet`` instance

.. code-block:: text

/api/v1/subnet/<subnet-id>/
/api/v1/ipam/subnet/<subnet-id>/

DELETE
------
Expand All @@ -320,7 +320,7 @@ Delete a ``Subnet`` instance

.. code-block:: text

/api/v1/subnet/<subnet-id>/
/api/v1/ipam/subnet/<subnet-id>/

PUT
---
Expand All @@ -329,7 +329,7 @@ Update details of a ``Subnet`` instance.

.. code-block:: text

/api/v1/subnet/<subnet-id>/
/api/v1/ipam/subnet/<subnet-id>/

============= ========================================
Param Description
Expand All @@ -342,7 +342,7 @@ description Optional description for the IP address
IP Address View
===============

An api enpoint for retrieving, updating or deleting a IP address instance.
An api endpoint for retrieving, updating or deleting a IP address instance.

GET
---
Expand All @@ -351,7 +351,7 @@ Get details of an ``IP address`` instance.

.. code-block:: text

/api/v1/ip-address/<ip_address-id>/
/api/v1/ipam/ip-address/<ip_address-id>/

DELETE
------
Expand All @@ -360,7 +360,7 @@ Delete an ``IP address`` instance.

.. code-block:: text

/api/v1/ip-address/<ip_address-id>/
/api/v1/ipam/ip-address/<ip_address-id>/

PUT
---
Expand All @@ -369,7 +369,7 @@ Update details of an ``IP address`` instance.

.. code-block:: text

/api/v1/ip-address/<ip_address-id>/
/api/v1/ipam/ip-address/<ip_address-id>/

=========== ========================================
Param Description
Expand All @@ -389,7 +389,7 @@ POST

.. code-block:: text

/api/v1/subnet/<subnet-id>/export/
/api/v1/ipam/subnet/<subnet-id>/export/

Import Subnet View
==================
Expand All @@ -401,7 +401,7 @@ POST

.. code-block:: text

/api/v1/import-subnet/
/api/v1/ipam/import-subnet/


Exporting and Importing Subnet
Expand Down
37 changes: 0 additions & 37 deletions openwisp_ipam/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +0,0 @@
from django.urls import path
nemesifier marked this conversation as resolved.
Show resolved Hide resolved


def get_api_urls(api_views):
"""
returns:: all the API urls of the app
arguements::
api_views: location for getting API views
"""

return [
path('import-subnet/', api_views.import_subnet, name='import-subnet'),
path(
'subnet/<str:subnet_id>/get-next-available-ip/',
api_views.get_next_available_ip,
name='get_next_available_ip',
),
path(
'subnet/<str:subnet_id>/request-ip/',
api_views.request_ip,
name='request_ip',
),
path(
'subnet/<str:subnet_id>/export/',
api_views.export_subnet,
name='export-subnet',
),
path(
'subnet/<str:subnet_id>/ip-address/',
api_views.subnet_list_ipaddress,
name='list_create_ip_address',
),
path('subnet/', api_views.subnet_list_create, name='subnet_list_create'),
path('subnet/<str:pk>/', api_views.subnet, name='subnet'),
path('subnet/<str:subnet_id>/hosts/', api_views.subnet_hosts, name='hosts'),
path('ip-address/<str:pk>/', api_views.ip_address, name='ip_address'),
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in other modules, we usually just define the prefix in the root urlconf or something similar, so I suggest doing that to maintain consistency. Please add ipam here:

path('api/v1/', include((get_api_urls(api_views), 'ipam'), namespace='ipam')),

37 changes: 37 additions & 0 deletions openwisp_ipam/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django.urls import path


def get_api_urls(api_views):
"""
returns:: all the API urls of the app
arguements::
api_views: location for getting API views
"""

return [
path('import-subnet/', api_views.import_subnet, name='import-subnet'),
path(
'subnet/<str:subnet_id>/get-next-available-ip/',
api_views.get_next_available_ip,
name='get_next_available_ip',
),
path(
'subnet/<str:subnet_id>/request-ip/',
api_views.request_ip,
name='request_ip',
),
path(
'subnet/<str:subnet_id>/export/',
api_views.export_subnet,
name='export-subnet',
),
path(
'subnet/<str:subnet_id>/ip-address/',
api_views.subnet_list_ipaddress,
name='list_create_ip_address',
),
path('subnet/', api_views.subnet_list_create, name='subnet_list_create'),
path('subnet/<str:pk>/', api_views.subnet, name='subnet'),
path('subnet/<str:subnet_id>/hosts/', api_views.subnet_hosts, name='hosts'),
path('ip-address/<str:pk>/', api_views.ip_address, name='ip_address'),
]
6 changes: 3 additions & 3 deletions openwisp_ipam/static/openwisp-ipam/js/subnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function initHostsInfiniteScroll($, current_subnet, address_add_url, address_cha
var renderedPages = 5,
fetchedPages = [],
busy = false,
nextPageUrl = '/api/v1/subnet/' + current_subnet + '/hosts/',
nextPageUrl = '/api/v1/ipam/subnet/' + current_subnet + '/hosts/',
searchQuery = '',
lastRenderedPage = 0; //1 based indexing (0 -> no page rendered)
function addressListItem(addr) {
Expand Down Expand Up @@ -74,7 +74,7 @@ function initHostsInfiniteScroll($, current_subnet, address_add_url, address_cha
}
$.ajax({
type: 'GET',
url: '/api/v1/subnet/' + current_subnet + '/hosts/?start=' + ip_address,
url: '/api/v1/ipam/subnet/' + current_subnet + '/hosts/?start=' + ip_address,
success: function (res) {
callback(res.results[0].address === ip_address);
},
Expand All @@ -91,7 +91,7 @@ function initHostsInfiniteScroll($, current_subnet, address_add_url, address_cha
$("#invalid-address").hide();
if (input !== searchQuery) {
searchQuery = input;
nextPageUrl = '/api/v1/subnet/' + current_subnet + '/hosts/?start=' + searchQuery;
nextPageUrl = '/api/v1/ipam/subnet/' + current_subnet + '/hosts/?start=' + searchQuery;
$('#subnet-visual').empty();
fetchedPages = [];
lastRenderedPage = 0;
Expand Down
7 changes: 5 additions & 2 deletions openwisp_ipam/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.urls import include, path

from .api import get_api_urls, views as ipam_api_views
from .api import views as ipam_api_views
from .api.urls import get_api_urls


def get_urls(api_views):
Expand All @@ -10,7 +11,9 @@ def get_urls(api_views):
api_views: location for getting API views
"""
return [
path('api/v1/', include((get_api_urls(api_views), 'ipam'), namespace='ipam')),
path(
'api/v1/ipam/', include((get_api_urls(api_views), 'ipam'), namespace='ipam')
),
path('accounts/', include('openwisp_users.accounts.urls')),
]

Expand Down