From e50b7174bf94f9b73232587d3b122576d4ba261a Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 15 Nov 2017 15:26:00 -0500 Subject: [PATCH] Closes #1669: Clicking "add an IP" from the prefix view will default to the first available IP within the prefix --- netbox/ipam/models.py | 10 ++++++++++ netbox/templates/ipam/inc/prefix_header.html | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py index 6e4788840..0ce0afbdf 100644 --- a/netbox/ipam/models.py +++ b/netbox/ipam/models.py @@ -304,6 +304,16 @@ class Prefix(CreatedUpdatedModel, CustomFieldModel): return available_ips + def get_first_available_ip(self): + """ + Return the first available IP within the prefix (or None). + """ + available_ips = self.get_available_ips() + if available_ips: + return '{}/{}'.format(next(available_ips.__iter__()), self.prefix.prefixlen) + else: + return None + def get_utilization(self): """ Determine the utilization of the prefix and return it as a percentage. For Prefixes with a status of diff --git a/netbox/templates/ipam/inc/prefix_header.html b/netbox/templates/ipam/inc/prefix_header.html index d9e017860..3f593e67a 100644 --- a/netbox/templates/ipam/inc/prefix_header.html +++ b/netbox/templates/ipam/inc/prefix_header.html @@ -23,7 +23,7 @@
{% if perms.ipam.add_ipaddress %} - + Add an IP Address