Compare commits

...

12 Commits

Author SHA1 Message Date
Carlos Torres 4f88b2c1aa
Merge 745a815d27 into d606cf1b3c 2024-04-22 15:06:31 -05:00
Jeremy Stretch d606cf1b3c Update source translations 2024-04-22 15:50:38 -04:00
Jeremy Stretch 0b0dab42eb PRVB 2024-04-22 12:23:31 -04:00
Jeremy Stretch d115601da3
Merge pull request #15805 from netbox-community/develop
Release v3.7.6
2024-04-22 12:18:27 -04:00
Jeremy Stretch a61e20849b Release v3.7.6 2024-04-22 11:46:03 -04:00
Arthur Hanson 1eca1c3d17
15803 localize help_text (#15804) 2024-04-22 11:42:20 -04:00
transifex-integration[bot] 5d95d49268
Update translations 2024-04-22 11:28:04 -04:00
Jeremy Stretch 6b8bfe9947 Changelog for #14690, #15541, #15588, #15761, #15771, #15790 2024-04-22 11:25:21 -04:00
Jeremy Stretch e87877b6ea Fixes #15771: Show id field as supported on all bulk import forms 2024-04-22 11:08:36 -04:00
Jeremy Stretch ebe504c825 Closes #15664: Restore usage of READTHEDOCS env variable 2024-04-22 09:52:03 -04:00
Markku Leiniö b6e38b2ebe
Closes #14690: Pretty-format JSON fields in the config form (#15623)
* Closes #14690: Pretty-format JSON fields in the config form

* Revert changes

* Use our own JSONField for config parameters for pretty editor outputs

* Compare identity instead of equality
2024-04-22 09:25:16 -04:00
8ctorres 745a815d27 Add references to Nbshell in export templates, reports and scripts 2024-04-07 12:00:11 +00:00
25 changed files with 335 additions and 209 deletions

View File

@ -26,7 +26,7 @@ body:
attributes:
label: NetBox Version
description: What version of NetBox are you currently running?
placeholder: v3.7.5
placeholder: v3.7.6
validations:
required: true
- type: dropdown

View File

@ -14,7 +14,7 @@ body:
attributes:
label: NetBox version
description: What version of NetBox are you currently running?
placeholder: v3.7.5
placeholder: v3.7.6
validations:
required: true
- type: dropdown

View File

@ -61,7 +61,8 @@ django-timezone-field
# A REST API framework for Django projects
# https://www.django-rest-framework.org/community/release-notes/
djangorestframework
# Pinned to 3.14 for NetBox v3.7
djangorestframework<3.15
# Sane and flexible OpenAPI 3 schema generation for Django REST framework.
# https://github.com/tfranzel/drf-spectacular/blob/master/CHANGELOG.rst

View File

@ -2,8 +2,8 @@
{% block site_meta %}
{{ super() }}
{# Disable search indexing unless we're building for ReadTheDocs (see #10496) #}
{% if page.canonical_url != 'https://docs.netbox.dev/' %}
{# Disable search indexing unless we're building for ReadTheDocs #}
{% if not config.extra.readthedocs %}
<meta name="robots" content="noindex">
{% endif %}
{% endblock %}

View File

@ -1,6 +1,6 @@
# The NetBox Python Shell
NetBox includes a Python management shell within which objects can be directly queried, created, modified, and deleted. To enter the shell, run the following command:
NetBox includes a Python management shell within which objects can be directly queried, created, modified, and deleted. To enter the shell, run the following command from a shell that has the netbox virtualenv activated:
```
./manage.py nbshell
@ -143,6 +143,40 @@ To return the inverse of a filtered queryset, use `exclude()` instead of `filter
346
```
If the query returns only one object, the get() method can be used. This method will yield the actual object resulting from the query, instead of a QuerySet. For this to work, the query must return only one object. The syntax is identical to the filter and exclude methods. For example, we can get a device from it's asset tag:
```
>>>
>>> Device.objects.get(asset_tag="100079912515")
<Device: AP994003 (100079912515)>
>>>
```
If the query returns more than one object, a MultipleObjectsReturned exception will be thrown:
```
>>> Device.objects.get(role_id=13)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/srv/netbox/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/srv/netbox/venv/lib/python3.10/site-packages/django/db/models/query.py", line 640, in get
raise self.model.MultipleObjectsReturned(
dcim.models.devices.Device.MultipleObjectsReturned: get() returned more than one Device -- it returned more than 20!
>>>
```
Queries can all also be executed from a particular object instead of from the model itself. For instance, to get all circuits that are assigned to one site, it is easier to filter from the site itself, instead of using the "Circuit" model and building the query from there. This is particularly useful for configuration templates and export templates, since it allows to query other database objects that are related to the object that we're rendering the template for.
```
>>> site.circuit_terminations.all()
<RestrictedQuerySet [<CircuitTermination: 20899518: Termination A>, <CircuitTermination: DT00018356: Termination A>]>
>>>
```
The same methods (all, filter, exclude, get...) can be used in this kind of queries.
!!! info
The examples above are intended only to provide a cursory introduction to queryset filtering. For an exhaustive list of the available filters, please consult the [Django queryset API documentation](https://docs.djangoproject.com/en/stable/ref/models/querysets/).

View File

@ -56,6 +56,15 @@ class AnotherCustomScript(Script):
script_order = (MyCustomScript, AnotherCustomScript)
```
### The run() method
The run() method is the entrypoint for the script, and it runs in the context of Netbox's own execution environment. This means from here, everything inside Netbox itself is accesible. The [Netbox Shell](../administration/netbox-shell.md) is a good resource to keep in hand, since it allows to see the objects in Netbox in the same way the run() method of the script does.
The run() method can itself call other methods that are in the same module but outside the "MyCustomScript" class, and if there are several scripts in the same module (this is, in the same Python file), both scripts can reuse the same auxiliary methods, keeping the code cleaner. For this reason, it is encouraged to keep similar scripts in the same module.
The run() method can return a string, and this will be displayed in a text box in the web interface after the script finishes. This is useful, for instance, for returning a piece of configuration or information that you want the user to be able to easily copy and paste somewhere else.
## Module Attributes
### `name`

View File

@ -32,6 +32,8 @@ If you need to use the config context data in an export template, you'll should
{% endfor %}
```
To see all the attributes of a given object, you can use the [Netbox Shell](../administration/netbox-shell.md). It supports autocompletion and allows one to see all of the methods and attributes a given object type has. All of them can be called from within a Jinja template. Using queries from one object to another, one can navigate pretty much the entire Netbox object model. For instance, from an export template for sites, one can get the devices that are in that site, the circuits that are connected to those devices, the providers that serve those circuits... etc, so an export template is not limited to just the model that it's being called from. In fact, the same result can be achieved in different ways, depending on which model you start from.
The `as_attachment` attribute of an export template controls its behavior when rendered. If true, the rendered content will be returned to the user as a downloadable file. If false, it will be displayed within the browser. (This may be handy e.g. for generating HTML content.)
A MIME type and file extension can optionally be defined for each export template. The default MIME type is `text/plain`.

View File

@ -29,7 +29,9 @@ class DeviceIPsReport(Report):
description = "Check that every device has a primary IP address assigned"
```
Within each report class, we'll create a number of test methods to execute our report's logic. In DeviceConnectionsReport, for instance, we want to ensure that every live device has a console connection, an out-of-band management connection, and two power connections.
Within each report class, we'll create a number of test methods to execute our report's logic. The method's name must start with "test_" and it takes no arguments.
In DeviceConnectionsReport, for instance, we want to ensure that every live device has a console connection, an out-of-band management connection, and two power connections.
```
from dcim.choices import DeviceStatusChoices
@ -82,6 +84,8 @@ class DeviceConnectionsReport(Report):
As you can see, reports are completely customizable. Validation logic can be as simple or as complex as needed. Also note that the `description` attribute support markdown syntax. It will be rendered in the report list page.
In the same way scripts do, reports run from within Netbox's own environment and can access the objects inside Netbox directly. The [Netbox Shell](../administration/netbox-shell.md) is a good resource to keep in hand, since it allows to see the objects in Netbox in the same way the test methods of a report do.
!!! warning
Reports should never alter data: If you find yourself using the `create()`, `save()`, `update()`, or `delete()` methods on objects within reports, stop and re-evaluate what you're trying to accomplish. Note that there are no safeguards against the accidental alteration or destruction of data.

View File

@ -35,6 +35,8 @@ Configuration templates are written in the [Jinja2 templating language](https://
{% endblock %}
```
To see all the attributes of a given object, you can use the [Netbox Shell](../administration/netbox-shell.md). It supports autocompletion and allows one to see all of the methods and attributes a given object type has. All of them can be called from within the configuration template. Also, other objects, for instance, a device's interfaces or connected circuits can be accessed from the template itself, so the rendered configuration may include information not only about the device itself, but also related objects like IP addresses or circuits.
When rendered for a specific NetBox device, the template's `device` variable will be populated with the device instance, and `ntp_servers` will be pulled from the device's available context data. The resulting output will be a valid configuration segment that can be applied directly to a compatible network device.
### Context Data

View File

@ -62,7 +62,7 @@ class MyModelImportForm(NetBoxModelImportForm):
site = CSVModelChoiceField(
queryset=Site.objects.all(),
to_field_name='name',
help_text='Assigned site'
help_text=_('Assigned site')
)
class Meta:

View File

@ -1,20 +1,30 @@
# NetBox v3.7
## v3.7.6 (FUTURE)
## v3.7.7 (FUTURE)
---
## v3.7.6 (2024-04-22)
### Enhancements
* [#14690](https://github.com/netbox-community/netbox/issues/14690) - Improve rendering of JSON data in configuration form
* [#15427](https://github.com/netbox-community/netbox/issues/15427) - Enable compatibility with non-Amazon S3 providers for remote data sources
* [#15640](https://github.com/netbox-community/netbox/issues/15640) - Add global search support for L2VPN identifiers
* [#15644](https://github.com/netbox-community/netbox/issues/15644) - Introduce new configuration parameters for enabling HTTP Strict Transport Security (HSTS)
### Bug Fixes
* [#15541](https://github.com/netbox-community/netbox/issues/15541) - Restore ability to modify assigned component template when adding/modifying an inventory item template
* [#15582](https://github.com/netbox-community/netbox/issues/15582) - Fix permission constraints for synchronization of remote data sources
* [#15588](https://github.com/netbox-community/netbox/issues/15588) - Correct OpenAPI schema definitions for read-only fields which may return null values
* [#15635](https://github.com/netbox-community/netbox/issues/15635) - Extend plugin removal instruction to include reindexing the global search cache
* [#15654](https://github.com/netbox-community/netbox/issues/15654) - Fix `AttributeError` exception when attempting to save an incomplete tunnel termination
* [#15668](https://github.com/netbox-community/netbox/issues/15668) - Fix permission required to display virtual disks tab on virtual machine UI view
* [#15685](https://github.com/netbox-community/netbox/issues/15685) - Allow filtering cables by decimal values using UI filter form
* [#15761](https://github.com/netbox-community/netbox/issues/15761) - Add missing `ike_policy` & `ike_policy_id` filters for IKE proposals
* [#15771](https://github.com/netbox-community/netbox/issues/15771) - Include `id` in list of supported fields for all bulk import forms
* [#15790](https://github.com/netbox-community/netbox/issues/15790) - Fix live preview support for EventRule comments
---

View File

@ -42,6 +42,7 @@ plugins:
show_root_toc_entry: false
show_source: false
extra:
readthedocs: !ENV READTHEDOCS
social:
- icon: fontawesome/brands/github
link: https://github.com/netbox-community/netbox

View File

@ -3,6 +3,7 @@ import json
from django import forms
from django.conf import settings
from django.forms.fields import JSONField as _JSONField
from django.utils.translation import gettext_lazy as _
from core.forms.mixins import SyncedDataMixin
@ -12,7 +13,7 @@ from netbox.forms import NetBoxModelForm
from netbox.registry import registry
from netbox.utils import get_data_backend_choices
from utilities.forms import BootstrapMixin, get_field_value
from utilities.forms.fields import CommentField
from utilities.forms.fields import CommentField, JSONField
from utilities.forms.widgets import HTMXSelect
__all__ = (
@ -132,6 +133,9 @@ class ConfigFormMetaclass(forms.models.ModelFormMetaclass):
'help_text': param.description,
}
field_kwargs.update(**param.field_kwargs)
if param.field is _JSONField:
# Replace with our own JSONField to get pretty JSON in config editor
param.field = JSONField
param_fields[param.name] = param.field(**field_kwargs)
attrs.update(param_fields)

View File

@ -668,7 +668,7 @@ class DeviceSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:device-detail')
device_type = NestedDeviceTypeSerializer()
role = NestedDeviceRoleSerializer()
device_role = NestedDeviceRoleSerializer(read_only=True, help_text='Deprecated in v3.6 in favor of `role`.')
device_role = NestedDeviceRoleSerializer(read_only=True, help_text=_('Deprecated in v3.6 in favor of `role`.'))
tenant = NestedTenantSerializer(required=False, allow_null=True, default=None)
platform = NestedPlatformSerializer(required=False, allow_null=True)
site = NestedSiteSerializer()

View File

@ -1373,14 +1373,14 @@ class VirtualDeviceContextImportForm(NetBoxModelImportForm):
label=_('Device'),
queryset=Device.objects.all(),
to_field_name='name',
help_text='Assigned role'
help_text=_('Assigned role')
)
tenant = CSVModelChoiceField(
label=_('Tenant'),
queryset=Tenant.objects.all(),
required=False,
to_field_name='name',
help_text='Assigned tenant'
help_text=_('Assigned tenant')
)
status = CSVChoiceField(
label=_('Status'),

View File

@ -73,17 +73,12 @@ class NetBoxModelImportForm(CSVModelForm, NetBoxModelForm):
"""
Base form for creating a NetBox objects from CSV data. Used for bulk importing.
"""
id = forms.IntegerField(
label=_('Id'),
required=False,
help_text='Numeric ID of an existing object to update (if not creating a new object)'
)
tags = CSVModelMultipleChoiceField(
label=_('Tags'),
queryset=Tag.objects.all(),
required=False,
to_field_name='slug',
help_text='Tag slugs separated by commas, encased with double quotes (e.g. "tag1,tag2,tag3")'
help_text=_('Tag slugs separated by commas, encased with double quotes (e.g. "tag1,tag2,tag3")')
)
def _get_custom_fields(self, content_type):

View File

@ -28,7 +28,7 @@ from netbox.plugins import PluginConfig
# Environment setup
#
VERSION = '3.7.6-dev'
VERSION = '3.7.7-dev'
# Hostname
HOSTNAME = platform.node()

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@
# Translators:
# Jonathan Senecal, 2024
# Jeremy Stretch, 2024
# Quentin Laurent, 2024
#
#, fuzzy
msgid ""
@ -14,7 +15,7 @@ msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-04-04 19:11+0000\n"
"PO-Revision-Date: 2023-10-30 17:48+0000\n"
"Last-Translator: Jeremy Stretch, 2024\n"
"Last-Translator: Quentin Laurent, 2024\n"
"Language-Team: French (https://app.transifex.com/netbox-community/teams/178115/fr/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -3716,7 +3717,7 @@ msgstr "Réservation"
#: dcim/forms/model_forms.py:301 dcim/forms/model_forms.py:384
#: utilities/forms/fields/fields.py:47
msgid "Slug"
msgstr "limace"
msgstr "Identifiant"
#: dcim/forms/model_forms.py:308 templates/dcim/devicetype.html:12
msgid "Chassis"
@ -5813,7 +5814,7 @@ msgstr "Poids maximum"
#: ipam/tables/asn.py:66 netbox/navigation/menu.py:16
#: netbox/navigation/menu.py:18
msgid "Sites"
msgstr "Des sites"
msgstr "Sites"
#: dcim/tests/test_api.py:49
msgid "Test case must set peer_termination_type"
@ -13355,7 +13356,7 @@ msgstr ""
#: utilities/forms/fields/fields.py:48
msgid "URL-friendly unique shorthand"
msgstr "Raccourci unique et convivial pour les URL"
msgstr "Identifiant unique utilisable dans les URL"
#: utilities/forms/fields/fields.py:101
msgid "Enter context data in <a href=\"https://json.org/\">JSON</a> format."

View File

@ -5,8 +5,8 @@
#
# Translators:
# Tatsuya Ueda <ml@tatsuya.info>, 2024
# teapot, 2024
# Jeremy Stretch, 2024
# teapot, 2024
#
#, fuzzy
msgid ""
@ -15,7 +15,7 @@ msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-04-04 19:11+0000\n"
"PO-Revision-Date: 2023-10-30 17:48+0000\n"
"Last-Translator: Jeremy Stretch, 2024\n"
"Last-Translator: teapot, 2024\n"
"Language-Team: Japanese (https://app.transifex.com/netbox-community/teams/178115/ja/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -7681,7 +7681,7 @@ msgstr "プレフィックス内およびプレフィックスを含む"
#: ipam/filtersets.py:259
msgid "Prefixes which contain this prefix or IP"
msgstr "このプレフィックスまたは IP を含むプレフィックス"
msgstr "このプレフィックス / IP を含むプレフィックス"
#: ipam/filtersets.py:270 ipam/filtersets.py:538 ipam/forms/bulk_edit.py:326
#: ipam/forms/filtersets.py:191 ipam/forms/filtersets.py:317
@ -7700,11 +7700,11 @@ msgstr "VLAN 番号 (1-4094)"
#: ipam/forms/model_forms.py:430 templates/tenancy/contact.html:54
#: tenancy/forms/bulk_edit.py:112
msgid "Address"
msgstr "住所"
msgstr "アドレス"
#: ipam/filtersets.py:445
msgid "Ranges which contain this prefix or IP"
msgstr "このプレフィックスまたは IP を含む範囲"
msgstr "このプレフィックス / IP を含む範囲"
#: ipam/filtersets.py:473 ipam/filtersets.py:529
msgid "Parent prefix"
@ -7743,11 +7743,11 @@ msgstr "FHRP グループ (ID)"
#: ipam/filtersets.py:618
msgid "Is assigned to an interface"
msgstr "インタフェースに割り当てられている"
msgstr "インタフェースに割り当てられている"
#: ipam/filtersets.py:622
msgid "Is assigned"
msgstr "割り当てられている"
msgstr "割当済みか"
#: ipam/filtersets.py:1047
msgid "IP address (ID)"
@ -7881,7 +7881,7 @@ msgstr "子 VLAN VID の最小値"
#: ipam/forms/bulk_edit.py:420
msgid "Maximum child VLAN VID"
msgstr "子 VLAN VID の最大"
msgstr "子 VLAN VID の最大"
#: ipam/forms/bulk_edit.py:428 ipam/forms/model_forms.py:531
msgid "Scope type"
@ -7905,11 +7905,11 @@ msgstr "ポート"
#: ipam/forms/bulk_import.py:47
msgid "Import route targets"
msgstr "ルートターゲットをインポート"
msgstr "インポートルートターゲット"
#: ipam/forms/bulk_import.py:53
msgid "Export route targets"
msgstr "ルートターゲットをエクスポートする"
msgstr "エクスポートルートターゲット"
#: ipam/forms/bulk_import.py:91 ipam/forms/bulk_import.py:111
#: ipam/forms/bulk_import.py:131

View File

@ -70,6 +70,12 @@ class CSVModelForm(forms.ModelForm):
"""
ModelForm used for the import of objects in CSV format.
"""
id = forms.IntegerField(
label=_('ID'),
required=False,
help_text=_('Numeric ID of an existing object to update (if not creating a new object)')
)
def __init__(self, *args, headers=None, **kwargs):
self.headers = headers or {}
super().__init__(*args, **kwargs)

View File

@ -42,7 +42,7 @@ class WirelessLANImportForm(NetBoxModelImportForm):
status = CSVChoiceField(
label=_('Status'),
choices=WirelessLANStatusChoices,
help_text='Operational status'
help_text=_('Operational status')
)
vlan = CSVModelChoiceField(
label=_('VLAN'),

View File

@ -18,11 +18,11 @@ drf-spectacular==0.27.2
drf-spectacular-sidecar==2024.4.1
feedparser==6.0.11
graphene-django==3.0.0
gunicorn==21.2.0
gunicorn==22.0.0
Jinja2==3.1.3
Markdown==3.6
mkdocs-material==9.5.17
mkdocstrings[python-legacy]==0.24.2
mkdocs-material==9.5.18
mkdocstrings[python-legacy]==0.24.3
netaddr==1.2.1
Pillow==10.3.0
psycopg[binary,pool]==3.1.18