Django-ipam is part of the OpenWISP project.
Table of Contents:
- IPv4 and IPv6 IP address management
- IPv4 and IPv6 Subnet management
- Automatic free space display for all subnets
- Visual display for a specific subnet
- IP request module
- RESTful API to for CRUD operations
- Possibility to search for an IP or subnet
- CSV Import and Export of subnets and their IPs
- provide a django reusable app with features of IP Address management
- provide abstract models which can be extended into other django based apps
- Python 3.4 or higher
- Django 2.0 or higher
Install the development version using the following commands:
git clone https://github.com/openwisp/django-ipam.git
cd django-ipam
python setup.py develop
Launch the development sever:
cd tests/
./manage.py migrate
./manage.py createsuperuser
./manage.py runserver
You can access the admin interface at http://127.0.0.1:8000/admin/.
Install test requirements:
pip install -r requirements-test.txt
Then run the test suite:
./runtests.py
Add django_ipam
to INSTALLED_APPS
:
INSTALLED_APPS = [
# other apps
'django_ipam',
]
Add the URLs to your main urls.py
:
urlpatterns = [
# ... other urls in your project ...
# django-ipam urls
# keep the namespace argument unchanged
url(r'^', include('django_ipam.urls', namespace='ipam')),
]
Then run:
./manage.py migrate
Django-ipam provides a graphical representation of a subnet which shows the available free space under any subnet.
The API authentication is based on session based authentication via Django REST framework. This authentication scheme uses Django's default session backend for authentication.
http -a username:password <HTTP verb> <api url>
API pagination is provided with the help page parameter. The default page size is 10 which can be overridden using the page_size parameter.
/api/v1/<api endpoint url>/?page=1&page_size=10
A model method to fetch the next available IP address under a specific subnet. This method can also be accessed via a RESTful API.
Returns the next available IP address under a subnet.
/api/v1/subnet/<subnet_id>/get-first-available-ip/
A model method to create and fetch the next available IP address record under a subnet.
Creates a record for next available IP address and returns JSON data of that record.
POST /api/v1/subnet/<subnet_id>/request-ip/
Param | Description |
---|---|
description | Optional description for the IP address |
{
"ip_address": "ip_address",
"subnet": "subnet_uuid",
"description": "optional description"
}
An api enpoint to retrieve or create IP addresses under a specific subnet.
Returns the list of IP addresses under a particular subnet.
/api/v1/subnet/<subnet_id>/ip-address/
Create a new IP Address
.
/api/v1/subnet/<subnet_id>/ip-address/
Param | Description |
---|---|
ip_address | IPv6/IPv4 address value |
subnet | Subnet UUID |
description | Optional description for the IP address |
An api endpoint to create or retrieve the list of subnet instances.
Returns the list of Subnet
instances.
/api/v1/subnet
Create a new Subnet
.
/api/v1/subnet
Param | Description |
---|---|
subnet | Subnet value in CIDR format |
master_subnet | Master Subnet UUID |
description | Optional description for the IP address |
An api endpoint for retrieving, updating or deleting a subnet instance.
Get details of a Subnet
instance
/api/v1/subnet/<subnet-id>
Delete a Subnet
instance
/api/v1/subnet/<subnet-id>
Update details of a Subnet
instance.
/api/v1/subnet/<subnet-id>
Param | Description |
---|---|
subnet | Subnet value in CIDR format |
master_subnet | Master Subnet UUID |
description | Optional description for the IP address |
An api enpoint for retrieving, updating or deleting a IP address instance.
Get details of an IP address
instance.
/api/v1/ip-address/<ip_address-id>
Delete an IP address
instance.
/api/v1/ip-address/<ip_address-id>
Update details of an IP address
instance.
/api/v1/ip-address/<ip_address-id>
Param | Description |
---|---|
ip_address | IPv6/IPv4 value |
subnet | Subnet UUID |
description | Optional description for the IP address |
View to export subnet data.
/api/v1/subnet/<subnet-id>/export
View to import subnet data.
/api/v1/import-subnet
One can easily import and export Subnet data and it's Ip Addresses using django-ipam. This works for both IPv4 and IPv6 types of networks.
Data can be exported via the admin interface or by using a management command. The exported data is in .csv file format.
./manage.py export_subnet <subnet value>
This would export the subnet if it exists on the database.
Data can be exported from the admin interface by just clicking on the export button on the subnet's admin change view.
Data can be imported via the admin interface or by using a management command. The imported data file can be in .csv, .xls and .xlsx format. While importing data for ip addresses, the system checks if the subnet specified in the import file exists or not. If the subnet does not exists it will be created while importing data.
./manage.py import_subnet --file=<file path>
Data can be imported from the admin interface by just clicking on the import button on the subnet view.
Follow the following structure while creating csv file to import data.
Subnet Name
Subnet Value
ip_address,description
<ip-address>,<optional-description>
<ip-address>,<optional-description>
<ip-address>,<optional-description>
The base API view classes can be extended into other django applications.
# your app.api.views
from ..models import Subnet, IpAddress
from .generics import (
BaseAvailableIpView, BaseExportSubnetView, BaseImportSubnetView, BaseIpAddressListCreateView,
BaseIpAddressView, BaseRequestIPView, BaseSubnetListCreateView, BaseSubnetView,
)
class AvailableIpView(BaseAvailableIpView):
subnet_model = Subnet
queryset = IpAddress.objects.none()
class RequestIPView(BaseRequestIPView):
subnet_model = Subnet
queryset = IpAddress.objects.none()
class SubnetIpAddressListCreateView(BaseIpAddressListCreateView):
subnet_model = Subnet
class SubnetListCreateView(BaseSubnetListCreateView):
queryset = Subnet.objects.all()
class SubnetVew(BaseSubnetView):
queryset = Subnet.objects.all()
class IpAddressView(BaseIpAddressView):
queryset = IpAddress.objects.all()
class ImportSubnetView(BaseImportSubnetView):
subnet_model = Subnet
queryset = Subnet.objects.none()
class ExportSubnetView(BaseExportSubnetView):
subnet_model = Subnet
queryset = Subnet.objects.none()