From be8fef0228c0cad77c0b49f357fbb92f7431a37c Mon Sep 17 00:00:00 2001 From: Jason Yates Date: Tue, 11 Jan 2022 21:03:18 +0000 Subject: [PATCH 01/42] Fixes #8279 A device that is part of a VC that has no name should display [virtual-chassis name]:[virtual-chassis position] as opposed to [device_type] in the rack rendering. --- netbox/dcim/svg.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/netbox/dcim/svg.py b/netbox/dcim/svg.py index e19e8fa2f..1058d8385 100644 --- a/netbox/dcim/svg.py +++ b/netbox/dcim/svg.py @@ -19,7 +19,12 @@ __all__ = ( def get_device_name(device): - return device.name or str(device.device_type) + if device.virtual_chassis: + return f'{device.virtual_chassis.name}:{device.vc_position}' + elif device.name: + return device.name + else: + return str(device.device_type) class RackElevationSVG: From d08accaaf14a4c0b6d4f84d7bdf1439c2f6d56c9 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 11 Jan 2022 16:27:30 -0500 Subject: [PATCH 02/42] Changelog for #8279 --- docs/release-notes/version-3.1.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 898d77437..dac6119aa 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -11,6 +11,7 @@ ### Bug Fixes +* [#8279](https://github.com/netbox-community/netbox/issues/8279) - Fix display of virtual chassis members in rack elevations * [#8285](https://github.com/netbox-community/netbox/issues/8285) - Fix `cluster_count` under tenant REST API serializer * [#8287](https://github.com/netbox-community/netbox/issues/8287) - Correct label in export template form * [#8301](https://github.com/netbox-community/netbox/issues/8301) - Fix delete button for various object children views From ea644868a6c072c8131c9b3e16071e3a54569d73 Mon Sep 17 00:00:00 2001 From: Jason Yates Date: Wed, 12 Jan 2022 14:06:22 +0000 Subject: [PATCH 03/42] Adding asdot notation to ASN views Adds custom property to asn model to compute asdot notation if required. Updates asn view to show asdot notation if one exists in the format xxxxx (yyy.yyy) Adds a custom column renderer to asn table to display asdot notation if one exists --- netbox/ipam/models/ip.py | 8 ++++++++ netbox/ipam/tables/ip.py | 7 +++++++ netbox/templates/ipam/asn.html | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index 9c00a9068..c92b54537 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -130,6 +130,14 @@ class ASN(PrimaryModel): def get_absolute_url(self): return reverse('ipam:asn', args=[self.pk]) + @property + def asdot_notation(self): + # Return asdot notation for an ASN larger than 65535 + if self.asn > 65535: + return '{}.{}'.format(self.asn // 65536, self.asn % 65536) + else: + return None + @extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks') class Aggregate(GetAvailablePrefixesMixin, PrimaryModel): diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index 3fddbf48e..988c89aa2 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -106,6 +106,13 @@ class ASNTable(BaseTable): asn = tables.Column( linkify=True ) + + def render_asn(self, value, record): + if record.asdot_notation: + return f'{value} ({record.asdot_notation})' + else: + return value + site_count = LinkedCountColumn( viewname='dcim:site_list', url_params={'asn_id': 'pk'}, diff --git a/netbox/templates/ipam/asn.html b/netbox/templates/ipam/asn.html index 53afd5ebb..85eaf8122 100644 --- a/netbox/templates/ipam/asn.html +++ b/netbox/templates/ipam/asn.html @@ -18,7 +18,7 @@ - + From 85f588e8c9965193b3b037fab1c65b473fd6665e Mon Sep 17 00:00:00 2001 From: Jason Yates Date: Wed, 12 Jan 2022 16:44:22 +0000 Subject: [PATCH 04/42] Updating page title to include asdot notation --- netbox/ipam/models/ip.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index c92b54537..fa27aaf1b 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -125,7 +125,10 @@ class ASN(PrimaryModel): verbose_name_plural = 'ASNs' def __str__(self): - return f'AS{self.asn}' + if self.asn > 65535: + return 'AS{} ({}.{})'.format(self.asn, self.asn // 65536, self.asn % 65536) + else: + return f'AS{self.asn}' def get_absolute_url(self): return reverse('ipam:asn', args=[self.pk]) From e19451bb4fca23014bda6528df82898f3776c218 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 12 Jan 2022 14:40:33 -0500 Subject: [PATCH 05/42] Plug WG8333 in the plugins development docs --- docs/plugins/development.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/plugins/development.md b/docs/plugins/development.md index cde659a45..9d1ad1444 100644 --- a/docs/plugins/development.md +++ b/docs/plugins/development.md @@ -1,5 +1,8 @@ # Plugin Development +!!! info "Help Improve the NetBox Plugins Framework!" + We're looking for volunteers to help improve NetBox's plugins framework. If you have experience developing plugins, we'd love to hear from you! You can find more information about this initiative [here](https://github.com/netbox-community/netbox/discussions/8338). + This documentation covers the development of custom plugins for NetBox. Plugins are essentially self-contained [Django apps](https://docs.djangoproject.com/en/stable/) which integrate with NetBox to provide custom functionality. Since the development of Django apps is already very well-documented, we'll only be covering the aspects that are specific to NetBox. Plugins can do a lot, including: From 62fc7717c84a31a9a83cae4af25d26cbea128828 Mon Sep 17 00:00:00 2001 From: Jason Yates Date: Thu, 13 Jan 2022 04:58:51 +0000 Subject: [PATCH 06/42] Suggested changes * Updating asdot computation to use an fstring * Cleaning code. Custom property now returns either the ASN with ASDOT notation or just the ASN. asn_with_asdot can now be referenced in ASNTable & objet template. --- netbox/ipam/models/ip.py | 13 +++++-------- netbox/ipam/tables/ip.py | 5 +---- netbox/templates/ipam/asn.html | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index fa27aaf1b..5cce88481 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -125,21 +125,18 @@ class ASN(PrimaryModel): verbose_name_plural = 'ASNs' def __str__(self): - if self.asn > 65535: - return 'AS{} ({}.{})'.format(self.asn, self.asn // 65536, self.asn % 65536) - else: - return f'AS{self.asn}' + return f'AS{self.asn_with_asdot}' def get_absolute_url(self): return reverse('ipam:asn', args=[self.pk]) @property - def asdot_notation(self): - # Return asdot notation for an ASN larger than 65535 + def asn_with_asdot(self): + # Return asn with asdot notation for an ASN larger than 65535 otherwise return the plain ASN if self.asn > 65535: - return '{}.{}'.format(self.asn // 65536, self.asn % 65536) + return f'{self.asn} ({self.asn // 65536}.{self.asn % 65536})' else: - return None + return self.asn @extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks') diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index 988c89aa2..8efb1caf3 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -108,10 +108,7 @@ class ASNTable(BaseTable): ) def render_asn(self, value, record): - if record.asdot_notation: - return f'{value} ({record.asdot_notation})' - else: - return value + return record.asn_with_asdot site_count = LinkedCountColumn( viewname='dcim:site_list', diff --git a/netbox/templates/ipam/asn.html b/netbox/templates/ipam/asn.html index 85eaf8122..4a1ecda0d 100644 --- a/netbox/templates/ipam/asn.html +++ b/netbox/templates/ipam/asn.html @@ -18,7 +18,7 @@
AS Number{{ object.asn }}{{ object.asn }} {% if object.asdot_notation %}({{ object.asdot_notation }}){% endif %}
RIR
- + From 381796e7087453a5e5a8602514a51d980ca1e060 Mon Sep 17 00:00:00 2001 From: Jason Yates Date: Thu, 13 Jan 2022 09:22:32 +0000 Subject: [PATCH 07/42] Add created & last updated as available fields to all tables Adds two fields to all relevant tables to allow the addition of Created & Last Updated columns. All tables with a Configure Table option were updated. Some sections reformatted to comply with E501 line length as a result of changes --- netbox/circuits/tables.py | 8 ++++---- netbox/dcim/tables/cables.py | 2 +- netbox/dcim/tables/devices.py | 31 ++++++++++++++++++------------- netbox/dcim/tables/devicetypes.py | 4 ++-- netbox/dcim/tables/power.py | 4 ++-- netbox/dcim/tables/racks.py | 12 ++++++++---- netbox/dcim/tables/sites.py | 8 ++++---- netbox/extras/tables.py | 11 ++++++----- netbox/ipam/tables/fhrp.py | 2 +- netbox/ipam/tables/ip.py | 25 +++++++++++++++++-------- netbox/ipam/tables/services.py | 5 ++++- netbox/ipam/tables/vlans.py | 10 ++++++++-- netbox/ipam/tables/vrfs.py | 5 +++-- netbox/tenancy/tables.py | 15 ++++++++++----- netbox/virtualization/tables.py | 19 +++++++++++++------ netbox/wireless/tables.py | 8 +++++--- 16 files changed, 106 insertions(+), 63 deletions(-) diff --git a/netbox/circuits/tables.py b/netbox/circuits/tables.py index 29bf704f0..889792be3 100644 --- a/netbox/circuits/tables.py +++ b/netbox/circuits/tables.py @@ -66,7 +66,7 @@ class ProviderTable(BaseTable): model = Provider fields = ( 'pk', 'id', 'name', 'asn', 'account', 'portal_url', 'noc_contact', 'admin_contact', 'circuit_count', - 'comments', 'tags', + 'comments', 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'asn', 'account', 'circuit_count') @@ -90,7 +90,7 @@ class ProviderNetworkTable(BaseTable): class Meta(BaseTable.Meta): model = ProviderNetwork - fields = ('pk', 'id', 'name', 'provider', 'description', 'comments', 'tags') + fields = ('pk', 'id', 'name', 'provider', 'description', 'comments', 'tags', 'created', 'last_updated',) default_columns = ('pk', 'name', 'provider', 'description') @@ -113,7 +113,7 @@ class CircuitTypeTable(BaseTable): class Meta(BaseTable.Meta): model = CircuitType - fields = ('pk', 'id', 'name', 'circuit_count', 'description', 'slug', 'tags', 'actions') + fields = ('pk', 'id', 'name', 'circuit_count', 'description', 'slug', 'tags', 'actions', 'created', 'last_updated',) default_columns = ('pk', 'name', 'circuit_count', 'description', 'slug', 'actions') @@ -150,7 +150,7 @@ class CircuitTable(BaseTable): model = Circuit fields = ( 'pk', 'id', 'cid', 'provider', 'type', 'status', 'tenant', 'termination_a', 'termination_z', 'install_date', - 'commit_rate', 'description', 'comments', 'tags', + 'commit_rate', 'description', 'comments', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'cid', 'provider', 'type', 'status', 'tenant', 'termination_a', 'termination_z', 'description', diff --git a/netbox/dcim/tables/cables.py b/netbox/dcim/tables/cables.py index 9b912894b..bea2c0adf 100644 --- a/netbox/dcim/tables/cables.py +++ b/netbox/dcim/tables/cables.py @@ -56,7 +56,7 @@ class CableTable(BaseTable): model = Cable fields = ( 'pk', 'id', 'label', 'termination_a_parent', 'termination_a', 'termination_b_parent', 'termination_b', - 'status', 'type', 'tenant', 'color', 'length', 'tags', + 'status', 'type', 'tenant', 'color', 'length', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'id', 'label', 'termination_a_parent', 'termination_a', 'termination_b_parent', 'termination_b', diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index f0e9c9bb0..5f15d5fbf 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -97,7 +97,7 @@ class DeviceRoleTable(BaseTable): model = DeviceRole fields = ( 'pk', 'id', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'description', 'slug', 'tags', - 'actions', + 'actions', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'device_count', 'vm_count', 'color', 'vm_role', 'description', 'actions') @@ -130,7 +130,7 @@ class PlatformTable(BaseTable): model = Platform fields = ( 'pk', 'id', 'name', 'manufacturer', 'device_count', 'vm_count', 'slug', 'napalm_driver', 'napalm_args', - 'description', 'tags', 'actions', + 'description', 'tags', 'actions', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'manufacturer', 'device_count', 'vm_count', 'napalm_driver', 'description', 'actions', @@ -204,7 +204,8 @@ class DeviceTable(BaseTable): fields = ( 'pk', 'id', 'name', 'status', 'tenant', 'device_role', 'manufacturer', 'device_type', 'platform', 'serial', 'asset_tag', 'site', 'location', 'rack', 'position', 'face', 'primary_ip', 'airflow', 'primary_ip4', - 'primary_ip6', 'cluster', 'virtual_chassis', 'vc_position', 'vc_priority', 'comments', 'tags', + 'primary_ip6', 'cluster', 'virtual_chassis', 'vc_position', 'vc_priority', 'comments', 'tags', 'created', + 'last_updated', ) default_columns = ( 'pk', 'name', 'status', 'tenant', 'site', 'location', 'rack', 'device_role', 'manufacturer', 'device_type', @@ -297,7 +298,7 @@ class ConsolePortTable(DeviceComponentTable, PathEndpointTable): model = ConsolePort fields = ( 'pk', 'id', 'name', 'device', 'label', 'type', 'speed', 'description', 'mark_connected', 'cable', 'cable_color', - 'link_peer', 'connection', 'tags', + 'link_peer', 'connection', 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'device', 'label', 'type', 'speed', 'description') @@ -341,7 +342,7 @@ class ConsoleServerPortTable(DeviceComponentTable, PathEndpointTable): model = ConsoleServerPort fields = ( 'pk', 'id', 'name', 'device', 'label', 'type', 'speed', 'description', 'mark_connected', 'cable', - 'cable_color', 'link_peer', 'connection', 'tags', + 'cable_color', 'link_peer', 'connection', 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'device', 'label', 'type', 'speed', 'description') @@ -386,7 +387,7 @@ class PowerPortTable(DeviceComponentTable, PathEndpointTable): model = PowerPort fields = ( 'pk', 'id', 'name', 'device', 'label', 'type', 'description', 'mark_connected', 'maximum_draw', - 'allocated_draw', 'cable', 'cable_color', 'link_peer', 'connection', 'tags', + 'allocated_draw', 'cable', 'cable_color', 'link_peer', 'connection', 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'device', 'label', 'type', 'maximum_draw', 'allocated_draw', 'description') @@ -437,7 +438,7 @@ class PowerOutletTable(DeviceComponentTable, PathEndpointTable): model = PowerOutlet fields = ( 'pk', 'id', 'name', 'device', 'label', 'type', 'description', 'power_port', 'feed_leg', 'mark_connected', - 'cable', 'cable_color', 'link_peer', 'connection', 'tags', + 'cable', 'cable_color', 'link_peer', 'connection', 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'device', 'label', 'type', 'power_port', 'feed_leg', 'description') @@ -515,7 +516,7 @@ class InterfaceTable(DeviceComponentTable, BaseInterfaceTable, PathEndpointTable 'pk', 'id', 'name', 'device', 'label', 'enabled', 'type', 'mgmt_only', 'mtu', 'mode', 'mac_address', 'wwn', 'rf_role', 'rf_channel', 'rf_channel_frequency', 'rf_channel_width', 'tx_power', 'description', 'mark_connected', 'cable', 'cable_color', 'wireless_link', 'wireless_lans', 'link_peer', 'connection', - 'tags', 'ip_addresses', 'fhrp_groups', 'untagged_vlan', 'tagged_vlans', + 'tags', 'ip_addresses', 'fhrp_groups', 'untagged_vlan', 'tagged_vlans', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'device', 'label', 'enabled', 'type', 'description') @@ -586,7 +587,7 @@ class FrontPortTable(DeviceComponentTable, CableTerminationTable): model = FrontPort fields = ( 'pk', 'id', 'name', 'device', 'label', 'type', 'color', 'rear_port', 'rear_port_position', 'description', - 'mark_connected', 'cable', 'cable_color', 'link_peer', 'tags', + 'mark_connected', 'cable', 'cable_color', 'link_peer', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'device', 'label', 'type', 'color', 'rear_port', 'rear_port_position', 'description', @@ -637,7 +638,7 @@ class RearPortTable(DeviceComponentTable, CableTerminationTable): model = RearPort fields = ( 'pk', 'id', 'name', 'device', 'label', 'type', 'color', 'positions', 'description', 'mark_connected', 'cable', - 'cable_color', 'link_peer', 'tags', + 'cable_color', 'link_peer', 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'device', 'label', 'type', 'color', 'description') @@ -689,7 +690,11 @@ class DeviceBayTable(DeviceComponentTable): class Meta(DeviceComponentTable.Meta): model = DeviceBay - fields = ('pk', 'id', 'name', 'device', 'label', 'status', 'installed_device', 'description', 'tags') + fields = ( + 'pk', 'id', 'name', 'device', 'label', 'status', 'installed_device', 'description', 'tags', + 'created', 'last_updated', + ) + default_columns = ('pk', 'name', 'device', 'label', 'status', 'installed_device', 'description') @@ -736,7 +741,7 @@ class InventoryItemTable(DeviceComponentTable): model = InventoryItem fields = ( 'pk', 'id', 'name', 'device', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'description', - 'discovered', 'tags', + 'discovered', 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'device', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag') @@ -788,5 +793,5 @@ class VirtualChassisTable(BaseTable): class Meta(BaseTable.Meta): model = VirtualChassis - fields = ('pk', 'id', 'name', 'domain', 'master', 'member_count', 'tags') + fields = ('pk', 'id', 'name', 'domain', 'master', 'member_count', 'tags', 'created', 'last_updated',) default_columns = ('pk', 'name', 'domain', 'master', 'member_count') diff --git a/netbox/dcim/tables/devicetypes.py b/netbox/dcim/tables/devicetypes.py index 0aa8ac2bf..dc437ee96 100644 --- a/netbox/dcim/tables/devicetypes.py +++ b/netbox/dcim/tables/devicetypes.py @@ -50,7 +50,7 @@ class ManufacturerTable(BaseTable): model = Manufacturer fields = ( 'pk', 'id', 'name', 'devicetype_count', 'inventoryitem_count', 'platform_count', 'description', 'slug', - 'actions', + 'actions', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'devicetype_count', 'inventoryitem_count', 'platform_count', 'description', 'slug', 'actions', @@ -84,7 +84,7 @@ class DeviceTypeTable(BaseTable): model = DeviceType fields = ( 'pk', 'id', 'model', 'manufacturer', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', - 'airflow', 'comments', 'instance_count', 'tags', + 'airflow', 'comments', 'instance_count', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'model', 'manufacturer', 'part_number', 'u_height', 'is_full_depth', 'instance_count', diff --git a/netbox/dcim/tables/power.py b/netbox/dcim/tables/power.py index ac58b64de..c1ea8a34c 100644 --- a/netbox/dcim/tables/power.py +++ b/netbox/dcim/tables/power.py @@ -33,7 +33,7 @@ class PowerPanelTable(BaseTable): class Meta(BaseTable.Meta): model = PowerPanel - fields = ('pk', 'id', 'name', 'site', 'location', 'powerfeed_count', 'tags') + fields = ('pk', 'id', 'name', 'site', 'location', 'powerfeed_count', 'tags', 'created', 'last_updated',) default_columns = ('pk', 'name', 'site', 'location', 'powerfeed_count') @@ -72,7 +72,7 @@ class PowerFeedTable(CableTerminationTable): fields = ( 'pk', 'id', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase', 'max_utilization', 'mark_connected', 'cable', 'cable_color', 'link_peer', 'connection', 'available_power', - 'comments', 'tags', + 'comments', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase', 'cable', diff --git a/netbox/dcim/tables/racks.py b/netbox/dcim/tables/racks.py index 14bbe3589..dba28603c 100644 --- a/netbox/dcim/tables/racks.py +++ b/netbox/dcim/tables/racks.py @@ -31,7 +31,10 @@ class RackRoleTable(BaseTable): class Meta(BaseTable.Meta): model = RackRole - fields = ('pk', 'id', 'name', 'rack_count', 'color', 'description', 'slug', 'tags', 'actions') + fields = ( + 'pk', 'id', 'name', 'rack_count', 'color', 'description', 'slug', 'tags', 'actions', + 'created', 'last_updated', + ) default_columns = ('pk', 'name', 'rack_count', 'color', 'description', 'actions') @@ -87,8 +90,9 @@ class RackTable(BaseTable): class Meta(BaseTable.Meta): model = Rack fields = ( - 'pk', 'id', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'role', 'serial', 'asset_tag', 'type', - 'width', 'outer_width', 'outer_depth', 'u_height', 'comments', 'device_count', 'get_utilization', 'get_power_utilization', 'tags', + 'pk', 'id', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'role', 'serial', 'asset_tag', + 'type', 'width', 'outer_width', 'outer_depth', 'u_height', 'comments', 'device_count', 'get_utilization', + 'get_power_utilization', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'role', 'u_height', 'device_count', @@ -127,7 +131,7 @@ class RackReservationTable(BaseTable): model = RackReservation fields = ( 'pk', 'id', 'reservation', 'site', 'rack', 'unit_list', 'user', 'created', 'tenant', 'description', 'tags', - 'actions', + 'actions', 'created', 'last_updated', ) default_columns = ( 'pk', 'reservation', 'site', 'rack', 'unit_list', 'user', 'description', 'actions', diff --git a/netbox/dcim/tables/sites.py b/netbox/dcim/tables/sites.py index 8ef17c6f2..83e5fa408 100644 --- a/netbox/dcim/tables/sites.py +++ b/netbox/dcim/tables/sites.py @@ -36,7 +36,7 @@ class RegionTable(BaseTable): class Meta(BaseTable.Meta): model = Region - fields = ('pk', 'id', 'name', 'slug', 'site_count', 'description', 'tags', 'actions') + fields = ('pk', 'id', 'name', 'slug', 'site_count', 'description', 'tags', 'actions', 'created', 'last_updated') default_columns = ('pk', 'name', 'site_count', 'description', 'actions') @@ -61,7 +61,7 @@ class SiteGroupTable(BaseTable): class Meta(BaseTable.Meta): model = SiteGroup - fields = ('pk', 'id', 'name', 'slug', 'site_count', 'description', 'tags', 'actions') + fields = ('pk', 'id', 'name', 'slug', 'site_count', 'description', 'tags', 'actions', 'created', 'last_updated') default_columns = ('pk', 'name', 'site_count', 'description', 'actions') @@ -98,7 +98,7 @@ class SiteTable(BaseTable): fields = ( 'pk', 'id', 'name', 'slug', 'status', 'facility', 'region', 'group', 'tenant', 'asn_count', 'time_zone', 'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name', - 'contact_phone', 'contact_email', 'comments', 'tags', + 'contact_phone', 'contact_email', 'comments', 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'status', 'facility', 'region', 'group', 'tenant', 'description') @@ -138,6 +138,6 @@ class LocationTable(BaseTable): model = Location fields = ( 'pk', 'id', 'name', 'site', 'tenant', 'rack_count', 'device_count', 'description', 'slug', 'tags', - 'actions', + 'actions', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'site', 'tenant', 'rack_count', 'device_count', 'description', 'actions') diff --git a/netbox/extras/tables.py b/netbox/extras/tables.py index 266f2089a..bee21f697 100644 --- a/netbox/extras/tables.py +++ b/netbox/extras/tables.py @@ -58,7 +58,7 @@ class CustomFieldTable(BaseTable): model = CustomField fields = ( 'pk', 'id', 'name', 'content_types', 'label', 'type', 'required', 'weight', 'default', - 'description', 'filter_logic', 'choices', + 'description', 'filter_logic', 'choices', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'content_types', 'label', 'type', 'required', 'description') @@ -79,7 +79,7 @@ class CustomLinkTable(BaseTable): model = CustomLink fields = ( 'pk', 'id', 'name', 'content_type', 'link_text', 'link_url', 'weight', 'group_name', - 'button_class', 'new_window', + 'button_class', 'new_window', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'content_type', 'group_name', 'button_class', 'new_window') @@ -100,6 +100,7 @@ class ExportTemplateTable(BaseTable): model = ExportTemplate fields = ( 'pk', 'id', 'name', 'content_type', 'description', 'mime_type', 'file_extension', 'as_attachment', + 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'content_type', 'description', 'mime_type', 'file_extension', 'as_attachment', @@ -134,7 +135,7 @@ class WebhookTable(BaseTable): model = Webhook fields = ( 'pk', 'id', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method', - 'payload_url', 'secret', 'ssl_validation', 'ca_file_path', + 'payload_url', 'secret', 'ssl_validation', 'ca_file_path', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'content_types', 'enabled', 'type_create', 'type_update', 'type_delete', 'http_method', @@ -156,7 +157,7 @@ class TagTable(BaseTable): class Meta(BaseTable.Meta): model = Tag - fields = ('pk', 'id', 'name', 'items', 'slug', 'color', 'description', 'actions') + fields = ('pk', 'id', 'name', 'items', 'slug', 'color', 'description', 'actions', 'created', 'last_updated',) default_columns = ('pk', 'name', 'items', 'slug', 'color', 'description', 'actions') @@ -193,7 +194,7 @@ class ConfigContextTable(BaseTable): model = ConfigContext fields = ( 'pk', 'id', 'name', 'weight', 'is_active', 'description', 'regions', 'sites', 'roles', - 'platforms', 'cluster_groups', 'clusters', 'tenant_groups', 'tenants', + 'platforms', 'cluster_groups', 'clusters', 'tenant_groups', 'tenants', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'weight', 'is_active', 'description') diff --git a/netbox/ipam/tables/fhrp.py b/netbox/ipam/tables/fhrp.py index 766345e49..a8a25f319 100644 --- a/netbox/ipam/tables/fhrp.py +++ b/netbox/ipam/tables/fhrp.py @@ -38,7 +38,7 @@ class FHRPGroupTable(BaseTable): model = FHRPGroup fields = ( 'pk', 'group_id', 'protocol', 'auth_type', 'auth_key', 'description', 'ip_addresses', 'interface_count', - 'tags', + 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'group_id', 'protocol', 'auth_type', 'description', 'ip_addresses', 'interface_count') diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index 3fddbf48e..477702012 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -93,7 +93,10 @@ class RIRTable(BaseTable): class Meta(BaseTable.Meta): model = RIR - fields = ('pk', 'id', 'name', 'slug', 'is_private', 'aggregate_count', 'description', 'tags', 'actions') + fields = ( + 'pk', 'id', 'name', 'slug', 'is_private', 'aggregate_count', 'description', 'tags', 'actions', 'created', + 'last_updated', + ) default_columns = ('pk', 'name', 'is_private', 'aggregate_count', 'description', 'actions') @@ -115,7 +118,7 @@ class ASNTable(BaseTable): class Meta(BaseTable.Meta): model = ASN - fields = ('pk', 'asn', 'rir', 'site_count', 'tenant', 'description', 'actions') + fields = ('pk', 'asn', 'rir', 'site_count', 'tenant', 'description', 'actions', 'created', 'last_updated',) default_columns = ('pk', 'asn', 'rir', 'site_count', 'sites', 'tenant', 'actions') @@ -147,7 +150,10 @@ class AggregateTable(BaseTable): class Meta(BaseTable.Meta): model = Aggregate - fields = ('pk', 'id', 'prefix', 'rir', 'tenant', 'child_count', 'utilization', 'date_added', 'description', 'tags') + fields = ( + 'pk', 'id', 'prefix', 'rir', 'tenant', 'child_count', 'utilization', 'date_added', 'description', 'tags', + 'created', 'last_updated', + ) default_columns = ('pk', 'prefix', 'rir', 'tenant', 'child_count', 'utilization', 'date_added', 'description') @@ -177,7 +183,10 @@ class RoleTable(BaseTable): class Meta(BaseTable.Meta): model = Role - fields = ('pk', 'id', 'name', 'slug', 'prefix_count', 'vlan_count', 'description', 'weight', 'tags', 'actions') + fields = ( + 'pk', 'id', 'name', 'slug', 'prefix_count', 'vlan_count', 'description', 'weight', 'tags', 'actions', + 'created', 'last_updated', + ) default_columns = ('pk', 'name', 'prefix_count', 'vlan_count', 'description', 'actions') @@ -264,8 +273,8 @@ class PrefixTable(BaseTable): class Meta(BaseTable.Meta): model = Prefix fields = ( - 'pk', 'id', 'prefix', 'prefix_flat', 'status', 'children', 'vrf', 'utilization', 'tenant', 'site', 'vlan_group', - 'vlan', 'role', 'is_pool', 'mark_utilized', 'description', 'tags', + 'pk', 'id', 'prefix', 'prefix_flat', 'status', 'children', 'vrf', 'utilization', 'tenant', 'site', + 'vlan_group', 'vlan', 'role', 'is_pool', 'mark_utilized', 'description', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'prefix', 'status', 'children', 'vrf', 'utilization', 'tenant', 'site', 'vlan', 'role', 'description', @@ -306,7 +315,7 @@ class IPRangeTable(BaseTable): model = IPRange fields = ( 'pk', 'id', 'start_address', 'end_address', 'size', 'vrf', 'status', 'role', 'tenant', 'description', - 'utilization', 'tags', + 'utilization', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'start_address', 'end_address', 'size', 'vrf', 'status', 'role', 'tenant', 'description', @@ -364,7 +373,7 @@ class IPAddressTable(BaseTable): model = IPAddress fields = ( 'pk', 'id', 'address', 'vrf', 'status', 'role', 'tenant', 'nat_inside', 'assigned', 'dns_name', 'description', - 'tags', + 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'address', 'vrf', 'status', 'role', 'tenant', 'assigned', 'dns_name', 'description', diff --git a/netbox/ipam/tables/services.py b/netbox/ipam/tables/services.py index ff6b766f7..29039644f 100644 --- a/netbox/ipam/tables/services.py +++ b/netbox/ipam/tables/services.py @@ -31,5 +31,8 @@ class ServiceTable(BaseTable): class Meta(BaseTable.Meta): model = Service - fields = ('pk', 'id', 'name', 'parent', 'protocol', 'ports', 'ipaddresses', 'description', 'tags') + fields = ( + 'pk', 'id', 'name', 'parent', 'protocol', 'ports', 'ipaddresses', 'description', 'tags', 'created', + 'last_updated', + ) default_columns = ('pk', 'name', 'parent', 'protocol', 'ports', 'description') diff --git a/netbox/ipam/tables/vlans.py b/netbox/ipam/tables/vlans.py index 365c6119b..5f38bc868 100644 --- a/netbox/ipam/tables/vlans.py +++ b/netbox/ipam/tables/vlans.py @@ -84,7 +84,10 @@ class VLANGroupTable(BaseTable): class Meta(BaseTable.Meta): model = VLANGroup - fields = ('pk', 'id', 'name', 'scope_type', 'scope', 'vlan_count', 'slug', 'description', 'tags', 'actions') + fields = ( + 'pk', 'id', 'name', 'scope_type', 'scope', 'vlan_count', 'slug', 'description', 'tags', 'actions', + 'created', 'last_updated', + ) default_columns = ('pk', 'name', 'scope_type', 'scope', 'vlan_count', 'description', 'actions') @@ -125,7 +128,10 @@ class VLANTable(BaseTable): class Meta(BaseTable.Meta): model = VLAN - fields = ('pk', 'id', 'vid', 'name', 'site', 'group', 'prefixes', 'tenant', 'status', 'role', 'description', 'tags') + fields = ( + 'pk', 'id', 'vid', 'name', 'site', 'group', 'prefixes', 'tenant', 'status', 'role', 'description', 'tags', + 'created', 'last_updated', + ) default_columns = ('pk', 'vid', 'name', 'site', 'group', 'prefixes', 'tenant', 'status', 'role', 'description') row_attrs = { 'class': lambda record: 'success' if not isinstance(record, VLAN) else '', diff --git a/netbox/ipam/tables/vrfs.py b/netbox/ipam/tables/vrfs.py index 1264368f4..e71fb1fa4 100644 --- a/netbox/ipam/tables/vrfs.py +++ b/netbox/ipam/tables/vrfs.py @@ -47,7 +47,8 @@ class VRFTable(BaseTable): class Meta(BaseTable.Meta): model = VRF fields = ( - 'pk', 'id', 'name', 'rd', 'tenant', 'enforce_unique', 'description', 'import_targets', 'export_targets', 'tags', + 'pk', 'id', 'name', 'rd', 'tenant', 'enforce_unique', 'description', 'import_targets', 'export_targets', + 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'rd', 'tenant', 'description') @@ -68,5 +69,5 @@ class RouteTargetTable(BaseTable): class Meta(BaseTable.Meta): model = RouteTarget - fields = ('pk', 'id', 'name', 'tenant', 'description', 'tags') + fields = ('pk', 'id', 'name', 'tenant', 'description', 'tags', 'created', 'last_updated',) default_columns = ('pk', 'name', 'tenant', 'description') diff --git a/netbox/tenancy/tables.py b/netbox/tenancy/tables.py index 0ae1139bf..11893481c 100644 --- a/netbox/tenancy/tables.py +++ b/netbox/tenancy/tables.py @@ -63,7 +63,9 @@ class TenantGroupTable(BaseTable): class Meta(BaseTable.Meta): model = TenantGroup - fields = ('pk', 'id', 'name', 'tenant_count', 'description', 'slug', 'tags', 'actions') + fields = ( + 'pk', 'id', 'name', 'tenant_count', 'description', 'slug', 'tags', 'actions', 'created', 'last_updated', + ) default_columns = ('pk', 'name', 'tenant_count', 'description', 'actions') @@ -82,7 +84,7 @@ class TenantTable(BaseTable): class Meta(BaseTable.Meta): model = Tenant - fields = ('pk', 'id', 'name', 'slug', 'group', 'description', 'comments', 'tags') + fields = ('pk', 'id', 'name', 'slug', 'group', 'description', 'comments', 'tags', 'created', 'last_updated',) default_columns = ('pk', 'name', 'group', 'description') @@ -107,7 +109,7 @@ class ContactGroupTable(BaseTable): class Meta(BaseTable.Meta): model = ContactGroup - fields = ('pk', 'name', 'contact_count', 'description', 'slug', 'tags', 'actions') + fields = ('pk', 'name', 'contact_count', 'description', 'slug', 'tags', 'actions', 'created', 'last_updated',) default_columns = ('pk', 'name', 'contact_count', 'description', 'actions') @@ -120,7 +122,7 @@ class ContactRoleTable(BaseTable): class Meta(BaseTable.Meta): model = ContactRole - fields = ('pk', 'name', 'description', 'slug', 'actions') + fields = ('pk', 'name', 'description', 'slug', 'actions', 'created', 'last_updated',) default_columns = ('pk', 'name', 'description', 'actions') @@ -145,7 +147,10 @@ class ContactTable(BaseTable): class Meta(BaseTable.Meta): model = Contact - fields = ('pk', 'name', 'group', 'title', 'phone', 'email', 'address', 'comments', 'assignment_count', 'tags') + fields = ( + 'pk', 'name', 'group', 'title', 'phone', 'email', 'address', 'comments', 'assignment_count', 'tags', + 'created', 'last_updated', + ) default_columns = ('pk', 'name', 'group', 'assignment_count', 'title', 'phone', 'email') diff --git a/netbox/virtualization/tables.py b/netbox/virtualization/tables.py index 2af3fcd5e..dfa46047e 100644 --- a/netbox/virtualization/tables.py +++ b/netbox/virtualization/tables.py @@ -44,7 +44,9 @@ class ClusterTypeTable(BaseTable): class Meta(BaseTable.Meta): model = ClusterType - fields = ('pk', 'id', 'name', 'slug', 'cluster_count', 'description', 'tags', 'actions') + fields = ( + 'pk', 'id', 'name', 'slug', 'cluster_count', 'description', 'tags', 'actions', 'created', 'last_updated', + ) default_columns = ('pk', 'name', 'cluster_count', 'description', 'actions') @@ -67,7 +69,9 @@ class ClusterGroupTable(BaseTable): class Meta(BaseTable.Meta): model = ClusterGroup - fields = ('pk', 'id', 'name', 'slug', 'cluster_count', 'description', 'tags', 'actions') + fields = ( + 'pk', 'id', 'name', 'slug', 'cluster_count', 'description', 'tags', 'actions', 'created', 'last_updated', + ) default_columns = ('pk', 'name', 'cluster_count', 'description', 'actions') @@ -109,7 +113,10 @@ class ClusterTable(BaseTable): class Meta(BaseTable.Meta): model = Cluster - fields = ('pk', 'id', 'name', 'type', 'group', 'tenant', 'site', 'comments', 'device_count', 'vm_count', 'tags') + fields = ( + 'pk', 'id', 'name', 'type', 'group', 'tenant', 'site', 'comments', 'device_count', 'vm_count', 'tags', + 'created', 'last_updated', + ) default_columns = ('pk', 'name', 'type', 'group', 'tenant', 'site', 'device_count', 'vm_count') @@ -150,8 +157,8 @@ class VirtualMachineTable(BaseTable): class Meta(BaseTable.Meta): model = VirtualMachine fields = ( - 'pk', 'id', 'name', 'status', 'cluster', 'role', 'tenant', 'platform', 'vcpus', 'memory', 'disk', 'primary_ip4', - 'primary_ip6', 'primary_ip', 'comments', 'tags', + 'pk', 'id', 'name', 'status', 'cluster', 'role', 'tenant', 'platform', 'vcpus', 'memory', 'disk', + 'primary_ip4', 'primary_ip6', 'primary_ip', 'comments', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'name', 'status', 'cluster', 'role', 'tenant', 'vcpus', 'memory', 'disk', 'primary_ip', @@ -178,7 +185,7 @@ class VMInterfaceTable(BaseInterfaceTable): model = VMInterface fields = ( 'pk', 'id', 'name', 'virtual_machine', 'enabled', 'mac_address', 'mtu', 'mode', 'description', 'tags', - 'ip_addresses', 'fhrp_groups', 'untagged_vlan', 'tagged_vlans', + 'ip_addresses', 'fhrp_groups', 'untagged_vlan', 'tagged_vlans', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'virtual_machine', 'enabled', 'description') diff --git a/netbox/wireless/tables.py b/netbox/wireless/tables.py index 4f47ee7f9..b3516c765 100644 --- a/netbox/wireless/tables.py +++ b/netbox/wireless/tables.py @@ -30,7 +30,9 @@ class WirelessLANGroupTable(BaseTable): class Meta(BaseTable.Meta): model = WirelessLANGroup - fields = ('pk', 'name', 'wirelesslan_count', 'description', 'slug', 'tags', 'actions') + fields = ( + 'pk', 'name', 'wirelesslan_count', 'description', 'slug', 'tags', 'actions', 'created', 'last_updated', + ) default_columns = ('pk', 'name', 'wirelesslan_count', 'description', 'actions') @@ -53,7 +55,7 @@ class WirelessLANTable(BaseTable): model = WirelessLAN fields = ( 'pk', 'ssid', 'group', 'description', 'vlan', 'interface_count', 'auth_type', 'auth_cipher', 'auth_psk', - 'tags', + 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'ssid', 'group', 'description', 'vlan', 'auth_type', 'interface_count') @@ -102,7 +104,7 @@ class WirelessLinkTable(BaseTable): model = WirelessLink fields = ( 'pk', 'id', 'status', 'device_a', 'interface_a', 'device_b', 'interface_b', 'ssid', 'description', - 'auth_type', 'auth_cipher', 'auth_psk', 'tags', + 'auth_type', 'auth_cipher', 'auth_psk', 'tags', 'created', 'last_updated', ) default_columns = ( 'pk', 'id', 'status', 'device_a', 'interface_a', 'device_b', 'interface_b', 'ssid', 'auth_type', From 0ca6d73614900ae72b729615bcd529057561b6ce Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 13 Jan 2022 15:10:06 -0500 Subject: [PATCH 08/42] #8293: Tweak table column output & add changelog --- docs/release-notes/version-3.1.md | 1 + netbox/ipam/models/ip.py | 13 ++++++++++++- netbox/ipam/tables/ip.py | 4 +--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index dac6119aa..8a2275a65 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -7,6 +7,7 @@ * [#8246](https://github.com/netbox-community/netbox/issues/8246) - Show human-friendly values for commit rates in circuits table * [#8262](https://github.com/netbox-community/netbox/issues/8262) - Add cable count to tenant stats * [#8265](https://github.com/netbox-community/netbox/issues/8265) - Add Stackwise-n interface types +* [#8293](https://github.com/netbox-community/netbox/issues/8293) - Show 4-byte ASNs in ASDOT notation * [#8302](https://github.com/netbox-community/netbox/issues/8302) - Linkify role column in device & VM tables ### Bug Fixes diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index 5cce88481..81c3ef34a 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -130,9 +130,20 @@ class ASN(PrimaryModel): def get_absolute_url(self): return reverse('ipam:asn', args=[self.pk]) + @property + def asn_asdot(self): + """ + Return ASDOT notation for AS numbers greater than 16 bits. + """ + if self.asn > 65535: + return f'{self.asn // 65536}.{self.asn % 65536}' + return self.asn + @property def asn_with_asdot(self): - # Return asn with asdot notation for an ASN larger than 65535 otherwise return the plain ASN + """ + Return both plain and ASDOT notation, where applicable. + """ if self.asn > 65535: return f'{self.asn} ({self.asn // 65536}.{self.asn % 65536})' else: diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index 8efb1caf3..0f43aecb8 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -104,12 +104,10 @@ class RIRTable(BaseTable): class ASNTable(BaseTable): pk = ToggleColumn() asn = tables.Column( + accessor=tables.A('asn_asdot'), linkify=True ) - def render_asn(self, value, record): - return record.asn_with_asdot - site_count = LinkedCountColumn( viewname='dcim:site_list', url_params={'asn_id': 'pk'}, From 60ba4a9830eebdeba238c88829bca3bb1ee97e38 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 13 Jan 2022 15:24:15 -0500 Subject: [PATCH 09/42] Changelog for #8337 --- docs/release-notes/version-3.1.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 8a2275a65..705d62cf2 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -9,6 +9,7 @@ * [#8265](https://github.com/netbox-community/netbox/issues/8265) - Add Stackwise-n interface types * [#8293](https://github.com/netbox-community/netbox/issues/8293) - Show 4-byte ASNs in ASDOT notation * [#8302](https://github.com/netbox-community/netbox/issues/8302) - Linkify role column in device & VM tables +* [#8337](https://github.com/netbox-community/netbox/issues/8337) - Enable sorting object tables by created & updated times ### Bug Fixes From 0181a25d704f25486ad6cf0921a6ac6c97b6de9b Mon Sep 17 00:00:00 2001 From: Jason Yates Date: Thu, 13 Jan 2022 19:13:28 -0800 Subject: [PATCH 10/42] Fixes #8342 created & last_updated fields are missing from some REST API calls. Added missing fields to the following API calls /api/dcim/virtual-chassis/ /api/dcim/cables/ /api/dcim/power-panels/ /api/dcim/rack-reservations/ /api/circuits/circuit-terminations/ /api/extras/webhooks/ /api/extras/custom-fields/ /api/extras/custom-links/ /api/extras/export-templates/ /api/extras/tags/ --- netbox/circuits/api/serializers.py | 2 +- netbox/dcim/api/serializers.py | 14 ++++++++++---- netbox/extras/api/serializers.py | 13 ++++++++----- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/netbox/circuits/api/serializers.py b/netbox/circuits/api/serializers.py index 470a0b030..42f9d9322 100644 --- a/netbox/circuits/api/serializers.py +++ b/netbox/circuits/api/serializers.py @@ -100,5 +100,5 @@ class CircuitTerminationSerializer(ValidatedModelSerializer, LinkTerminationSeri fields = [ 'id', 'url', 'display', 'circuit', 'term_side', 'site', 'provider_network', 'port_speed', 'upstream_speed', 'xconnect_id', 'pp_info', 'description', 'mark_connected', 'cable', 'link_peer', 'link_peer_type', - '_occupied', + '_occupied', 'created', 'last_updated', ] diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index 45930c5f5..337fd35c6 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -219,7 +219,7 @@ class RackReservationSerializer(PrimaryModelSerializer): class Meta: model = RackReservation fields = [ - 'id', 'url', 'display', 'rack', 'units', 'created', 'user', 'tenant', 'description', 'tags', + 'id', 'url', 'display', 'rack', 'units', 'created', 'last_updated', 'user', 'tenant', 'description', 'tags', 'custom_fields', ] @@ -762,7 +762,7 @@ class CableSerializer(PrimaryModelSerializer): fields = [ 'id', 'url', 'display', 'termination_a_type', 'termination_a_id', 'termination_a', 'termination_b_type', 'termination_b_id', 'termination_b', 'type', 'status', 'tenant', 'label', 'color', 'length', 'length_unit', - 'tags', 'custom_fields', + 'tags', 'custom_fields', 'created', 'last_updated', ] def _get_termination(self, obj, side): @@ -856,7 +856,10 @@ class VirtualChassisSerializer(PrimaryModelSerializer): class Meta: model = VirtualChassis - fields = ['id', 'url', 'display', 'name', 'domain', 'master', 'tags', 'custom_fields', 'member_count'] + fields = [ + 'id', 'url', 'display', 'name', 'domain', 'master', 'tags', 'custom_fields', 'member_count', + 'created', 'last_updated', + ] # @@ -875,7 +878,10 @@ class PowerPanelSerializer(PrimaryModelSerializer): class Meta: model = PowerPanel - fields = ['id', 'url', 'display', 'site', 'location', 'name', 'tags', 'custom_fields', 'powerfeed_count'] + fields = [ + 'id', 'url', 'display', 'site', 'location', 'name', 'tags', 'custom_fields', 'powerfeed_count', + 'created', 'last_updated', + ] class PowerFeedSerializer(PrimaryModelSerializer, LinkTerminationSerializer, ConnectedEndpointSerializer): diff --git a/netbox/extras/api/serializers.py b/netbox/extras/api/serializers.py index 9e4665cc2..685949dea 100644 --- a/netbox/extras/api/serializers.py +++ b/netbox/extras/api/serializers.py @@ -61,7 +61,7 @@ class WebhookSerializer(ValidatedModelSerializer): fields = [ 'id', 'url', 'display', 'content_types', 'name', 'type_create', 'type_update', 'type_delete', 'payload_url', 'enabled', 'http_method', 'http_content_type', 'additional_headers', 'body_template', 'secret', - 'conditions', 'ssl_verification', 'ca_file_path', + 'conditions', 'ssl_verification', 'ca_file_path', 'created', 'last_updated', ] @@ -82,7 +82,8 @@ class CustomFieldSerializer(ValidatedModelSerializer): model = CustomField fields = [ 'id', 'url', 'display', 'content_types', 'type', 'name', 'label', 'description', 'required', 'filter_logic', - 'default', 'weight', 'validation_minimum', 'validation_maximum', 'validation_regex', 'choices', + 'default', 'weight', 'validation_minimum', 'validation_maximum', 'validation_regex', 'choices', 'created', + 'last_updated', ] @@ -100,7 +101,7 @@ class CustomLinkSerializer(ValidatedModelSerializer): model = CustomLink fields = [ 'id', 'url', 'display', 'content_type', 'name', 'link_text', 'link_url', 'weight', 'group_name', - 'button_class', 'new_window', + 'button_class', 'new_window', 'created', 'last_updated', ] @@ -118,7 +119,7 @@ class ExportTemplateSerializer(ValidatedModelSerializer): model = ExportTemplate fields = [ 'id', 'url', 'display', 'content_type', 'name', 'description', 'template_code', 'mime_type', - 'file_extension', 'as_attachment', + 'file_extension', 'as_attachment', 'created', 'last_updated', ] @@ -132,7 +133,9 @@ class TagSerializer(ValidatedModelSerializer): class Meta: model = Tag - fields = ['id', 'url', 'display', 'name', 'slug', 'color', 'description', 'tagged_items'] + fields = [ + 'id', 'url', 'display', 'name', 'slug', 'color', 'description', 'tagged_items', 'created', 'last_updated', + ] # From 1ae5a2c8085d7c4b5968d03a9b72ca21aab8a723 Mon Sep 17 00:00:00 2001 From: Jason Yates Date: Fri, 14 Jan 2022 06:19:25 -0800 Subject: [PATCH 11/42] Fixes #8357 - Filter view for Locations is missing tags field Adding tag field to Locations filter view --- netbox/dcim/forms/filtersets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/dcim/forms/filtersets.py b/netbox/dcim/forms/filtersets.py index cb9575d42..f4b4c0a87 100644 --- a/netbox/dcim/forms/filtersets.py +++ b/netbox/dcim/forms/filtersets.py @@ -152,7 +152,7 @@ class SiteFilterForm(TenancyFilterForm, CustomFieldModelFilterForm): class LocationFilterForm(TenancyFilterForm, CustomFieldModelFilterForm): model = Location field_groups = [ - ['q'], + ['q', 'tag'], ['region_id', 'site_group_id', 'site_id', 'parent_id'], ['tenant_group_id', 'tenant_id'], ] From b0948ea01837180447cafdd4bed580551242198f Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 14 Jan 2022 11:51:02 -0500 Subject: [PATCH 12/42] Changelog for #8342, #8357 --- docs/release-notes/version-3.1.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 705d62cf2..4ff9c1e5a 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -22,6 +22,8 @@ * [#8314](https://github.com/netbox-community/netbox/issues/8314) - Prevent custom fields with default values from appearing as applied filters erroneously * [#8317](https://github.com/netbox-community/netbox/issues/8317) - Fix CSV import of multi-select custom field values * [#8319](https://github.com/netbox-community/netbox/issues/8319) - Custom URL fields should honor `ALLOWED_URL_SCHEMES` config parameter +* [#8342](https://github.com/netbox-community/netbox/issues/8342) - Restore `created` & `last_updated` fields missing from several REST API serializers +* [#8357](https://github.com/netbox-community/netbox/issues/8357) - Add missing tags field to location filter form --- From 2b3115483415b3a84e5ff0b892d2650b83d656ef Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 14 Jan 2022 14:23:58 -0500 Subject: [PATCH 13/42] Fixes #8358: Fix inconsistent styling of custom fields on filter & bulk edit forms --- docs/release-notes/version-3.1.md | 1 + netbox/extras/forms/customfields.py | 63 +++++++++++++-------------- netbox/templates/inc/filter_list.html | 6 +-- netbox/utilities/forms/forms.py | 14 +++--- 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 4ff9c1e5a..7c6377ea8 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -24,6 +24,7 @@ * [#8319](https://github.com/netbox-community/netbox/issues/8319) - Custom URL fields should honor `ALLOWED_URL_SCHEMES` config parameter * [#8342](https://github.com/netbox-community/netbox/issues/8342) - Restore `created` & `last_updated` fields missing from several REST API serializers * [#8357](https://github.com/netbox-community/netbox/issues/8357) - Add missing tags field to location filter form +* [#8358](https://github.com/netbox-community/netbox/issues/8358) - Fix inconsistent styling of custom fields on filter & bulk edit forms --- diff --git a/netbox/extras/forms/customfields.py b/netbox/extras/forms/customfields.py index 7d5b40894..bc55d750a 100644 --- a/netbox/extras/forms/customfields.py +++ b/netbox/extras/forms/customfields.py @@ -4,7 +4,7 @@ from django.db.models import Q from extras.choices import * from extras.models import * -from utilities.forms import BootstrapMixin, BulkEditForm, CSVModelForm, FilterForm +from utilities.forms import BootstrapMixin, BulkEditBaseForm, CSVModelForm __all__ = ( 'CustomFieldModelCSVForm', @@ -34,6 +34,9 @@ class CustomFieldsMixin: raise NotImplementedError(f"{self.__class__.__name__} must specify a model class.") return ContentType.objects.get_for_model(self.model) + def _get_custom_fields(self, content_type): + return CustomField.objects.filter(content_types=content_type) + def _get_form_field(self, customfield): return customfield.to_form_field() @@ -41,10 +44,7 @@ class CustomFieldsMixin: """ Append form fields for all CustomFields assigned to this object type. """ - content_type = self._get_content_type() - - # Append form fields; assign initial values if modifying and existing object - for customfield in CustomField.objects.filter(content_types=content_type): + for customfield in self._get_custom_fields(self._get_content_type()): field_name = f'cf_{customfield.name}' self.fields[field_name] = self._get_form_field(customfield) @@ -86,40 +86,37 @@ class CustomFieldModelCSVForm(CSVModelForm, CustomFieldModelForm): return customfield.to_form_field(for_csv_import=True) -class CustomFieldModelBulkEditForm(BulkEditForm): +class CustomFieldModelBulkEditForm(BootstrapMixin, CustomFieldsMixin, BulkEditBaseForm): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) + def _get_form_field(self, customfield): + return customfield.to_form_field(set_initial=False, enforce_required=False) - self.custom_fields = [] - self.obj_type = ContentType.objects.get_for_model(self.model) - - # Add all applicable CustomFields to the form - custom_fields = CustomField.objects.filter(content_types=self.obj_type) - for cf in custom_fields: + def _append_customfield_fields(self): + """ + Append form fields for all CustomFields assigned to this object type. + """ + for customfield in self._get_custom_fields(self._get_content_type()): # Annotate non-required custom fields as nullable - if not cf.required: - self.nullable_fields.append(cf.name) - self.fields[cf.name] = cf.to_form_field(set_initial=False, enforce_required=False) - # Annotate this as a custom field - self.custom_fields.append(cf.name) + if not customfield.required: + self.nullable_fields.append(customfield.name) + + self.fields[customfield.name] = self._get_form_field(customfield) + + # Annotate the field in the list of CustomField form fields + self.custom_fields.append(customfield.name) -class CustomFieldModelFilterForm(FilterForm): +class CustomFieldModelFilterForm(BootstrapMixin, CustomFieldsMixin, forms.Form): + q = forms.CharField( + required=False, + label='Search' + ) - def __init__(self, *args, **kwargs): - - self.obj_type = ContentType.objects.get_for_model(self.model) - - super().__init__(*args, **kwargs) - - # Add all applicable CustomFields to the form - self.custom_field_filters = [] - custom_fields = CustomField.objects.filter(content_types=self.obj_type).exclude( + def _get_custom_fields(self, content_type): + return CustomField.objects.filter(content_types=content_type).exclude( Q(filter_logic=CustomFieldFilterLogicChoices.FILTER_DISABLED) | Q(type=CustomFieldTypeChoices.TYPE_JSON) ) - for cf in custom_fields: - field_name = f'cf_{cf.name}' - self.fields[field_name] = cf.to_form_field(set_initial=False, enforce_required=False) - self.custom_field_filters.append(field_name) + + def _get_form_field(self, customfield): + return customfield.to_form_field(set_initial=False, enforce_required=False) diff --git a/netbox/templates/inc/filter_list.html b/netbox/templates/inc/filter_list.html index 1e73fedb2..e6a1e6a28 100644 --- a/netbox/templates/inc/filter_list.html +++ b/netbox/templates/inc/filter_list.html @@ -24,17 +24,17 @@ {% else %} {# List all non-customfield filters as declared in the form class #} {% for field in filter_form.visible_fields %} - {% if not filter_form.custom_field_filters or field.name not in filter_form.custom_field_filters %} + {% if not filter_form.custom_fields or field.name not in filter_form.custom_fields %}
{% render_field field %}
{% endif %} {% endfor %} {% endif %} - {% if filter_form.custom_field_filters %} + {% if filter_form.custom_fields %} {# List all custom field filters #}
- {% for name in filter_form.custom_field_filters %} + {% for name in filter_form.custom_fields %}
{% with field=filter_form|get_item:name %} {% render_field field %} diff --git a/netbox/utilities/forms/forms.py b/netbox/utilities/forms/forms.py index 87fa4ae33..88f837b2b 100644 --- a/netbox/utilities/forms/forms.py +++ b/netbox/utilities/forms/forms.py @@ -3,7 +3,6 @@ import re import yaml from django import forms -from django.utils.translation import gettext as _ from .widgets import APISelect, APISelectMultiple, ClearableFileInput, StaticSelect @@ -11,6 +10,7 @@ from .widgets import APISelect, APISelectMultiple, ClearableFileInput, StaticSel __all__ = ( 'BootstrapMixin', 'BulkEditForm', + 'BulkEditBaseForm', 'BulkRenameForm', 'ConfirmationForm', 'CSVModelForm', @@ -75,11 +75,10 @@ class ConfirmationForm(BootstrapMixin, ReturnURLForm): confirm = forms.BooleanField(required=True, widget=forms.HiddenInput(), initial=True) -class BulkEditForm(BootstrapMixin, forms.Form): +class BulkEditBaseForm(forms.Form): """ Base form for editing multiple objects in bulk """ - def __init__(self, model, *args, **kwargs): super().__init__(*args, **kwargs) self.model = model @@ -90,6 +89,10 @@ class BulkEditForm(BootstrapMixin, forms.Form): self.nullable_fields = self.Meta.nullable_fields +class BulkEditForm(BootstrapMixin, BulkEditBaseForm): + pass + + class BulkRenameForm(BootstrapMixin, forms.Form): """ An extendable form to be used for renaming objects in bulk. @@ -185,10 +188,7 @@ class FilterForm(BootstrapMixin, forms.Form): """ q = forms.CharField( required=False, - widget=forms.TextInput( - attrs={'placeholder': _('All fields')} - ), - label=_('Search') + label='Search' ) From 69f525bfd3be176a3c45e11b9f1bcbe9d8e06c6e Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Mon, 17 Jan 2022 09:49:16 -0500 Subject: [PATCH 14/42] Release v3.1.6 --- .github/ISSUE_TEMPLATE/bug_report.yaml | 2 +- .github/ISSUE_TEMPLATE/feature_request.yaml | 2 +- base_requirements.txt | 4 ---- docs/release-notes/version-3.1.md | 2 +- netbox/netbox/settings.py | 2 +- requirements.txt | 6 +++--- 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 594f23f9a..16182af64 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -14,7 +14,7 @@ body: attributes: label: NetBox version description: What version of NetBox are you currently running? - placeholder: v3.1.5 + placeholder: v3.1.6 validations: required: true - type: dropdown diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index b1193ae02..0be999b16 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -14,7 +14,7 @@ body: attributes: label: NetBox version description: What version of NetBox are you currently running? - placeholder: v3.1.5 + placeholder: v3.1.6 validations: required: true - type: dropdown diff --git a/base_requirements.txt b/base_requirements.txt index cbc893aa9..aaa9c7f44 100644 --- a/base_requirements.txt +++ b/base_requirements.txt @@ -98,10 +98,6 @@ psycopg2-binary # https://github.com/yaml/pyyaml PyYAML -# In-memory key/value store used for caching and queuing -# https://github.com/andymccurdy/redis-py -redis - # Social authentication framework # https://github.com/python-social-auth/social-core social-auth-core[all] diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 7c6377ea8..88a6da77f 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -1,6 +1,6 @@ # NetBox v3.1 -## v3.1.6 (FUTURE) +## v3.1.6 (2022-01-17) ### Enhancements diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 5bcc98d1c..ff767b4d8 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -19,7 +19,7 @@ from netbox.config import PARAMS # Environment setup # -VERSION = '3.1.6-dev' +VERSION = '3.1.6' # Hostname HOSTNAME = platform.node() diff --git a/requirements.txt b/requirements.txt index e0148e74e..83c1b9f2e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ Django==3.2.11 -django-cors-headers==3.10.1 +django-cors-headers==3.11.0 django-debug-toolbar==3.2.4 django-filter==21.1 django-graphiql-debug-toolbar==0.2.0 @@ -10,7 +10,7 @@ django-redis==5.2.0 django-rq==2.5.1 django-tables2==2.4.1 django-taggit==2.0.0 -django-timezone-field==4.2.1 +django-timezone-field==4.2.3 djangorestframework==3.12.4 drf-yasg[validation]==1.20.0 graphene_django==2.15.0 @@ -18,7 +18,7 @@ gunicorn==20.1.0 Jinja2==3.0.3 Markdown==3.3.6 markdown-include==0.6.0 -mkdocs-material==8.1.4 +mkdocs-material==8.1.7 netaddr==0.8.0 Pillow==8.4.0 psycopg2-binary==2.9.3 From 1584d51433cb68dc93c9f83c111c5744443a2538 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Mon, 17 Jan 2022 10:16:37 -0500 Subject: [PATCH 15/42] PRVB --- docs/release-notes/version-3.1.md | 4 ++++ netbox/netbox/settings.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 88a6da77f..c42837b24 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -1,5 +1,9 @@ # NetBox v3.1 +## v3.1.7 (FUTURE) + +--- + ## v3.1.6 (2022-01-17) ### Enhancements diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index ff767b4d8..199df264c 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -19,7 +19,7 @@ from netbox.config import PARAMS # Environment setup # -VERSION = '3.1.6' +VERSION = '3.1.7-dev' # Hostname HOSTNAME = platform.node() From 38963e7960102501a2a22d0150d74252a1f7f8a5 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 18 Jan 2022 11:09:12 -0500 Subject: [PATCH 16/42] Fixes #8377: Fix calculation of absolute cable lengths when specified in fractional units --- docs/release-notes/version-3.1.md | 4 +++ .../migrations/0144_fix_cable_abs_length.py | 31 +++++++++++++++++++ netbox/dcim/tables/cables.py | 2 +- netbox/dcim/tables/template_code.py | 3 +- netbox/utilities/utils.py | 21 ++++++------- 5 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 netbox/dcim/migrations/0144_fix_cable_abs_length.py diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index c42837b24..89a68423f 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -2,6 +2,10 @@ ## v3.1.7 (FUTURE) +### Bug Fixes + +* [#8377](https://github.com/netbox-community/netbox/issues/8377) - Fix calculation of absolute cable lengths when specified in fractional units + --- ## v3.1.6 (2022-01-17) diff --git a/netbox/dcim/migrations/0144_fix_cable_abs_length.py b/netbox/dcim/migrations/0144_fix_cable_abs_length.py new file mode 100644 index 000000000..0da30ffb5 --- /dev/null +++ b/netbox/dcim/migrations/0144_fix_cable_abs_length.py @@ -0,0 +1,31 @@ +from django.db import migrations + +from utilities.utils import to_meters + + +def recalculate_abs_length(apps, schema_editor): + """ + Recalculate absolute lengths for all cables with a length and length unit defined. Fixes + incorrectly calculated values as reported under bug #8377. + """ + Cable = apps.get_model('dcim', 'Cable') + + cables = Cable.objects.filter(length__isnull=False).exclude(length_unit='') + for cable in cables: + cable._abs_length = to_meters(cable.length, cable.length_unit) + + Cable.objects.bulk_update(cables, ['_abs_length'], batch_size=100) + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0143_remove_primary_for_related_name'), + ] + + operations = [ + migrations.RunPython( + code=recalculate_abs_length, + reverse_code=migrations.RunPython.noop + ), + ] diff --git a/netbox/dcim/tables/cables.py b/netbox/dcim/tables/cables.py index bea2c0adf..9f2c08342 100644 --- a/netbox/dcim/tables/cables.py +++ b/netbox/dcim/tables/cables.py @@ -45,7 +45,7 @@ class CableTable(BaseTable): tenant = TenantColumn() length = TemplateColumn( template_code=CABLE_LENGTH, - order_by='_abs_length' + order_by=('_abs_length', 'length_unit') ) color = ColorColumn() tags = TagColumn( diff --git a/netbox/dcim/tables/template_code.py b/netbox/dcim/tables/template_code.py index ccca32be8..233694a7a 100644 --- a/netbox/dcim/tables/template_code.py +++ b/netbox/dcim/tables/template_code.py @@ -9,7 +9,8 @@ LINKTERMINATION = """ """ CABLE_LENGTH = """ -{% if record.length %}{{ record.length }} {{ record.get_length_unit_display }}{% endif %} +{% load helpers %} +{% if record.length %}{{ record.length|simplify_decimal }} {{ record.length_unit }}{% endif %} """ CABLE_TERMINATION_PARENT = """ diff --git a/netbox/utilities/utils.py b/netbox/utilities/utils.py index ce1f6a111..31e57cd69 100644 --- a/netbox/utilities/utils.py +++ b/netbox/utilities/utils.py @@ -1,9 +1,8 @@ import datetime import json -import urllib from collections import OrderedDict +from decimal import Decimal from itertools import count, groupby -from typing import Any, Dict, List, Tuple from django.core.serializers import serialize from django.db.models import Count, OuterRef, Subquery @@ -195,15 +194,15 @@ def to_meters(length, unit): """ Convert the given length to meters. """ - length = int(length) - if length < 0: - raise ValueError("Length must be a positive integer") + try: + if length < 0: + raise ValueError("Length must be a positive number") + except TypeError: + raise TypeError(f"Invalid value '{length}' for length (must be a number)") valid_units = CableLengthUnitChoices.values() if unit not in valid_units: - raise ValueError( - "Unknown unit {}. Must be one of the following: {}".format(unit, ', '.join(valid_units)) - ) + raise ValueError(f"Unknown unit {unit}. Must be one of the following: {', '.join(valid_units)}") if unit == CableLengthUnitChoices.UNIT_KILOMETER: return length * 1000 @@ -212,11 +211,11 @@ def to_meters(length, unit): if unit == CableLengthUnitChoices.UNIT_CENTIMETER: return length / 100 if unit == CableLengthUnitChoices.UNIT_MILE: - return length * 1609.344 + return length * Decimal(1609.344) if unit == CableLengthUnitChoices.UNIT_FOOT: - return length * 0.3048 + return length * Decimal(0.3048) if unit == CableLengthUnitChoices.UNIT_INCH: - return length * 0.3048 * 12 + return length * Decimal(0.3048) * 12 raise ValueError(f"Unknown unit {unit}. Must be 'km', 'm', 'cm', 'mi', 'ft', or 'in'.") From 4b81d86311e80c055bd5a8b1ad55b2472ebc69e8 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 18 Jan 2022 11:31:39 -0500 Subject: [PATCH 17/42] Closes #8376: Correct example condition defitinions; call out value vs label ealuation for choice fields --- docs/additional-features/webhooks.md | 17 +++++++++++++++++ docs/models/extras/webhook.md | 13 ------------- docs/reference/conditions.md | 7 +++++-- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/additional-features/webhooks.md b/docs/additional-features/webhooks.md index 3f10cb9e6..5077f3a68 100644 --- a/docs/additional-features/webhooks.md +++ b/docs/additional-features/webhooks.md @@ -1,5 +1,22 @@ {!models/extras/webhook.md!} +## Conditional Webhooks + +A webhook may include a set of conditional logic expressed in JSON used to control whether a webhook triggers for a specific object. For example, you may wish to trigger a webhook for devices only when the `status` field of an object is "active": + +```json +{ + "and": [ + { + "attr": "status.value", + "value": "active" + } + ] +} +``` + +For more detail, see the reference documentation for NetBox's [conditional logic](../reference/conditions.md). + ## Webhook Processing When a change is detected, any resulting webhooks are placed into a Redis queue for processing. This allows the user's request to complete without needing to wait for the outgoing webhook(s) to be processed. The webhooks are then extracted from the queue by the `rqworker` process and HTTP requests are sent to their respective destinations. The current webhook queue and any failed webhooks can be inspected in the admin UI under System > Background Tasks. diff --git a/docs/models/extras/webhook.md b/docs/models/extras/webhook.md index c71657336..eb47dd332 100644 --- a/docs/models/extras/webhook.md +++ b/docs/models/extras/webhook.md @@ -81,16 +81,3 @@ If no body template is specified, the request body will be populated with a JSON } } ``` - -## Conditional Webhooks - -A webhook may include a set of conditional logic expressed in JSON used to control whether a webhook triggers for a specific object. For example, you may wish to trigger a webhook for devices only when the `status` field of an object is "active": - -```json -{ - "attr": "status", - "value": "active" -} -``` - -For more detail, see the reference documentation for NetBox's [conditional logic](../reference/conditions.md). diff --git a/docs/reference/conditions.md b/docs/reference/conditions.md index 40b2ccb4b..fb8b66139 100644 --- a/docs/reference/conditions.md +++ b/docs/reference/conditions.md @@ -81,13 +81,16 @@ The following condition will evaluate as true: ```json { - "attr": "status", + "attr": "status.value", "value": ["planned", "staging"], "op": "in", "negate": true } ``` +!!! note "Evaluating static choice fields" + Pay close attention when evaluating static choice fields, such as the `status` field above. These fields typically render as a dictionary specifying both the field's raw value (`value`) and its human-friendly label (`label`). be sure to specify on which of these you want to match. + ## Condition Sets Multiple conditions can be combined into nested sets using AND or OR logic. This is done by declaring a JSON object with a single key (`and` or `or`) containing a list of condition objects and/or child condition sets. @@ -102,7 +105,7 @@ Multiple conditions can be combined into nested sets using AND or OR logic. This { "and": [ { - "attr": "status", + "attr": "status.value", "value": "active" }, { From 29d4859e02b02f0afdd59d7b7e4c3c693758cd4e Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Tue, 18 Jan 2022 11:23:52 -0600 Subject: [PATCH 18/42] Fixes #8375 - Change ASN display column from ASDOT to ASPLAIN. Add ASDOT display column. --- docs/release-notes/version-3.1.md | 4 ++++ netbox/ipam/tables/ip.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 89a68423f..fdb7c18b5 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -2,6 +2,10 @@ ## v3.1.7 (FUTURE) +### Enhancements + +* [#8275](https://github.com/netbox-community/netbox/issues/8275) - Change ASN display column from ASDOT to ASPLAIN. Add ASDOT display column. + ### Bug Fixes * [#8377](https://github.com/netbox-community/netbox/issues/8377) - Fix calculation of absolute cable lengths when specified in fractional units diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index f188a21c0..eca35de1a 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -107,9 +107,13 @@ class RIRTable(BaseTable): class ASNTable(BaseTable): pk = ToggleColumn() asn = tables.Column( - accessor=tables.A('asn_asdot'), linkify=True ) + asn_asdot = tables.Column( + accessor=tables.A('asn_asdot'), + linkify=True, + verbose_name='ASDOT' + ) site_count = LinkedCountColumn( viewname='dcim:site_list', @@ -120,7 +124,7 @@ class ASNTable(BaseTable): class Meta(BaseTable.Meta): model = ASN - fields = ('pk', 'asn', 'rir', 'site_count', 'tenant', 'description', 'actions', 'created', 'last_updated',) + fields = ('pk', 'asn', 'asn_asdot', 'rir', 'site_count', 'tenant', 'description', 'actions', 'created', 'last_updated',) default_columns = ('pk', 'asn', 'rir', 'site_count', 'sites', 'tenant', 'actions') From 4711b4d5290f822ea33b668bc151181b2b085e6f Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 18 Jan 2022 15:17:05 -0500 Subject: [PATCH 19/42] Correct FeatureQuery invocations --- netbox/extras/forms/bulk_edit.py | 4 ++-- netbox/extras/forms/filtersets.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/netbox/extras/forms/bulk_edit.py b/netbox/extras/forms/bulk_edit.py index 1b87256a5..45b48e9a2 100644 --- a/netbox/extras/forms/bulk_edit.py +++ b/netbox/extras/forms/bulk_edit.py @@ -44,7 +44,7 @@ class CustomLinkBulkEditForm(BulkEditForm): ) content_type = ContentTypeChoiceField( queryset=ContentType.objects.all(), - limit_choices_to=FeatureQuery('custom_fields'), + limit_choices_to=FeatureQuery('custom_links'), required=False ) new_window = forms.NullBooleanField( @@ -71,7 +71,7 @@ class ExportTemplateBulkEditForm(BulkEditForm): ) content_type = ContentTypeChoiceField( queryset=ContentType.objects.all(), - limit_choices_to=FeatureQuery('custom_fields'), + limit_choices_to=FeatureQuery('export_templates'), required=False ) description = forms.CharField( diff --git a/netbox/extras/forms/filtersets.py b/netbox/extras/forms/filtersets.py index 03cd170b8..3848dcb0d 100644 --- a/netbox/extras/forms/filtersets.py +++ b/netbox/extras/forms/filtersets.py @@ -62,7 +62,7 @@ class CustomLinkFilterForm(FilterForm): ] content_type = ContentTypeChoiceField( queryset=ContentType.objects.all(), - limit_choices_to=FeatureQuery('custom_fields'), + limit_choices_to=FeatureQuery('custom_links'), required=False ) weight = forms.IntegerField( @@ -83,7 +83,7 @@ class ExportTemplateFilterForm(FilterForm): ] content_type = ContentTypeChoiceField( queryset=ContentType.objects.all(), - limit_choices_to=FeatureQuery('custom_fields'), + limit_choices_to=FeatureQuery('export_templates'), required=False ) mime_type = forms.CharField( @@ -109,7 +109,7 @@ class WebhookFilterForm(FilterForm): ] content_types = ContentTypeMultipleChoiceField( queryset=ContentType.objects.all(), - limit_choices_to=FeatureQuery('custom_fields'), + limit_choices_to=FeatureQuery('webhooks'), required=False ) http_method = forms.MultipleChoiceField( From 21468fff25cb87327d77340900fd2ff0c6355caf Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 18 Jan 2022 15:36:21 -0500 Subject: [PATCH 20/42] Closes #8367: Add ASNs to global search function --- docs/release-notes/version-3.1.md | 3 ++- netbox/ipam/filtersets.py | 4 ++++ netbox/ipam/tables/ip.py | 6 ++++-- netbox/netbox/constants.py | 14 +++++++++++--- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index fdb7c18b5..b985a5651 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -4,7 +4,8 @@ ### Enhancements -* [#8275](https://github.com/netbox-community/netbox/issues/8275) - Change ASN display column from ASDOT to ASPLAIN. Add ASDOT display column. +* [#8275](https://github.com/netbox-community/netbox/issues/8275) - Introduce alternative ASDOT-formatted column for ASNs +* [#8367](https://github.com/netbox-community/netbox/issues/8367) - Add ASNs to global search function ### Bug Fixes diff --git a/netbox/ipam/filtersets.py b/netbox/ipam/filtersets.py index df6ee1055..d7e1ee47e 100644 --- a/netbox/ipam/filtersets.py +++ b/netbox/ipam/filtersets.py @@ -209,6 +209,10 @@ class ASNFilterSet(OrganizationalModelFilterSet, TenancyFilterSet): if not value.strip(): return queryset qs_filter = Q(description__icontains=value) + try: + qs_filter |= Q(asn=int(value)) + except ValueError: + pass return queryset.filter(qs_filter) diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index eca35de1a..49892f557 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -114,7 +114,6 @@ class ASNTable(BaseTable): linkify=True, verbose_name='ASDOT' ) - site_count = LinkedCountColumn( viewname='dcim:site_list', url_params={'asn_id': 'pk'}, @@ -124,7 +123,10 @@ class ASNTable(BaseTable): class Meta(BaseTable.Meta): model = ASN - fields = ('pk', 'asn', 'asn_asdot', 'rir', 'site_count', 'tenant', 'description', 'actions', 'created', 'last_updated',) + fields = ( + 'pk', 'asn', 'asn_asdot', 'rir', 'site_count', 'tenant', 'description', 'actions', 'created', + 'last_updated', + ) default_columns = ('pk', 'asn', 'rir', 'site_count', 'sites', 'tenant', 'actions') diff --git a/netbox/netbox/constants.py b/netbox/netbox/constants.py index 3e935e722..e087423bb 100644 --- a/netbox/netbox/constants.py +++ b/netbox/netbox/constants.py @@ -12,9 +12,11 @@ from dcim.tables import ( CableTable, DeviceTable, DeviceTypeTable, PowerFeedTable, RackTable, RackReservationTable, LocationTable, SiteTable, VirtualChassisTable, ) -from ipam.filtersets import AggregateFilterSet, IPAddressFilterSet, PrefixFilterSet, VLANFilterSet, VRFFilterSet -from ipam.models import Aggregate, IPAddress, Prefix, VLAN, VRF -from ipam.tables import AggregateTable, IPAddressTable, PrefixTable, VLANTable, VRFTable +from ipam.filtersets import ( + AggregateFilterSet, ASNFilterSet, IPAddressFilterSet, PrefixFilterSet, VLANFilterSet, VRFFilterSet, +) +from ipam.models import Aggregate, ASN, IPAddress, Prefix, VLAN, VRF +from ipam.tables import AggregateTable, ASNTable, IPAddressTable, PrefixTable, VLANTable, VRFTable from tenancy.filtersets import TenantFilterSet from tenancy.models import Tenant from tenancy.tables import TenantTable @@ -170,6 +172,12 @@ SEARCH_TYPES = OrderedDict(( 'table': VLANTable, 'url': 'ipam:vlan_list', }), + ('asn', { + 'queryset': ASN.objects.prefetch_related('rir', 'tenant'), + 'filterset': ASNFilterSet, + 'table': ASNTable, + 'url': 'ipam:asn_list', + }), # Tenancy ('tenant', { 'queryset': Tenant.objects.prefetch_related('group'), From 1f2d4fd2b3ae3ef0c454e1c48cced4c7773c6cc1 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 18 Jan 2022 15:40:19 -0500 Subject: [PATCH 21/42] Closes #8381: Add contacts to global search function --- docs/release-notes/version-3.1.md | 1 + netbox/netbox/constants.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index b985a5651..9cfdcad23 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -6,6 +6,7 @@ * [#8275](https://github.com/netbox-community/netbox/issues/8275) - Introduce alternative ASDOT-formatted column for ASNs * [#8367](https://github.com/netbox-community/netbox/issues/8367) - Add ASNs to global search function +* [#8381](https://github.com/netbox-community/netbox/issues/8381) - Add contacts to global search function ### Bug Fixes diff --git a/netbox/netbox/constants.py b/netbox/netbox/constants.py index e087423bb..be5f12980 100644 --- a/netbox/netbox/constants.py +++ b/netbox/netbox/constants.py @@ -17,9 +17,9 @@ from ipam.filtersets import ( ) from ipam.models import Aggregate, ASN, IPAddress, Prefix, VLAN, VRF from ipam.tables import AggregateTable, ASNTable, IPAddressTable, PrefixTable, VLANTable, VRFTable -from tenancy.filtersets import TenantFilterSet -from tenancy.models import Tenant -from tenancy.tables import TenantTable +from tenancy.filtersets import ContactFilterSet, TenantFilterSet +from tenancy.models import Contact, Tenant +from tenancy.tables import ContactTable, TenantTable from utilities.utils import count_related from virtualization.filtersets import ClusterFilterSet, VirtualMachineFilterSet from virtualization.models import Cluster, VirtualMachine @@ -185,4 +185,10 @@ SEARCH_TYPES = OrderedDict(( 'table': TenantTable, 'url': 'tenancy:tenant_list', }), + ('contact', { + 'queryset': Contact.objects.prefetch_related('group', 'assignments'), + 'filterset': ContactFilterSet, + 'table': ContactTable, + 'url': 'tenancy:contact_list', + }), )) From 69eb6b11d0ee288b41d6b905e890b5995273e092 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 18 Jan 2022 16:01:40 -0500 Subject: [PATCH 22/42] Closes #8368: Enable controlling the order of custom script form fields with field_order --- docs/customization/custom-scripts.md | 4 ++++ docs/release-notes/version-3.1.md | 1 + netbox/extras/scripts.py | 13 +++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/customization/custom-scripts.md b/docs/customization/custom-scripts.md index df436fe99..02af19726 100644 --- a/docs/customization/custom-scripts.md +++ b/docs/customization/custom-scripts.md @@ -77,6 +77,10 @@ This is the human-friendly names of your script. If omitted, the class name will A human-friendly description of what your script does. +### `field_order` + +By default, script variables will be ordered in the form as they are defined in the script. `field_order` may be defined as an iterable of field names to determine the order in which variables are rendered. Any fields not included in this iterable be listed last. + ### `commit_default` The checkbox to commit database changes when executing a script is checked by default. Set `commit_default` to False under the script's Meta class to leave this option unchecked by default. diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 9cfdcad23..ee49a9b64 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -6,6 +6,7 @@ * [#8275](https://github.com/netbox-community/netbox/issues/8275) - Introduce alternative ASDOT-formatted column for ASNs * [#8367](https://github.com/netbox-community/netbox/issues/8367) - Add ASNs to global search function +* [#8368](https://github.com/netbox-community/netbox/issues/8368) - Enable controlling the order of custom script form fields with `field_order` * [#8381](https://github.com/netbox-community/netbox/issues/8381) - Add contacts to global search function ### Bug Fixes diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index 3c7ad3c15..fb3c6558a 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -296,12 +296,21 @@ class BaseScript: @classmethod def _get_vars(cls): - vars = OrderedDict() + vars = {} for name, attr in cls.__dict__.items(): if name not in vars and issubclass(attr.__class__, ScriptVariable): vars[name] = attr - return vars + # Order variables according to field_order + field_order = getattr(cls.Meta, 'field_order', None) + if not field_order: + return vars + ordered_vars = { + field: vars.pop(field) for field in field_order if field in vars + } + ordered_vars.update(vars) + + return ordered_vars def run(self, data, commit): raise NotImplementedError("The script must define a run() method.") From 8df382d976fd111373163a34dd105eeb47df2200 Mon Sep 17 00:00:00 2001 From: Johannes Erwerle Date: Fri, 28 Jan 2022 11:58:29 +0100 Subject: [PATCH 23/42] Fixes #8476: Bring the ASN Web UI up to the standard set by other objects --- docs/release-notes/version-3.1.md | 1 + netbox/ipam/tables/ip.py | 9 +++++++-- netbox/templates/tenancy/tenant.html | 4 ++++ netbox/tenancy/views.py | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index ee49a9b64..fa590215e 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -8,6 +8,7 @@ * [#8367](https://github.com/netbox-community/netbox/issues/8367) - Add ASNs to global search function * [#8368](https://github.com/netbox-community/netbox/issues/8368) - Enable controlling the order of custom script form fields with `field_order` * [#8381](https://github.com/netbox-community/netbox/issues/8381) - Add contacts to global search function +* [#8476](https://github.com/netbox-community/netbox/issues/8476) - Bring the ASN Web UI up to the standard set by other objects ### Bug Fixes diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index 49892f557..df2d97dac 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -119,15 +119,20 @@ class ASNTable(BaseTable): url_params={'asn_id': 'pk'}, verbose_name='Sites' ) + tenant = TenantColumn() + tags = TagColumn( + url_name='ipam:asn_list' + ) + actions = ButtonsColumn(ASN) class Meta(BaseTable.Meta): model = ASN fields = ( 'pk', 'asn', 'asn_asdot', 'rir', 'site_count', 'tenant', 'description', 'actions', 'created', - 'last_updated', + 'last_updated', 'tags', ) - default_columns = ('pk', 'asn', 'rir', 'site_count', 'sites', 'tenant', 'actions') + default_columns = ('pk', 'asn', 'rir', 'site_count', 'sites', 'description', 'tenant', 'actions') # diff --git a/netbox/templates/tenancy/tenant.html b/netbox/templates/tenancy/tenant.html index 083cc4777..b64438866 100644 --- a/netbox/templates/tenancy/tenant.html +++ b/netbox/templates/tenancy/tenant.html @@ -71,6 +71,10 @@

{{ stats.aggregate_count }}

Aggregates

+

{{ stats.prefix_count }}

Prefixes

diff --git a/netbox/tenancy/views.py b/netbox/tenancy/views.py index b0f550304..e219a5670 100644 --- a/netbox/tenancy/views.py +++ b/netbox/tenancy/views.py @@ -4,7 +4,7 @@ from django.shortcuts import get_object_or_404 from circuits.models import Circuit from dcim.models import Site, Rack, Device, RackReservation, Cable -from ipam.models import Aggregate, IPAddress, Prefix, VLAN, VRF +from ipam.models import Aggregate, IPAddress, Prefix, VLAN, VRF, ASN from netbox.views import generic from utilities.tables import paginate_table from utilities.utils import count_related @@ -113,6 +113,7 @@ class TenantView(generic.ObjectView): 'virtualmachine_count': VirtualMachine.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'cluster_count': Cluster.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'cable_count': Cable.objects.restrict(request.user, 'view').filter(tenant=instance).count(), + 'asn_count': ASN.objects.restrict(request.user, 'view').filter(tenant=instance).count(), } return { From 5d29c5958b5214d180991fbb18b2ba051a679703 Mon Sep 17 00:00:00 2001 From: Johannes Erwerle Date: Fri, 28 Jan 2022 17:54:37 +0100 Subject: [PATCH 24/42] Fixes #8477: The commands for running the tests in the development section are not working --- docs/development/getting-started.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/development/getting-started.md b/docs/development/getting-started.md index 742e93804..0e892bd4a 100644 --- a/docs/development/getting-started.md +++ b/docs/development/getting-started.md @@ -122,22 +122,22 @@ The demo data is provided in JSON format and loaded into an empty database using ## Running Tests -Prior to committing any substantial changes to the code base, be sure to run NetBox's test suite to catch any potential errors. Tests are run using the `test` management command. Remember to ensure the Python virtual environment is active before running this command. +Prior to committing any substantial changes to the code base, be sure to run NetBox's test suite to catch any potential errors. Tests are run using the `test` management command. Remember to ensure the Python virtual environment is active before running this command. Also keep in mind that these commands are executed in the `/netbox/` directory, not the root directory of the repository. ```no-highlight -$ python netbox/manage.py test +$ python manage.py test ``` In cases where you haven't made any changes to the database (which is most of the time), you can append the `--keepdb` argument to this command to reuse the test database between runs. This cuts down on the time it takes to run the test suite since the database doesn't have to be rebuilt each time. (Note that this argument will cause errors if you've modified any model fields since the previous test run.) ```no-highlight -$ python netbox/manage.py test --keepdb +$ python manage.py test --keepdb ``` You can also limit the command to running only a specific subset of tests. For example, to run only IPAM and DCIM view tests: ```no-highlight -$ python netbox/manage.py test dcim.tests.test_views ipam.tests.test_views +$ python manage.py test dcim.tests.test_views ipam.tests.test_views ``` ## Submitting Pull Requests From 222100697022c3d5cb102f1a26086ab205ebe43c Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 28 Jan 2022 13:09:57 -0500 Subject: [PATCH 25/42] Closes #8462: Linkify manufacturer column in device type table --- docs/release-notes/version-3.1.md | 1 + netbox/dcim/tables/devicetypes.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index fa590215e..802804e0b 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -8,6 +8,7 @@ * [#8367](https://github.com/netbox-community/netbox/issues/8367) - Add ASNs to global search function * [#8368](https://github.com/netbox-community/netbox/issues/8368) - Enable controlling the order of custom script form fields with `field_order` * [#8381](https://github.com/netbox-community/netbox/issues/8381) - Add contacts to global search function +* [#8462](https://github.com/netbox-community/netbox/issues/8462) - Linkify manufacturer column in device type table * [#8476](https://github.com/netbox-community/netbox/issues/8476) - Bring the ASN Web UI up to the standard set by other objects ### Bug Fixes diff --git a/netbox/dcim/tables/devicetypes.py b/netbox/dcim/tables/devicetypes.py index dc437ee96..5643edc37 100644 --- a/netbox/dcim/tables/devicetypes.py +++ b/netbox/dcim/tables/devicetypes.py @@ -67,6 +67,9 @@ class DeviceTypeTable(BaseTable): linkify=True, verbose_name='Device Type' ) + manufacturer = tables.Column( + linkify=True + ) is_full_depth = BooleanColumn( verbose_name='Full Depth' ) From f537dc632e88cb5dc0f7280ca1cbf8280a3fea73 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 28 Jan 2022 13:19:23 -0500 Subject: [PATCH 26/42] Fixes #8456: Fix redundant display of VRF RD in prefix view --- docs/release-notes/version-3.1.md | 1 + netbox/templates/ipam/prefix.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 802804e0b..3724ac3bd 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -14,6 +14,7 @@ ### Bug Fixes * [#8377](https://github.com/netbox-community/netbox/issues/8377) - Fix calculation of absolute cable lengths when specified in fractional units +* [#8456](https://github.com/netbox-community/netbox/issues/8456) - Fix redundant display of VRF RD in prefix view --- diff --git a/netbox/templates/ipam/prefix.html b/netbox/templates/ipam/prefix.html index cb62e56ae..045f4b9e0 100644 --- a/netbox/templates/ipam/prefix.html +++ b/netbox/templates/ipam/prefix.html @@ -18,7 +18,7 @@
+ + + + + + + +
AS Number{{ object.asn }} {% if object.asdot_notation %}({{ object.asdot_notation }}){% endif %}{{ object.asn_with_asdot }}
RIRVRF {% if object.vrf %} - {{ object.vrf }} ({{ object.vrf.rd }}) + {{ object.vrf }} {% else %} Global {% endif %} From 19fdd5e151a542393a2e7629bc4f10d7abcacf65 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 28 Jan 2022 14:03:36 -0500 Subject: [PATCH 27/42] Fixes #8465: Accept empty string values for Interface rf_channel in REST API --- docs/release-notes/version-3.1.md | 1 + netbox/dcim/api/serializers.py | 2 +- netbox/dcim/tests/test_api.py | 21 ++++++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 3724ac3bd..9554c1ddf 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -15,6 +15,7 @@ * [#8377](https://github.com/netbox-community/netbox/issues/8377) - Fix calculation of absolute cable lengths when specified in fractional units * [#8456](https://github.com/netbox-community/netbox/issues/8456) - Fix redundant display of VRF RD in prefix view +* [#8465](https://github.com/netbox-community/netbox/issues/8465) - Accept empty string values for Interface `rf_channel` in REST API --- diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index 337fd35c6..6549e51a1 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -621,7 +621,7 @@ class InterfaceSerializer(PrimaryModelSerializer, LinkTerminationSerializer, Con lag = NestedInterfaceSerializer(required=False, allow_null=True) mode = ChoiceField(choices=InterfaceModeChoices, allow_blank=True, required=False) rf_role = ChoiceField(choices=WirelessRoleChoices, required=False, allow_null=True) - rf_channel = ChoiceField(choices=WirelessChannelChoices, required=False) + rf_channel = ChoiceField(choices=WirelessChannelChoices, required=False, allow_blank=True) untagged_vlan = NestedVLANSerializer(required=False, allow_null=True) tagged_vlans = SerializedPKRelatedField( queryset=VLAN.objects.all(), diff --git a/netbox/dcim/tests/test_api.py b/netbox/dcim/tests/test_api.py index bc6b18ead..f403fa3eb 100644 --- a/netbox/dcim/tests/test_api.py +++ b/netbox/dcim/tests/test_api.py @@ -9,6 +9,7 @@ from dcim.models import * from ipam.models import ASN, RIR, VLAN from utilities.testing import APITestCase, APIViewTestCases from virtualization.models import Cluster, ClusterType +from wireless.choices import WirelessChannelChoices from wireless.models import WirelessLAN @@ -1239,10 +1240,8 @@ class InterfaceTest(Mixins.ComponentTraceMixin, APIViewTestCases.APIViewTestCase 'name': 'Interface 4', 'type': '1000base-t', 'mode': InterfaceModeChoices.MODE_TAGGED, - 'tx_power': 10, 'tagged_vlans': [vlans[0].pk, vlans[1].pk], 'untagged_vlan': vlans[2].pk, - 'wireless_lans': [wireless_lans[0].pk, wireless_lans[1].pk], }, { 'device': device.pk, @@ -1250,10 +1249,8 @@ class InterfaceTest(Mixins.ComponentTraceMixin, APIViewTestCases.APIViewTestCase 'type': '1000base-t', 'mode': InterfaceModeChoices.MODE_TAGGED, 'bridge': interfaces[0].pk, - 'tx_power': 10, 'tagged_vlans': [vlans[0].pk, vlans[1].pk], 'untagged_vlan': vlans[2].pk, - 'wireless_lans': [wireless_lans[0].pk, wireless_lans[1].pk], }, { 'device': device.pk, @@ -1261,10 +1258,24 @@ class InterfaceTest(Mixins.ComponentTraceMixin, APIViewTestCases.APIViewTestCase 'type': 'virtual', 'mode': InterfaceModeChoices.MODE_TAGGED, 'parent': interfaces[1].pk, - 'tx_power': 10, 'tagged_vlans': [vlans[0].pk, vlans[1].pk], 'untagged_vlan': vlans[2].pk, + }, + { + 'device': device.pk, + 'name': 'Interface 7', + 'type': InterfaceTypeChoices.TYPE_80211A, + 'tx_power': 10, 'wireless_lans': [wireless_lans[0].pk, wireless_lans[1].pk], + 'rf_channel': WirelessChannelChoices.CHANNEL_5G_32, + }, + { + 'device': device.pk, + 'name': 'Interface 8', + 'type': InterfaceTypeChoices.TYPE_80211A, + 'tx_power': 10, + 'wireless_lans': [wireless_lans[0].pk, wireless_lans[1].pk], + 'rf_channel': "", }, ] From 3bb7184f288a1aab8ecd70b3940aeec6023fa65e Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 1 Feb 2022 15:14:13 -0500 Subject: [PATCH 28/42] Fixes #8499: Content types REST API endpoint should not require model permission --- docs/release-notes/version-3.1.md | 1 + netbox/extras/api/views.py | 2 ++ netbox/extras/tests/test_api.py | 2 -- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 9554c1ddf..5369bb935 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -16,6 +16,7 @@ * [#8377](https://github.com/netbox-community/netbox/issues/8377) - Fix calculation of absolute cable lengths when specified in fractional units * [#8456](https://github.com/netbox-community/netbox/issues/8456) - Fix redundant display of VRF RD in prefix view * [#8465](https://github.com/netbox-community/netbox/issues/8465) - Accept empty string values for Interface `rf_channel` in REST API +* [#8499](https://github.com/netbox-community/netbox/issues/8499) - Content types REST API endpoint should not require model permission --- diff --git a/netbox/extras/api/views.py b/netbox/extras/api/views.py index fbeba8328..074a33823 100644 --- a/netbox/extras/api/views.py +++ b/netbox/extras/api/views.py @@ -4,6 +4,7 @@ from django_rq.queues import get_connection from rest_framework import status from rest_framework.decorators import action from rest_framework.exceptions import PermissionDenied +from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.routers import APIRootView from rest_framework.viewsets import ReadOnlyModelViewSet, ViewSet @@ -382,6 +383,7 @@ class ContentTypeViewSet(ReadOnlyModelViewSet): """ Read-only list of ContentTypes. Limit results to ContentTypes pertinent to NetBox objects. """ + permission_classes = (IsAuthenticated,) queryset = ContentType.objects.order_by('app_label', 'model') serializer_class = serializers.ContentTypeSerializer filterset_class = filtersets.ContentTypeFilterSet diff --git a/netbox/extras/tests/test_api.py b/netbox/extras/tests/test_api.py index d15b57e43..8769a9015 100644 --- a/netbox/extras/tests/test_api.py +++ b/netbox/extras/tests/test_api.py @@ -608,7 +608,6 @@ class CreatedUpdatedFilterTest(APITestCase): class ContentTypeTest(APITestCase): - @override_settings(EXEMPT_VIEW_PERMISSIONS=['contenttypes.contenttype']) def test_list_objects(self): contenttype_count = ContentType.objects.count() @@ -616,7 +615,6 @@ class ContentTypeTest(APITestCase): self.assertHttpStatus(response, status.HTTP_200_OK) self.assertEqual(response.data['count'], contenttype_count) - @override_settings(EXEMPT_VIEW_PERMISSIONS=['contenttypes.contenttype']) def test_get_object(self): contenttype = ContentType.objects.first() From 8545a547b9d8a6b6832e3fd9046e279a2ba8c10a Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 1 Feb 2022 16:31:34 -0500 Subject: [PATCH 29/42] Closes #8494: Include locations count under tenant view --- docs/release-notes/version-3.1.md | 1 + netbox/templates/tenancy/tenant.html | 4 ++++ netbox/tenancy/views.py | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 5369bb935..e827ea139 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -10,6 +10,7 @@ * [#8381](https://github.com/netbox-community/netbox/issues/8381) - Add contacts to global search function * [#8462](https://github.com/netbox-community/netbox/issues/8462) - Linkify manufacturer column in device type table * [#8476](https://github.com/netbox-community/netbox/issues/8476) - Bring the ASN Web UI up to the standard set by other objects +* [#8494](https://github.com/netbox-community/netbox/issues/8494) - Include locations count under tenant view ### Bug Fixes diff --git a/netbox/templates/tenancy/tenant.html b/netbox/templates/tenancy/tenant.html index b64438866..fb83a346f 100644 --- a/netbox/templates/tenancy/tenant.html +++ b/netbox/templates/tenancy/tenant.html @@ -59,6 +59,10 @@

{{ stats.rackreservation_count }}

Rack reservations

+
+

{{ stats.location_count }}

+

Locations

+

{{ stats.device_count }}

Devices

diff --git a/netbox/tenancy/views.py b/netbox/tenancy/views.py index e219a5670..4c9fffa1a 100644 --- a/netbox/tenancy/views.py +++ b/netbox/tenancy/views.py @@ -1,9 +1,8 @@ from django.contrib.contenttypes.models import ContentType -from django.http import Http404 from django.shortcuts import get_object_or_404 from circuits.models import Circuit -from dcim.models import Site, Rack, Device, RackReservation, Cable +from dcim.models import Cable, Device, Location, Rack, RackReservation, Site from ipam.models import Aggregate, IPAddress, Prefix, VLAN, VRF, ASN from netbox.views import generic from utilities.tables import paginate_table @@ -103,6 +102,7 @@ class TenantView(generic.ObjectView): 'site_count': Site.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'rack_count': Rack.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'rackreservation_count': RackReservation.objects.restrict(request.user, 'view').filter(tenant=instance).count(), + 'location_count': Location.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'device_count': Device.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'vrf_count': VRF.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'prefix_count': Prefix.objects.restrict(request.user, 'view').filter(tenant=instance).count(), From 4f4e6938eb7a1ea90a48bec65cd747c5dd7edbfc Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 1 Feb 2022 16:47:29 -0500 Subject: [PATCH 30/42] Closes #7504: Include IP range data under IPAM role views --- docs/release-notes/version-3.1.md | 1 + netbox/ipam/tables/ip.py | 11 ++++++++--- netbox/ipam/views.py | 1 + netbox/templates/ipam/role.html | 24 ++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index e827ea139..9c9ab0f5a 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -4,6 +4,7 @@ ### Enhancements +* [#7504](https://github.com/netbox-community/netbox/issues/7504) - Include IP range data under IPAM role views * [#8275](https://github.com/netbox-community/netbox/issues/8275) - Introduce alternative ASDOT-formatted column for ASNs * [#8367](https://github.com/netbox-community/netbox/issues/8367) - Add ASNs to global search function * [#8368](https://github.com/netbox-community/netbox/issues/8368) - Enable controlling the order of custom script form fields with `field_order` diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index df2d97dac..9fdde2b8b 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -184,6 +184,11 @@ class RoleTable(BaseTable): url_params={'role_id': 'pk'}, verbose_name='Prefixes' ) + iprange_count = LinkedCountColumn( + viewname='ipam:iprange_list', + url_params={'role_id': 'pk'}, + verbose_name='IP Ranges' + ) vlan_count = LinkedCountColumn( viewname='ipam:vlan_list', url_params={'role_id': 'pk'}, @@ -197,10 +202,10 @@ class RoleTable(BaseTable): class Meta(BaseTable.Meta): model = Role fields = ( - 'pk', 'id', 'name', 'slug', 'prefix_count', 'vlan_count', 'description', 'weight', 'tags', 'actions', - 'created', 'last_updated', + 'pk', 'id', 'name', 'slug', 'prefix_count', 'iprange_count', 'vlan_count', 'description', 'weight', 'tags', + 'actions', 'created', 'last_updated', ) - default_columns = ('pk', 'name', 'prefix_count', 'vlan_count', 'description', 'actions') + default_columns = ('pk', 'name', 'prefix_count', 'iprange_count', 'vlan_count', 'description', 'actions') # diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 38b30e9cc..c9ac44f46 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -340,6 +340,7 @@ class AggregateBulkDeleteView(generic.BulkDeleteView): class RoleListView(generic.ObjectListView): queryset = Role.objects.annotate( prefix_count=count_related(Prefix, 'role'), + iprange_count=count_related(IPRange, 'role'), vlan_count=count_related(VLAN, 'role') ) filterset = filtersets.RoleFilterSet diff --git a/netbox/templates/ipam/role.html b/netbox/templates/ipam/role.html index 879dccdfd..49570099d 100644 --- a/netbox/templates/ipam/role.html +++ b/netbox/templates/ipam/role.html @@ -38,6 +38,30 @@ {{ prefixes_table.rows|length }}
IP Ranges + {% with ipranges_count=object.ip_ranges.count %} + {% if ipranges_count %} + {{ ipranges_count }} + {% else %} + — + {% endif %} + {% endwith %} +
VLANs + {% with vlans_count=object.vlans.count %} + {% if vlans_count %} + {{ vlans_count }} + {% else %} + — + {% endif %} + {% endwith %} +
From c15cfc26f1a68656656a32d5ef37a8afc8aca1e9 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 1 Feb 2022 16:58:09 -0500 Subject: [PATCH 31/42] Fixes #8512: Correct file permissions to allow execution of housekeeping script --- contrib/netbox-housekeeping.sh | 0 docs/release-notes/version-3.1.md | 1 + 2 files changed, 1 insertion(+) mode change 100644 => 100755 contrib/netbox-housekeeping.sh diff --git a/contrib/netbox-housekeeping.sh b/contrib/netbox-housekeeping.sh old mode 100644 new mode 100755 diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 9c9ab0f5a..4b8aa7d82 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -19,6 +19,7 @@ * [#8456](https://github.com/netbox-community/netbox/issues/8456) - Fix redundant display of VRF RD in prefix view * [#8465](https://github.com/netbox-community/netbox/issues/8465) - Accept empty string values for Interface `rf_channel` in REST API * [#8499](https://github.com/netbox-community/netbox/issues/8499) - Content types REST API endpoint should not require model permission +* [#8512](https://github.com/netbox-community/netbox/issues/8512) - Correct file permissions to allow execution of housekeeping script --- From 2a8e0f9404fad7905e386fc164d7ce804ba4ec8a Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 2 Feb 2022 09:18:50 -0500 Subject: [PATCH 32/42] Update table accessors to use dunders in path --- netbox/dcim/tables/devices.py | 4 ++-- netbox/dcim/tables/sites.py | 2 +- netbox/ipam/tables/fhrp.py | 2 +- netbox/ipam/tables/ip.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index 5f15d5fbf..3c2b3dace 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -261,7 +261,7 @@ class CableTerminationTable(BaseTable): linkify=True ) cable_color = ColorColumn( - accessor='cable.color', + accessor='cable__color', orderable=False, verbose_name='Cable Color' ) @@ -276,7 +276,7 @@ class CableTerminationTable(BaseTable): class PathEndpointTable(CableTerminationTable): connection = TemplateColumn( - accessor='_path.last_node', + accessor='_path__last_node', template_code=LINKTERMINATION, verbose_name='Connection', orderable=False diff --git a/netbox/dcim/tables/sites.py b/netbox/dcim/tables/sites.py index 83e5fa408..e658f1caa 100644 --- a/netbox/dcim/tables/sites.py +++ b/netbox/dcim/tables/sites.py @@ -82,7 +82,7 @@ class SiteTable(BaseTable): linkify=True ) asn_count = LinkedCountColumn( - accessor=tables.A('asns.count'), + accessor=tables.A('asns__count'), viewname='ipam:asn_list', url_params={'site_id': 'pk'}, verbose_name='ASNs' diff --git a/netbox/ipam/tables/fhrp.py b/netbox/ipam/tables/fhrp.py index a8a25f319..d615b6374 100644 --- a/netbox/ipam/tables/fhrp.py +++ b/netbox/ipam/tables/fhrp.py @@ -46,7 +46,7 @@ class FHRPGroupTable(BaseTable): class FHRPGroupAssignmentTable(BaseTable): pk = ToggleColumn() interface_parent = tables.Column( - accessor=tables.A('interface.parent_object'), + accessor=tables.A('interface__parent_object'), linkify=True, orderable=False, verbose_name='Parent' diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index 9fdde2b8b..2cd2ab6ac 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -368,7 +368,7 @@ class IPAddressTable(BaseTable): verbose_name='Interface' ) assigned_object_parent = tables.Column( - accessor='assigned_object.parent_object', + accessor='assigned_object__parent_object', linkify=True, orderable=False, verbose_name='Device/VM' From 8211830bd8741475c2303d07195c03725a481099 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 2 Feb 2022 09:27:29 -0500 Subject: [PATCH 33/42] Fixes #8514: Correct several links to config parameters --- docs/administration/housekeeping.md | 2 +- docs/customization/custom-validation.md | 2 +- docs/graphql-api/overview.md | 2 +- docs/release-notes/version-3.0.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/administration/housekeeping.md b/docs/administration/housekeeping.md index 6f231798d..bbb03dc27 100644 --- a/docs/administration/housekeeping.md +++ b/docs/administration/housekeeping.md @@ -3,7 +3,7 @@ NetBox includes a `housekeeping` management command that should be run nightly. This command handles: * Clearing expired authentication sessions from the database -* Deleting changelog records older than the configured [retention time](../configuration/optional-settings.md#changelog_retention) +* Deleting changelog records older than the configured [retention time](../configuration/dynamic-settings.md#changelog_retention) This command can be invoked directly, or by using the shell script provided at `/opt/netbox/contrib/netbox-housekeeping.sh`. This script can be linked from your cron scheduler's daily jobs directory (e.g. `/etc/cron.daily`) or referenced directly within the cron configuration file. diff --git a/docs/customization/custom-validation.md b/docs/customization/custom-validation.md index bfa1fc1b1..9e01f8bb6 100644 --- a/docs/customization/custom-validation.md +++ b/docs/customization/custom-validation.md @@ -50,7 +50,7 @@ The `fail()` method may optionally specify a field with which to associate the s ## Assigning Custom Validators -Custom validators are associated with specific NetBox models under the [CUSTOM_VALIDATORS](../configuration/optional-settings.md#custom_validators) configuration parameter. There are three manners by which custom validation rules can be defined: +Custom validators are associated with specific NetBox models under the [CUSTOM_VALIDATORS](../configuration/dynamic-settings.md#custom_validators) configuration parameter. There are three manners by which custom validation rules can be defined: 1. Plain JSON mapping (no custom logic) 2. Dotted path to a custom validator class diff --git a/docs/graphql-api/overview.md b/docs/graphql-api/overview.md index f4cdc5fba..57dfb22bd 100644 --- a/docs/graphql-api/overview.md +++ b/docs/graphql-api/overview.md @@ -67,4 +67,4 @@ Authorization: Token $TOKEN ## Disabling the GraphQL API -If not needed, the GraphQL API can be disabled by setting the [`GRAPHQL_ENABLED`](../configuration/optional-settings.md#graphql_enabled) configuration parameter to False and restarting NetBox. +If not needed, the GraphQL API can be disabled by setting the [`GRAPHQL_ENABLED`](../configuration/dynamic-settings.md#graphql_enabled) configuration parameter to False and restarting NetBox. diff --git a/docs/release-notes/version-3.0.md b/docs/release-notes/version-3.0.md index 51ad02395..7d6341f44 100644 --- a/docs/release-notes/version-3.0.md +++ b/docs/release-notes/version-3.0.md @@ -367,7 +367,7 @@ More information about IP ranges is available [in the documentation](../models/i #### Custom Model Validation ([#5963](https://github.com/netbox-community/netbox/issues/5963)) -This release introduces the [`CUSTOM_VALIDATORS`](../configuration/optional-settings.md#custom_validators) configuration parameter, which allows administrators to map NetBox models to custom validator classes to enforce custom validation logic. For example, the following configuration requires every site to have a name of at least ten characters and a description: +This release introduces the [`CUSTOM_VALIDATORS`](../configuration/dynamic-settings.md#custom_validators) configuration parameter, which allows administrators to map NetBox models to custom validator classes to enforce custom validation logic. For example, the following configuration requires every site to have a name of at least ten characters and a description: ```python from extras.validators import CustomValidator From ea283365e7d48785c3b111eb257beef32e25bacd Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Wed, 2 Feb 2022 11:18:41 -0600 Subject: [PATCH 34/42] Fixes #8425 - Fix exception when viewing change list/records with removed plugins --- docs/release-notes/version-3.1.md | 1 + netbox/extras/tables.py | 2 +- netbox/templates/extras/objectchange.html | 10 ++++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 4b8aa7d82..c7aac208c 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -16,6 +16,7 @@ ### Bug Fixes * [#8377](https://github.com/netbox-community/netbox/issues/8377) - Fix calculation of absolute cable lengths when specified in fractional units +* [#8425](https://github.com/netbox-community/netbox/issues/8425) - Fix exception when viewing change list/records with removed plugins * [#8456](https://github.com/netbox-community/netbox/issues/8456) - Fix redundant display of VRF RD in prefix view * [#8465](https://github.com/netbox-community/netbox/issues/8465) - Accept empty string values for Interface `rf_channel` in REST API * [#8499](https://github.com/netbox-community/netbox/issues/8499) - Content types REST API endpoint should not require model permission diff --git a/netbox/extras/tables.py b/netbox/extras/tables.py index bee21f697..7cc29005f 100644 --- a/netbox/extras/tables.py +++ b/netbox/extras/tables.py @@ -30,7 +30,7 @@ CONFIGCONTEXT_ACTIONS = """ """ OBJECTCHANGE_OBJECT = """ -{% if record.changed_object.get_absolute_url %} +{% if record.changed_object and record.changed_object.get_absolute_url %} {{ record.object_repr }} {% else %} {{ record.object_repr }} diff --git a/netbox/templates/extras/objectchange.html b/netbox/templates/extras/objectchange.html index e8d72810e..501c9564f 100644 --- a/netbox/templates/extras/objectchange.html +++ b/netbox/templates/extras/objectchange.html @@ -5,12 +5,14 @@ {% block breadcrumbs %} - {% if object.related_object.get_absolute_url %} + {% if object.related_object and object.related_object.get_absolute_url %} - {% elif object.changed_object.get_absolute_url %} + {% elif object.changed_object and object.changed_object.get_absolute_url %} - {% elif object.changed_object %} + {% elif object.changed_object and object.changed_object.get_display %} + {% else %} + {% endif %} {% endblock %} @@ -54,7 +56,7 @@ Object - {% if object.changed_object.get_absolute_url %} + {% if object.changed_object and object.changed_object.get_absolute_url %} {{ object.changed_object }} {% else %} {{ object.object_repr }} From e20ac803f306871d1397a40ed8d54b03b6748045 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 2 Feb 2022 16:08:12 -0500 Subject: [PATCH 35/42] Fixes #8498: Fix display of selected content type filters in object list views --- docs/release-notes/version-3.1.md | 1 + netbox/utilities/forms/utils.py | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index c7aac208c..7cce525ed 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -19,6 +19,7 @@ * [#8425](https://github.com/netbox-community/netbox/issues/8425) - Fix exception when viewing change list/records with removed plugins * [#8456](https://github.com/netbox-community/netbox/issues/8456) - Fix redundant display of VRF RD in prefix view * [#8465](https://github.com/netbox-community/netbox/issues/8465) - Accept empty string values for Interface `rf_channel` in REST API +* [#8498](https://github.com/netbox-community/netbox/issues/8498) - Fix display of selected content type filters in object list views * [#8499](https://github.com/netbox-community/netbox/issues/8499) - Content types REST API endpoint should not require model permission * [#8512](https://github.com/netbox-community/netbox/issues/8512) - Correct file permissions to allow execution of housekeeping script diff --git a/netbox/utilities/forms/utils.py b/netbox/utilities/forms/utils.py index 343fdb8a3..6d45d524d 100644 --- a/netbox/utilities/forms/utils.py +++ b/netbox/utilities/forms/utils.py @@ -127,12 +127,13 @@ def get_selected_values(form, field_name): if not hasattr(field, 'choices'): return [str(filter_data)] - # Get choice labels + # Model choice field if type(field.choices) is forms.models.ModelChoiceIterator: - # Field uses dynamic choices: show all that have been populated on the widget - values = [ - subwidget.choice_label for subwidget in form[field_name].subwidgets - ] + # If this is a single-choice field, wrap its value in a list + if not hasattr(filter_data, '__iter__'): + values = [filter_data] + else: + values = filter_data else: # Static selection field From db3f47859867aa339c3547d01485c593af2abca9 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 2 Feb 2022 16:24:51 -0500 Subject: [PATCH 36/42] Closes #8517: Render boolean custom fields as icons in object tables --- docs/release-notes/version-3.1.md | 1 + netbox/utilities/tables.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 7cce525ed..ce50026b8 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -12,6 +12,7 @@ * [#8462](https://github.com/netbox-community/netbox/issues/8462) - Linkify manufacturer column in device type table * [#8476](https://github.com/netbox-community/netbox/issues/8476) - Bring the ASN Web UI up to the standard set by other objects * [#8494](https://github.com/netbox-community/netbox/issues/8494) - Include locations count under tenant view +* [#8517](https://github.com/netbox-community/netbox/issues/8517) - Render boolean custom fields as icons in object tables ### Bug Fixes diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py index c640e0e85..0b67434b1 100644 --- a/netbox/utilities/tables.py +++ b/netbox/utilities/tables.py @@ -414,13 +414,23 @@ class CustomFieldColumn(tables.Column): def render(self, value): if isinstance(value, list): return ', '.join(v for v in value) + elif self.customfield.type == CustomFieldTypeChoices.TYPE_BOOLEAN and value is True: + return mark_safe('') + elif self.customfield.type == CustomFieldTypeChoices.TYPE_BOOLEAN and value is False: + return mark_safe('') elif self.customfield.type == CustomFieldTypeChoices.TYPE_URL: - # Linkify custom URLs return mark_safe(f'{value}') if value is not None: return value return self.default + def value(self, value): + if isinstance(value, list): + return ','.join(v for v in value) + if value is not None: + return value + return self.default + class CustomLinkColumn(tables.Column): """ From ff3b48fa59ad2a578f6b65f623e28040547d0036 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Feb 2022 09:48:21 -0500 Subject: [PATCH 37/42] Fixes #8527: Fix display of changelog retention period --- docs/release-notes/version-3.1.md | 1 + netbox/templates/extras/object_changelog.html | 2 +- netbox/templates/extras/objectchange_list.html | 9 +++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index ce50026b8..46497bb03 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -23,6 +23,7 @@ * [#8498](https://github.com/netbox-community/netbox/issues/8498) - Fix display of selected content type filters in object list views * [#8499](https://github.com/netbox-community/netbox/issues/8499) - Content types REST API endpoint should not require model permission * [#8512](https://github.com/netbox-community/netbox/issues/8512) - Correct file permissions to allow execution of housekeeping script +* [#8527](https://github.com/netbox-community/netbox/issues/8527) - Fix display of changelog retention period --- diff --git a/netbox/templates/extras/object_changelog.html b/netbox/templates/extras/object_changelog.html index d84ba0b7a..d064ab435 100644 --- a/netbox/templates/extras/object_changelog.html +++ b/netbox/templates/extras/object_changelog.html @@ -11,7 +11,7 @@
- Change log retention: {% if settings.CHANGELOG_RETENTION %}{{ settings.CHANGELOG_RETENTION }} days{% else %}Indefinite{% endif %} + Change log retention: {% if config.CHANGELOG_RETENTION %}{{ config.CHANGELOG_RETENTION }} days{% else %}Indefinite{% endif %}
diff --git a/netbox/templates/extras/objectchange_list.html b/netbox/templates/extras/objectchange_list.html index efcac976d..4f4905e6e 100644 --- a/netbox/templates/extras/objectchange_list.html +++ b/netbox/templates/extras/objectchange_list.html @@ -2,8 +2,9 @@ {% block title %}Change Log{% endblock %} -{% block sidebar %} -
- Change log retention: {% if settings.CHANGELOG_RETENTION %}{{ settings.CHANGELOG_RETENTION }} days{% else %}Indefinite{% endif %} -
+{% block content-wrapper %} + {{ block.super }} +
+ Change log retention: {% if config.CHANGELOG_RETENTION %}{{ config.CHANGELOG_RETENTION }} days{% else %}Indefinite{% endif %} +
{% endblock %} From 24f48b11e6fb0bbc6b3ba7fbeea361c3a45a558e Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Feb 2022 10:22:38 -0500 Subject: [PATCH 38/42] Closes #8530: Indicate CSV or YAML as format for "all data" export --- docs/release-notes/version-3.1.md | 1 + .../utilities/templates/buttons/export.html | 50 +++++++++---------- netbox/utilities/templatetags/buttons.py | 22 ++++---- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 46497bb03..d2d1f4018 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -13,6 +13,7 @@ * [#8476](https://github.com/netbox-community/netbox/issues/8476) - Bring the ASN Web UI up to the standard set by other objects * [#8494](https://github.com/netbox-community/netbox/issues/8494) - Include locations count under tenant view * [#8517](https://github.com/netbox-community/netbox/issues/8517) - Render boolean custom fields as icons in object tables +* [#8530](https://github.com/netbox-community/netbox/issues/8530) - Indicate CSV or YAML as format for "all data" export ### Bug Fixes diff --git a/netbox/utilities/templates/buttons/export.html b/netbox/utilities/templates/buttons/export.html index 20ecc2dff..bb6e4379c 100644 --- a/netbox/utilities/templates/buttons/export.html +++ b/netbox/utilities/templates/buttons/export.html @@ -1,31 +1,31 @@ diff --git a/netbox/utilities/templatetags/buttons.py b/netbox/utilities/templatetags/buttons.py index ecbcb1143..d8b4987ba 100644 --- a/netbox/utilities/templatetags/buttons.py +++ b/netbox/utilities/templatetags/buttons.py @@ -81,19 +81,19 @@ def import_button(url): @register.inclusion_tag('buttons/export.html', takes_context=True) -def export_button(context, content_type=None): - add_exporttemplate_link = None +def export_button(context, content_type): + user = context['request'].user - if content_type is not None: - user = context['request'].user - export_templates = ExportTemplate.objects.restrict(user, 'view').filter(content_type=content_type) - if user.is_staff and user.has_perm('extras.add_exporttemplate'): - add_exporttemplate_link = f"{reverse('extras:exporttemplate_add')}?content_type={content_type.pk}" - else: - export_templates = [] + # Determine if the "all data" export returns CSV or YAML + data_format = 'YAML' if hasattr(content_type.model_class(), 'to_yaml') else 'CSV' + + # Retrieve all export templates for this model + export_templates = ExportTemplate.objects.restrict(user, 'view').filter(content_type=content_type) return { - 'url_params': context['request'].GET, + 'perms': context['perms'], + 'content_type': content_type, + 'url_params': context['request'].GET.urlencode() if context['request'].GET else '', 'export_templates': export_templates, - 'add_exporttemplate_link': add_exporttemplate_link, + 'data_format': data_format, } From 69305f050909f6da4a51c9b3f9d3f9fc7ba21f09 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Feb 2022 10:30:26 -0500 Subject: [PATCH 39/42] Fixes #8315: Fix display of NAT link for primary IPv4 address under device view --- docs/release-notes/version-3.1.md | 1 + netbox/templates/dcim/device.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index d2d1f4018..672d73d20 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -6,6 +6,7 @@ * [#7504](https://github.com/netbox-community/netbox/issues/7504) - Include IP range data under IPAM role views * [#8275](https://github.com/netbox-community/netbox/issues/8275) - Introduce alternative ASDOT-formatted column for ASNs +* [#8315](https://github.com/netbox-community/netbox/issues/8315) - Fix display of NAT link for primary IPv4 address under device view * [#8367](https://github.com/netbox-community/netbox/issues/8367) - Add ASNs to global search function * [#8368](https://github.com/netbox-community/netbox/issues/8368) - Enable controlling the order of custom script form fields with `field_order` * [#8381](https://github.com/netbox-community/netbox/issues/8381) - Add contacts to global search function diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 31f2a18bd..35224a1fc 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -188,7 +188,7 @@ {% if object.primary_ip4 %} {{ object.primary_ip4.address.ip }} {% if object.primary_ip4.nat_inside %} - (NAT for {{ object.primary_ip4.nat_inside.address.ip }}) + (NAT for {{ object.primary_ip4.nat_inside.address.ip }}) {% elif object.primary_ip4.nat_outside %} (NAT: {{ object.primary_ip4.nat_outside.address.ip }}) {% endif %} From 94a0a3b568a8d857b77fbe9bb86af44ce70a1011 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Feb 2022 10:39:39 -0500 Subject: [PATCH 40/42] Closes #8502: Omit [all] from social-auth-core in base requirements --- base_requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base_requirements.txt b/base_requirements.txt index aaa9c7f44..0b8365e0e 100644 --- a/base_requirements.txt +++ b/base_requirements.txt @@ -100,7 +100,7 @@ PyYAML # Social authentication framework # https://github.com/python-social-auth/social-core -social-auth-core[all] +social-auth-core # Django app for social-auth-core # https://github.com/python-social-auth/social-app-django From 70ce7293aca0d31a07815f2dd40fa7390ba02088 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Feb 2022 10:51:41 -0500 Subject: [PATCH 41/42] Release v3.1.7 --- .github/ISSUE_TEMPLATE/bug_report.yaml | 2 +- .github/ISSUE_TEMPLATE/feature_request.yaml | 2 +- docs/release-notes/version-3.1.md | 4 ++-- netbox/netbox/settings.py | 2 +- requirements.txt | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 16182af64..1c330e8a8 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -14,7 +14,7 @@ body: attributes: label: NetBox version description: What version of NetBox are you currently running? - placeholder: v3.1.6 + placeholder: v3.1.7 validations: required: true - type: dropdown diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index 0be999b16..eea258c09 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -14,7 +14,7 @@ body: attributes: label: NetBox version description: What version of NetBox are you currently running? - placeholder: v3.1.6 + placeholder: v3.1.7 validations: required: true - type: dropdown diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 672d73d20..27aaa4b4c 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -1,12 +1,11 @@ # NetBox v3.1 -## v3.1.7 (FUTURE) +## v3.1.7 (2022-02-03) ### Enhancements * [#7504](https://github.com/netbox-community/netbox/issues/7504) - Include IP range data under IPAM role views * [#8275](https://github.com/netbox-community/netbox/issues/8275) - Introduce alternative ASDOT-formatted column for ASNs -* [#8315](https://github.com/netbox-community/netbox/issues/8315) - Fix display of NAT link for primary IPv4 address under device view * [#8367](https://github.com/netbox-community/netbox/issues/8367) - Add ASNs to global search function * [#8368](https://github.com/netbox-community/netbox/issues/8368) - Enable controlling the order of custom script form fields with `field_order` * [#8381](https://github.com/netbox-community/netbox/issues/8381) - Add contacts to global search function @@ -18,6 +17,7 @@ ### Bug Fixes +* [#8315](https://github.com/netbox-community/netbox/issues/8315) - Fix display of NAT link for primary IPv4 address under device view * [#8377](https://github.com/netbox-community/netbox/issues/8377) - Fix calculation of absolute cable lengths when specified in fractional units * [#8425](https://github.com/netbox-community/netbox/issues/8425) - Fix exception when viewing change list/records with removed plugins * [#8456](https://github.com/netbox-community/netbox/issues/8456) - Fix redundant display of VRF RD in prefix view diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 199df264c..d69c45fc9 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -19,7 +19,7 @@ from netbox.config import PARAMS # Environment setup # -VERSION = '3.1.7-dev' +VERSION = '3.1.7' # Hostname HOSTNAME = platform.node() diff --git a/requirements.txt b/requirements.txt index 83c1b9f2e..a281a5326 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Django==3.2.11 +Django==3.2.12 django-cors-headers==3.11.0 django-debug-toolbar==3.2.4 django-filter==21.1 @@ -18,15 +18,15 @@ gunicorn==20.1.0 Jinja2==3.0.3 Markdown==3.3.6 markdown-include==0.6.0 -mkdocs-material==8.1.7 +mkdocs-material==8.1.9 netaddr==0.8.0 Pillow==8.4.0 psycopg2-binary==2.9.3 PyYAML==6.0 social-auth-app-django==5.0.0 -social-auth-core==4.1.0 +social-auth-core==4.2.0 svgwrite==1.4.1 -tablib==3.1.0 +tablib==3.2.0 # Workaround for #7401 jsonschema==3.2.0 From 795134c084c24efe2c86de266390071216b0233b Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Feb 2022 11:34:36 -0500 Subject: [PATCH 42/42] PRVB --- 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 d69c45fc9..c7498d1f2 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -19,7 +19,7 @@ from netbox.config import PARAMS # Environment setup # -VERSION = '3.1.7' +VERSION = '3.1.8-dev' # Hostname HOSTNAME = platform.node()