From 6037f99d60e0382e92983109eb452dadbff48953 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Sat, 13 Aug 2016 01:02:03 -0400 Subject: [PATCH 1/8] Fixes #460: Corrected ordering of IP addresses with differing prefix lengths --- netbox/ipam/models.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py index bd49feef1..65724d410 100644 --- a/netbox/ipam/models.py +++ b/netbox/ipam/models.py @@ -5,6 +5,7 @@ from django.core.exceptions import ValidationError from django.core.urlresolvers import reverse from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models +from django.db.models.expressions import RawSQL from dcim.models import Interface from tenancy.models import Tenant @@ -295,6 +296,18 @@ class Prefix(CreatedUpdatedModel): return STATUS_CHOICE_CLASSES[self.status] +class IPAddressManager(models.Manager): + + def get_queryset(self): + """ + By default, PostgreSQL will order INETs with shorter (larger) prefix lengths ahead of those with longer + (smaller) masks. This makes no sense when ordering IPs, which should be ordered solely by family and host + address. Here, we alter the default ordering to use HOST(address) instead of the raw address value. + """ + qs = super(IPAddressManager, self).get_queryset() + return qs.annotate(host=RawSQL('HOST(ipam_ipaddress.address)', [])).order_by('family', 'host') + + class IPAddress(CreatedUpdatedModel): """ An IPAddress represents an individual IPv4 or IPv6 address and its mask. The mask length should match what is @@ -317,6 +330,8 @@ class IPAddress(CreatedUpdatedModel): null=True, verbose_name='NAT IP (inside)') description = models.CharField(max_length=100, blank=True) + objects = IPAddressManager() + class Meta: ordering = ['family', 'address'] verbose_name = 'IP address' From b0c70a586fd2838aaf9ed15f0cce5dacec1568cc Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 15 Aug 2016 15:39:48 -0400 Subject: [PATCH 2/8] Fixes #460: For real this time --- netbox/ipam/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py index 65724d410..eebc43fad 100644 --- a/netbox/ipam/models.py +++ b/netbox/ipam/models.py @@ -302,10 +302,12 @@ class IPAddressManager(models.Manager): """ By default, PostgreSQL will order INETs with shorter (larger) prefix lengths ahead of those with longer (smaller) masks. This makes no sense when ordering IPs, which should be ordered solely by family and host - address. Here, we alter the default ordering to use HOST(address) instead of the raw address value. + address. We can use HOST() to extract just the host portion of the address (ignoring its mask), but we must + then re-cast this value to INET() so that records will be ordered properly. We are essentially re-casting each + IP address as a /32 or /128. """ qs = super(IPAddressManager, self).get_queryset() - return qs.annotate(host=RawSQL('HOST(ipam_ipaddress.address)', [])).order_by('family', 'host') + return qs.annotate(host=RawSQL('INET(HOST(ipam_ipaddress.address))', [])).order_by('family', 'host') class IPAddress(CreatedUpdatedModel): From d2af80fc4402a8c3eb0fdc42bfa77fdd3880ba69 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 15 Aug 2016 15:52:06 -0400 Subject: [PATCH 3/8] Fixes #468: Added validation to prevent a connected interface from having its form factor set to 'virtual' --- netbox/dcim/models.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index b1c6b60b7..a0e2b4e0f 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -1032,6 +1032,13 @@ class Interface(models.Model): def __unicode__(self): return self.name + def clean(self): + + if self.form_factor == IFACE_FF_VIRTUAL and self.is_connected: + raise ValidationError({'form_factor': "Virtual interfaces cannot be connected to another interface or " + "circuit. Disconnect the interface or choose a physical form " + "factor."}) + @property def is_physical(self): return self.form_factor != IFACE_FF_VIRTUAL From 19fb121db9ec8fca75c9f16c331eb71146c44618 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 15 Aug 2016 16:11:17 -0400 Subject: [PATCH 4/8] Fixes #467: Include prefixes and IPs which inherit tenancy from their VRF in tenant stats --- netbox/tenancy/views.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/netbox/tenancy/views.py b/netbox/tenancy/views.py index ec220b9be..a11915458 100644 --- a/netbox/tenancy/views.py +++ b/netbox/tenancy/views.py @@ -1,5 +1,5 @@ from django.contrib.auth.mixins import PermissionRequiredMixin -from django.db.models import Count +from django.db.models import Count, Q from django.shortcuts import get_object_or_404, render from circuits.models import Circuit @@ -59,8 +59,14 @@ def tenant(request, slug): 'rack_count': Rack.objects.filter(tenant=tenant).count(), 'device_count': Device.objects.filter(tenant=tenant).count(), 'vrf_count': VRF.objects.filter(tenant=tenant).count(), - 'prefix_count': Prefix.objects.filter(tenant=tenant).count(), - 'ipaddress_count': IPAddress.objects.filter(tenant=tenant).count(), + 'prefix_count': Prefix.objects.filter( + Q(tenant=tenant) | + Q(tenant__isnull=True, vrf__tenant=tenant) + ).count(), + 'ipaddress_count': IPAddress.objects.filter( + Q(tenant=tenant) | + Q(tenant__isnull=True, vrf__tenant=tenant) + ).count(), 'vlan_count': VLAN.objects.filter(tenant=tenant).count(), 'circuit_count': Circuit.objects.filter(tenant=tenant).count(), } From f888b7a1e4046102570df632ab4c2e4004ea5c6d Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 15 Aug 2016 17:57:17 -0400 Subject: [PATCH 5/8] Fixes #469: Added missing import buttons to list views --- netbox/templates/circuits/circuit_list.html | 4 ++++ netbox/templates/circuits/provider_list.html | 4 ++++ netbox/templates/ipam/aggregate_list.html | 4 ++++ netbox/templates/tenancy/tenant_list.html | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/netbox/templates/circuits/circuit_list.html b/netbox/templates/circuits/circuit_list.html index f30339ec6..db6861b2e 100644 --- a/netbox/templates/circuits/circuit_list.html +++ b/netbox/templates/circuits/circuit_list.html @@ -10,6 +10,10 @@ Add a circuit + + + Import circuits + {% endif %} {% include 'inc/export_button.html' with obj_type='circuits' %} diff --git a/netbox/templates/circuits/provider_list.html b/netbox/templates/circuits/provider_list.html index 54dfdac93..ca3dbfc09 100644 --- a/netbox/templates/circuits/provider_list.html +++ b/netbox/templates/circuits/provider_list.html @@ -9,6 +9,10 @@ Add a provider + + + Import providers + {% endif %} {% include 'inc/export_button.html' with obj_type='providers' %} diff --git a/netbox/templates/ipam/aggregate_list.html b/netbox/templates/ipam/aggregate_list.html index 52bca7219..aef7d84c1 100644 --- a/netbox/templates/ipam/aggregate_list.html +++ b/netbox/templates/ipam/aggregate_list.html @@ -11,6 +11,10 @@ Add an aggregate + + + Import aggregates + {% endif %} {% include 'inc/export_button.html' with obj_type='aggregates' %} diff --git a/netbox/templates/tenancy/tenant_list.html b/netbox/templates/tenancy/tenant_list.html index 24f796da3..529f01c76 100644 --- a/netbox/templates/tenancy/tenant_list.html +++ b/netbox/templates/tenancy/tenant_list.html @@ -10,6 +10,10 @@ Add a tenant + + + Import tenants + {% endif %} {% include 'inc/export_button.html' with obj_type='tenants' %} From 019c125f42447135ed9f4303784820ef895e0860 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 16 Aug 2016 09:29:20 -0400 Subject: [PATCH 6/8] Fixes #472: Hide the connection button for interfaces which have a circuit terminated to them --- netbox/templates/dcim/inc/_interface.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/netbox/templates/dcim/inc/_interface.html b/netbox/templates/dcim/inc/_interface.html index a3d1b8e04..a48200c30 100644 --- a/netbox/templates/dcim/inc/_interface.html +++ b/netbox/templates/dcim/inc/_interface.html @@ -56,6 +56,10 @@ + {% elif iface.circuit and perms.circuits.change_circuit %} + + + {% else %} From 2212979718e9a4444fa10656d0997df8ccf65dc0 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 16 Aug 2016 09:32:53 -0400 Subject: [PATCH 7/8] Release v1.5.2 --- netbox/netbox/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 81098d5c5..0384382b0 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -12,7 +12,7 @@ except ImportError: "the documentation.") -VERSION = '1.5.2-dev' +VERSION = '1.5.2' # Import local configuration for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']: From dfbf703f8ff3d30747bd96932d41d1f8f84aa1fe Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 16 Aug 2016 09:34:26 -0400 Subject: [PATCH 8/8] Post-release version bump --- netbox/netbox/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 0384382b0..6e2359ebe 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -12,7 +12,7 @@ except ImportError: "the documentation.") -VERSION = '1.5.2' +VERSION = '1.5.3-dev' # Import local configuration for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']: