From 3c36bec298217e56cc0a36384d278ca5b4523d62 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 10 Dec 2019 10:50:46 -0500 Subject: [PATCH 01/11] 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 9e17e4bb4..413850725 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -12,7 +12,7 @@ from django.core.exceptions import ImproperlyConfigured # Environment setup # -VERSION = '2.6.8' +VERSION = '2.6.9-dev' # Hostname HOSTNAME = platform.node() From 3b76e0203a349be3318979e1266c34b3435f648b Mon Sep 17 00:00:00 2001 From: hSaria <34197532+hSaria@users.noreply.github.com> Date: Wed, 11 Dec 2019 07:03:39 +0000 Subject: [PATCH 02/11] Fixes 3749 attribute error --- netbox/users/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/users/views.py b/netbox/users/views.py index 47d3503d7..6a2410274 100644 --- a/netbox/users/views.py +++ b/netbox/users/views.py @@ -96,7 +96,7 @@ class ChangePasswordView(LoginRequiredMixin, View): def get(self, request): # LDAP users cannot change their password here - if getattr(request.user, 'ldap_username'): + if getattr(request.user, 'ldap_username', None): messages.warning(request, "LDAP-authenticated user credentials cannot be changed within NetBox.") return redirect('user:profile') From b57d64c72db7987168d7f971bd9c8a2c95202b92 Mon Sep 17 00:00:00 2001 From: hSaria <34197532+hSaria@users.noreply.github.com> Date: Wed, 11 Dec 2019 07:11:59 +0000 Subject: [PATCH 03/11] Changelog for #3751 --- docs/release-notes/version-2.6.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index f499ec1ca..59d34495f 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -1,3 +1,9 @@ +# v2.6.9 (FUTURE) + +## Bug Fixes + +* [#3749](https://github.com/netbox-community/netbox/issues/3749) - Fix exception on password change page for local users + # v2.6.8 (2019-12-10) ## Enhancements From 77e0564d13a72f13363a5188489b9a04829399b4 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 13 Dec 2019 10:12:46 -0500 Subject: [PATCH 04/11] Closes #3152: Include direct link to rack elevations on site view --- docs/release-notes/version-2.6.md | 4 +++ netbox/templates/dcim/site.html | 41 +++++++++++++++++-------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 59d34495f..974a3e39d 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -1,5 +1,9 @@ # v2.6.9 (FUTURE) +## Enhancements + +* [#3152](https://github.com/netbox-community/netbox/issues/3152) - Include direct link to rack elevations on site view + ## Bug Fixes * [#3749](https://github.com/netbox-community/netbox/issues/3749) - Fix exception on password change page for local users diff --git a/netbox/templates/dcim/site.html b/netbox/templates/dcim/site.html index 0e38d2967..10e951efe 100644 --- a/netbox/templates/dcim/site.html +++ b/netbox/templates/dcim/site.html @@ -251,25 +251,28 @@
Rack Groups
- {% if rack_groups %} - - {% for rg in rack_groups %} - - - - - - {% endfor %} -
{{ rg }}{{ rg.rack_count }} - - - -
- {% else %} -
- None -
- {% endif %} + + {% for rg in rack_groups %} + + + + + + {% endfor %} + + + + + +
{{ rg }}{{ rg.rack_count }} + + + +
All racks{{ stats.rack_count }} + + + +
From 85c11bbd839e1e27f3b9bc99c653a902c6e42095 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 13 Dec 2019 10:37:58 -0500 Subject: [PATCH 05/11] Closes #3441: Move virtual machine results near devices in global search --- docs/release-notes/version-2.6.md | 1 + netbox/netbox/views.py | 34 +++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 974a3e39d..005a8f7c0 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -3,6 +3,7 @@ ## Enhancements * [#3152](https://github.com/netbox-community/netbox/issues/3152) - Include direct link to rack elevations on site view +* [#3441](https://github.com/netbox-community/netbox/issues/3441) - Move virtual machine results near devices in global search ## Bug Fixes diff --git a/netbox/netbox/views.py b/netbox/netbox/views.py index 05036a37a..5dee6cade 100644 --- a/netbox/netbox/views.py +++ b/netbox/netbox/views.py @@ -116,6 +116,23 @@ SEARCH_TYPES = OrderedDict(( 'table': PowerFeedTable, 'url': 'dcim:powerfeed_list', }), + # Virtualization + ('cluster', { + 'permission': 'virtualization.view_cluster', + 'queryset': Cluster.objects.prefetch_related('type', 'group'), + 'filter': ClusterFilter, + 'table': ClusterTable, + 'url': 'virtualization:cluster_list', + }), + ('virtualmachine', { + 'permission': 'virtualization.view_virtualmachine', + 'queryset': VirtualMachine.objects.prefetch_related( + 'cluster', 'tenant', 'platform', 'primary_ip4', 'primary_ip6', + ), + 'filter': VirtualMachineFilter, + 'table': VirtualMachineDetailTable, + 'url': 'virtualization:virtualmachine_list', + }), # IPAM ('vrf', { 'permission': 'ipam.view_vrf', @@ -168,23 +185,6 @@ SEARCH_TYPES = OrderedDict(( 'table': TenantTable, 'url': 'tenancy:tenant_list', }), - # Virtualization - ('cluster', { - 'permission': 'virtualization.view_cluster', - 'queryset': Cluster.objects.prefetch_related('type', 'group'), - 'filter': ClusterFilter, - 'table': ClusterTable, - 'url': 'virtualization:cluster_list', - }), - ('virtualmachine', { - 'permission': 'virtualization.view_virtualmachine', - 'queryset': VirtualMachine.objects.prefetch_related( - 'cluster', 'tenant', 'platform', 'primary_ip4', 'primary_ip6', - ), - 'filter': VirtualMachineFilter, - 'table': VirtualMachineDetailTable, - 'url': 'virtualization:virtualmachine_list', - }), )) From 462cede8631e45630482d7332a0faa9c274253f8 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 13 Dec 2019 11:36:31 -0500 Subject: [PATCH 06/11] Fixes #2170: Prevent the deletion of a virtual chassis when a cross-member LAG is present --- docs/release-notes/version-2.6.md | 1 + netbox/dcim/models.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 005a8f7c0..5a64ceb9e 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -7,6 +7,7 @@ ## Bug Fixes +* [#2170](https://github.com/netbox-community/netbox/issues/2170) - Prevent the deletion of a virtual chassis when a cross-member LAG is present * [#3749](https://github.com/netbox-community/netbox/issues/3749) - Fix exception on password change page for local users # v2.6.8 (2019-12-10) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index ad2a3d769..db88901b6 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -9,7 +9,7 @@ from django.contrib.postgres.fields import ArrayField, JSONField from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models -from django.db.models import Count, Q, Sum +from django.db.models import Count, F, ProtectedError, Q, Sum from django.urls import reverse from mptt.models import MPTTModel, TreeForeignKey from taggit.managers import TaggableManager @@ -2730,6 +2730,24 @@ class VirtualChassis(ChangeLoggedModel): 'master': "The selected master is not assigned to this virtual chassis." }) + def delete(self, *args, **kwargs): + + # Check for LAG interfaces split across member chassis + interfaces = Interface.objects.filter( + device__in=self.members.all(), + lag__isnull=False + ).exclude( + lag__device=F('device') + ) + if interfaces: + raise ProtectedError( + "Unable to delete virtual chassis {}. There are member interfaces which form a cross-chassis " + "LAG".format(self), + interfaces + ) + + return super().delete(*args, **kwargs) + def to_csv(self): return ( self.master, From 6a6959d0411eee32fe06be66e83ceec1f7262824 Mon Sep 17 00:00:00 2001 From: hSaria <34197532+hSaria@users.noreply.github.com> Date: Fri, 13 Dec 2019 18:06:14 +0000 Subject: [PATCH 07/11] Fixes #3761: copy button for tokens --- netbox/templates/users/api_tokens.html | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/netbox/templates/users/api_tokens.html b/netbox/templates/users/api_tokens.html index c6a219381..b775af73e 100644 --- a/netbox/templates/users/api_tokens.html +++ b/netbox/templates/users/api_tokens.html @@ -10,6 +10,7 @@
+ Copy {% if perms.users.change_token %} Edit {% endif %} @@ -17,7 +18,8 @@ Delete {% endif %}
- {{ token.key }} + + {{ token.key }} {% if token.is_expired %} Expired {% endif %} @@ -66,3 +68,9 @@
{% endblock %} + +{% block javascript %} + +{% endblock %} From ea51aa97b764e83ce6780453b443015e279b595c Mon Sep 17 00:00:00 2001 From: hSaria <34197532+hSaria@users.noreply.github.com> Date: Fri, 13 Dec 2019 18:08:34 +0000 Subject: [PATCH 08/11] Update version-2.6.md --- docs/release-notes/version-2.6.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 5a64ceb9e..7acf93cc7 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -4,6 +4,7 @@ * [#3152](https://github.com/netbox-community/netbox/issues/3152) - Include direct link to rack elevations on site view * [#3441](https://github.com/netbox-community/netbox/issues/3441) - Move virtual machine results near devices in global search +* [#3761](https://github.com/netbox-community/netbox/issues/3761) - Added copy button for API tokens ## Bug Fixes From a22c7c1539b67e9b19717927f1b25a71c31f6eb2 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 13 Dec 2019 14:15:48 -0500 Subject: [PATCH 09/11] Fixes #2358: Respect custom field default values when creating objects via the REST API --- docs/release-notes/version-2.6.md | 1 + netbox/extras/api/customfields.py | 29 ++++++++++++++++---- netbox/extras/tests/test_customfields.py | 34 ++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 5a64ceb9e..599c20c3b 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -8,6 +8,7 @@ ## Bug Fixes * [#2170](https://github.com/netbox-community/netbox/issues/2170) - Prevent the deletion of a virtual chassis when a cross-member LAG is present +* [#2358](https://github.com/netbox-community/netbox/issues/2358) - Respect custom field default values when creating objects via the REST API * [#3749](https://github.com/netbox-community/netbox/issues/3749) - Fix exception on password change page for local users # v2.6.8 (2019-12-10) diff --git a/netbox/extras/api/customfields.py b/netbox/extras/api/customfields.py index 42dc486b8..2a13e5ce1 100644 --- a/netbox/extras/api/customfields.py +++ b/netbox/extras/api/customfields.py @@ -22,7 +22,9 @@ class CustomFieldsSerializer(serializers.BaseSerializer): def to_internal_value(self, data): content_type = ContentType.objects.get_for_model(self.parent.Meta.model) - custom_fields = {field.name: field for field in CustomField.objects.filter(obj_type=content_type)} + custom_fields = { + field.name: field for field in CustomField.objects.filter(obj_type=content_type) + } for field_name, value in data.items(): @@ -107,11 +109,11 @@ class CustomFieldModelSerializer(ValidatedModelSerializer): super().__init__(*args, **kwargs) - if self.instance is not None: + # Retrieve the set of CustomFields which apply to this type of object + content_type = ContentType.objects.get_for_model(self.Meta.model) + fields = CustomField.objects.filter(obj_type=content_type) - # Retrieve the set of CustomFields which apply to this type of object - content_type = ContentType.objects.get_for_model(self.Meta.model) - fields = CustomField.objects.filter(obj_type=content_type) + if self.instance is not None: # Populate CustomFieldValues for each instance from database try: @@ -120,6 +122,23 @@ class CustomFieldModelSerializer(ValidatedModelSerializer): except TypeError: _populate_custom_fields(self.instance, fields) + else: + + # Populate default values + if fields and 'custom_fields' not in self.initial_data: + self.initial_data['custom_fields'] = {} + + # Populate initial data using custom field default values + for field in fields: + if field.name not in self.initial_data['custom_fields'] and field.default: + if field.type == CF_TYPE_SELECT: + field_value = field.choices.get(value=field.default).pk + elif field.type == CF_TYPE_BOOLEAN: + field_value = bool(field.default) + else: + field_value = field.default + self.initial_data['custom_fields'][field.name] = field_value + def _save_custom_fields(self, instance, custom_fields): content_type = ContentType.objects.get_for_model(self.Meta.model) for field_name, value in custom_fields.items(): diff --git a/netbox/extras/tests/test_customfields.py b/netbox/extras/tests/test_customfields.py index 96f3483bc..7db4e26d9 100644 --- a/netbox/extras/tests/test_customfields.py +++ b/netbox/extras/tests/test_customfields.py @@ -301,6 +301,40 @@ class CustomFieldAPITest(APITestCase): cfv = self.site.custom_field_values.get(field=self.cf_select) self.assertEqual(cfv.value.pk, data['custom_fields']['magic_choice']) + def test_set_custom_field_defaults(self): + """ + Create a new object with no custom field data. Custom field values should be created using the custom fields' + default values. + """ + CUSTOM_FIELD_DEFAULTS = { + 'magic_word': 'foobar', + 'magic_number': '123', + 'is_magic': 'true', + 'magic_date': '2019-12-13', + 'magic_url': 'http://example.com/', + 'magic_choice': self.cf_select_choice1.value, + } + + # Update CustomFields to set default values + for field_name, default_value in CUSTOM_FIELD_DEFAULTS.items(): + CustomField.objects.filter(name=field_name).update(default=default_value) + + data = { + 'name': 'Test Site X', + 'slug': 'test-site-x', + } + + url = reverse('dcim-api:site-list') + response = self.client.post(url, data, format='json', **self.header) + + self.assertHttpStatus(response, status.HTTP_201_CREATED) + self.assertEqual(response.data['custom_fields']['magic_word'], CUSTOM_FIELD_DEFAULTS['magic_word']) + self.assertEqual(response.data['custom_fields']['magic_number'], str(CUSTOM_FIELD_DEFAULTS['magic_number'])) + self.assertEqual(response.data['custom_fields']['is_magic'], bool(CUSTOM_FIELD_DEFAULTS['is_magic'])) + self.assertEqual(response.data['custom_fields']['magic_date'], CUSTOM_FIELD_DEFAULTS['magic_date']) + self.assertEqual(response.data['custom_fields']['magic_url'], CUSTOM_FIELD_DEFAULTS['magic_url']) + self.assertEqual(response.data['custom_fields']['magic_choice'], self.cf_select_choice1.pk) + class CustomFieldChoiceAPITest(APITestCase): def setUp(self): From 1d1cb867cd0fbded359421143213f2edfa020c60 Mon Sep 17 00:00:00 2001 From: kobayashi Date: Fri, 13 Dec 2019 14:24:11 -0500 Subject: [PATCH 10/11] fix 3679 --- docs/release-notes/version-2.6.md | 1 + netbox/ipam/tables.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 5a64ceb9e..538474912 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -9,6 +9,7 @@ * [#2170](https://github.com/netbox-community/netbox/issues/2170) - Prevent the deletion of a virtual chassis when a cross-member LAG is present * [#3749](https://github.com/netbox-community/netbox/issues/3749) - Fix exception on password change page for local users +* [#3757](https://github.com/netbox-community/netbox/issues/3757) - Fix unable to assign IP to interface # v2.6.8 (2019-12-10) diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py index 91f195ba0..e4d2bf8b4 100644 --- a/netbox/ipam/tables.py +++ b/netbox/ipam/tables.py @@ -85,7 +85,11 @@ IPADDRESS_LINK = """ """ IPADDRESS_ASSIGN_LINK = """ -{{ record }} +{% if request.GET %} + {{ record }} +{% else %} + {{ record }} +{% endif %} """ IPADDRESS_PARENT = """ From e53e1e31de5e8836fad67048ed0944addda0550c Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 16 Dec 2019 16:30:20 -0500 Subject: [PATCH 11/11] Release v2.6.9 --- docs/release-notes/version-2.6.md | 2 +- netbox/netbox/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 4d047cb69..afad93fde 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -1,4 +1,4 @@ -# v2.6.9 (FUTURE) +# v2.6.9 (2019-12-16) ## Enhancements diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 413850725..701af3c12 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -12,7 +12,7 @@ from django.core.exceptions import ImproperlyConfigured # Environment setup # -VERSION = '2.6.9-dev' +VERSION = '2.6.9' # Hostname HOSTNAME = platform.node()