Last active
October 2, 2017 09:46
-
-
Save candlerb/9ca144df7c36fe7a1f2a081f417d94cf to your computer and use it in GitHub Desktop.
Patch to netbox to enable entry of IP addresses without prefixlen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/netbox/ipam/formfields.py b/netbox/ipam/formfields.py | |
index 914310b..4810375 100644 | |
--- a/netbox/ipam/formfields.py | |
+++ b/netbox/ipam/formfields.py | |
@@ -21,8 +21,8 @@ class IPFormField(forms.Field): | |
return value | |
# Ensure that a subnet mask has been specified. This prevents IPs from defaulting to a /32 or /128. | |
- if len(value.split('/')) != 2: | |
- raise ValidationError('CIDR mask (e.g. /24) is required.') | |
+ #if len(value.split('/')) != 2: | |
+ # raise ValidationError('CIDR mask (e.g. /24) is required.') | |
try: | |
return IPNetwork(value) | |
diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py | |
index d37fdec..8f6b44c 100644 | |
--- a/netbox/ipam/models.py | |
+++ b/netbox/ipam/models.py | |
@@ -419,6 +419,8 @@ class IPAddress(CreatedUpdatedModel, CustomFieldModel): | |
verbose_name_plural = 'IP addresses' | |
def __str__(self): | |
+ if self.address and self.address.size == 1: | |
+ return str(self.address.ip) | |
return str(self.address) | |
def get_absolute_url(self): | |
diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py | |
index 6c99f7d..f3caa02 100644 | |
--- a/netbox/ipam/tables.py | |
+++ b/netbox/ipam/tables.py | |
@@ -68,7 +68,11 @@ PREFIX_ROLE_LINK = """ | |
IPADDRESS_LINK = """ | |
{% if record.pk %} | |
+ {% if record.address and record.address.size == 1 %} | |
+ <a href="{{ record.get_absolute_url }}">{{ record.address.ip }}</a> | |
+ {% else %} | |
<a href="{{ record.get_absolute_url }}">{{ record.address }}</a> | |
+ {% endif %} | |
{% elif perms.ipam.add_ipaddress %} | |
<a href="{% url 'ipam:ipaddress_add' %}?address={{ record.1 }}{% if prefix.vrf %}&vrf={{ prefix.vrf.pk }}{% endif %}" class="btn btn-xs btn-success">{% if record.0 <= 65536 %}{{ record.0 }}{% else %}Lots of{% endif %} free IP{{ record.0|pluralize }}</a> | |
{% else %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment