Compare commits

...

61 Commits

Author SHA1 Message Date
Jeremy Stretch
2b93510c45 Merge pull request #3121 from digitalocean/develop
Release v2.5.11
2019-04-29 14:25:37 -04:00
Jeremy Stretch
9717c6f825 Add a note about Django 2.2 2019-04-29 14:22:47 -04:00
Jeremy Stretch
92c227d103 Release v2.5.11 2019-04-29 14:21:10 -04:00
Jeremy Stretch
1491222642 Fixes #3072: Preserve multiselect filter values when updating per-page count for list views 2019-04-29 12:54:03 -04:00
Jeremy Stretch
39fceeb455 Add device field on cable search form (#3023) 2019-04-29 11:29:07 -04:00
Jeremy Stretch
3562b5552b Fixes #3118: Disable last_login update on login when maintenance mode is enabled 2019-04-29 11:04:32 -04:00
Jeremy Stretch
6d778f686d Closes #3023: Add support for filtering cables by connected device 2019-04-29 10:07:08 -04:00
Jeremy Stretch
245a97176a Closes #2986: Replace DeviceComponentManager with NaturalOrderingManager 2019-04-26 22:23:28 -04:00
Jeremy Stretch
ca56871aaa Changelog & CSS fix for #3070 2019-04-26 17:06:54 -04:00
Jeremy Stretch
bd4086cb50 Merge pull request #3103 from clercrobin/add_decommissioning
Fixes : #3070 Add the decommissioning status for devices
2019-04-26 17:04:36 -04:00
Jeremy Stretch
d8c9b1af27 Fixes #3116: Fix tagged_items count in tags API endpoint 2019-04-26 16:54:13 -04:00
Jeremy Stretch
19d2850b29 Fixes #3112: Fix ordering of interface connections list by termination B name/device 2019-04-26 16:41:01 -04:00
rclerc
f4636537ad Add the decommissioning status for devices 2019-04-24 09:14:29 +02:00
Jeremy Stretch
f4aec1e7d0 Change VLAN view columns to a 4/8 split 2019-04-22 07:47:16 -04:00
John Anderson
8b75969d1d fix typo in requirements 2019-04-18 14:39:12 -04:00
John Anderson
a5e1088f1f fixes #2621 - deletion issue in the changelog middleware 2019-04-18 14:37:58 -04:00
Jeremy Stretch
8d79353d9b Post-release version bump 2019-04-08 14:30:06 -04:00
Jeremy Stretch
f3fffc6161 Merge pull request #3053 from digitalocean/develop
Release v2.5.10
2019-04-08 14:26:27 -04:00
Jeremy Stretch
a8d20e13a8 Release v2.5.10 2019-04-08 14:19:37 -04:00
Jeremy Stretch
9a91bdbdb2 Fixes #2937: Redirect to list view after editing an object from list view 2019-04-08 14:10:55 -04:00
Jeremy Stretch
6f8591f769 Closes #3052: Add Jinja2 support for export templates 2019-04-08 12:20:24 -04:00
dansheps
7f6d79362e Fix virtualization test and add to changelog 2019-04-05 09:47:38 -05:00
Daniel Sheppard
c032413201 Remove unneeded import from testing. 2019-04-05 09:39:04 -05:00
dansheps
e556c78599 Fixes #3047: Fix exception string for invalid MAC Address format 2019-04-05 09:36:56 -05:00
Jeremy Stretch
1b389d662b Fixes #3046: Fix exception at reports API endpoint 2019-04-04 17:34:36 -04:00
Jeremy Stretch
090efde21a Fixes #3044: Ignore site/rack fields when connecting a new cable via device search 2019-04-04 16:19:20 -04:00
Jeremy Stretch
74c03e3295 Fixes #3036: DCIM interfaces API endpoint should not include VM interfaces 2019-04-04 15:07:41 -04:00
Jeremy Stretch
858be6d216 Fixes #3039: Fix exception when retrieving change object for a component template via API 2019-04-04 15:00:59 -04:00
Jeremy Stretch
1e160fd9e9 Fixes #3041: Fix form widget for bulk cable label update 2019-04-04 12:43:14 -04:00
Jeremy Stretch
7c6d2a6281 Post-release version bump 2019-04-02 12:37:39 -04:00
Jeremy Stretch
fdf168934e Merge pull request #3034 from digitalocean/develop
Release v2.5.9
2019-04-02 12:34:34 -04:00
Jeremy Stretch
738a20ad34 Release v2.5.9 2019-04-02 11:54:00 -04:00
Jeremy Stretch
3602d5a84c Fixes #3032: Save assigned tags when creating a new secret 2019-04-02 11:42:49 -04:00
Jeremy Stretch
d23ca041cf Ensure fallback to default serializer when attempting to load nested serializer 2019-04-02 11:17:14 -04:00
Jeremy Stretch
110387e81b Fixes #3019: Fix tag population when running NetBox within a path 2019-04-02 11:05:16 -04:00
Jeremy Stretch
498f132cad Fixes #3027: Ignore empty local context data when rendering config contexts 2019-03-28 10:16:28 -04:00
Jeremy Stretch
dff3165402 Fixes #3026: Tweak prefix/IP filter forms to filter using VRF ID rather than route distinguisher 2019-03-28 10:06:25 -04:00
Jeremy Stretch
3f5f75c71f Fixes #3001: Fix API representation of ObjectChange action and add changed_object_type 2019-03-28 09:57:26 -04:00
John Anderson
2e1887eb0e implements #3025 - Add request ID to outbound webhook requests 2019-03-24 15:35:42 -04:00
John Anderson
2170eedf08 implements #2933 - username in webhooks 2019-03-24 15:31:12 -04:00
Jeremy Stretch
3acc8ca3ab Fixes #3022: Add missing cable termination types to DCIM _choices endpoint 2019-03-22 16:26:56 -04:00
Jeremy Stretch
fc76c8eb0f FieldChoicesViewSet should infer field choices from serializer, not model 2019-03-22 16:24:53 -04:00
Jeremy Stretch
7d1ee2e94e Changelog for #3011 2019-03-19 10:34:07 -04:00
Jeremy Stretch
3cea92384c Merge pull request #3012 from ajknv/develop
Add support for configuring use of an SSL connection to Redis.
2019-03-19 10:28:01 -04:00
Jeremy Stretch
6ba3d611af Merge pull request #3015 from DanSheps/3014-fix-vm-roles
Changes vm_role from "true" to "True" in virtualization form
2019-03-19 10:24:59 -04:00
Jeremy Stretch
f6345b9a5d Fixes #2998: Limit device query to non-racked devices if no rack selected when creating a cable 2019-03-19 10:22:52 -04:00
Jeremy Stretch
044f7395bb Closes #2995: Added powerbox to community SDK list 2019-03-19 09:48:16 -04:00
Alexander Kinneer
8bda6be65a Merge branch 'develop' of https://github.com/ajknv/netbox into develop 2019-03-18 11:28:48 -05:00
Alexander Kinneer
e544705256 Add support for configuring use of an SSL connection to Redis.
Requires a build or release of django-rq containing
44f3fdd7cb
2019-03-18 11:26:37 -05:00
Alexander Kinneer
f88099eb3b Add documentation for new Redis SSL configuration parameter. 2019-03-18 11:15:40 -05:00
dansheps
5f40be4bd5 Changes vm_role from "true" to "True" in virtualization form 2019-03-18 09:22:36 -05:00
John Anderson
1bf04f2e30 fixes #2936 - device role selection showing duplicate first entry 2019-03-17 01:24:54 -04:00
Alexander Kinneer
7edad4eba9 Add support for configuring use of an SSL connection to Redis.
Requires a build or release of django-rq containing
44f3fdd7cb
2019-03-15 10:35:03 -05:00
Jeremy Stretch
dd7249d2ef Merge pull request #2996 from DanSheps/2207-fix_deterministic_ordering_of_interfaces
Fixes #2207
2019-03-13 16:15:34 -04:00
dansheps
aab84ba6f3 Change ID to PK 2019-03-13 14:02:23 -05:00
Jeremy Stretch
520af82f05 Closes #2924: Add interface type for QSFP28 50GE 2019-03-13 10:00:40 -04:00
dansheps
9292534324 Changelog Updates 2019-03-12 15:54:38 -05:00
dansheps
61efe6102e Fixes #2207
* Added 'id' field sort to InterfaceManager
2019-03-12 15:52:44 -05:00
Daniel Sheppard
0022a5a6e2 Merge pull request #2992 from DanSheps/api-documentation-filtering
* Fixes #2991: Fixed typo
* Fixes #2577: Clarified documentation regarding filtering multiple times (some filters can, some cannot)
2019-03-11 15:26:59 -05:00
dansheps
332487efcd API Filtering Documentation Changes
* Fixed typo
* Clarified documentation regarding filtering multiple times (some filters can, some cannot)
2019-03-11 15:11:16 -05:00
Jeremy Stretch
28331dfd53 Post-release version bump 2019-03-11 13:39:30 -04:00
44 changed files with 360 additions and 127 deletions

View File

@@ -1,3 +1,68 @@
2.5.11 (2019-04-29)
## Notes
This release upgrades the Django framework to version 2.2.
## Enhancements
* [#2986](https://github.com/digitalocean/netbox/issues/2986) - Improve natural ordering of device components
* [#3023](https://github.com/digitalocean/netbox/issues/3023) - Add support for filtering cables by connected device
* [#3070](https://github.com/digitalocean/netbox/issues/3070) - Add decommissioning status for devices
## Bug Fixes
* [#2621](https://github.com/digitalocean/netbox/issues/2621) - Upgrade Django requirement to 2.2 to fix object deletion issue in the changelog middleware
* [#3072](https://github.com/digitalocean/netbox/issues/3072) - Preserve multiselect filter values when updating per-page count for list views
* [#3112](https://github.com/digitalocean/netbox/issues/3112) - Fix ordering of interface connections list by termination B name/device
* [#3116](https://github.com/digitalocean/netbox/issues/3116) - Fix `tagged_items` count in tags API endpoint
* [#3118](https://github.com/digitalocean/netbox/issues/3118) - Disable `last_login` update on login when maintenance mode is enabled
---
v2.5.10 (2019-04-08)
## Enhancements
* [#3052](https://github.com/digitalocean/netbox/issues/3052) - Add Jinja2 support for export templates
## Bug Fixes
* [#2937](https://github.com/digitalocean/netbox/issues/2937) - Redirect to list view after editing an object from list view
* [#3036](https://github.com/digitalocean/netbox/issues/3036) - DCIM interfaces API endpoint should not include VM interfaces
* [#3039](https://github.com/digitalocean/netbox/issues/3039) - Fix exception when retrieving change object for a component template via API
* [#3041](https://github.com/digitalocean/netbox/issues/3041) - Fix form widget for bulk cable label update
* [#3044](https://github.com/digitalocean/netbox/issues/3044) - Ignore site/rack fields when connecting a new cable via device search
* [#3046](https://github.com/digitalocean/netbox/issues/3046) - Fix exception at reports API endpoint
* [#3047](https://github.com/digitalocean/netbox/issues/3047) - Fix exception when writing mac address for an interface via API
---
v2.5.9 (2019-04-01)
## Enhancements
* [#2933](https://github.com/digitalocean/netbox/issues/2933) - Add username to outbound webhook requests
* [#3011](https://github.com/digitalocean/netbox/issues/3011) - Add SSL support for django-rq (requires django-rq v1.3.1+)
* [#3025](https://github.com/digitalocean/netbox/issues/3025) - Add request ID to outbound webhook requests (for correlating all changes part of a single request)
## Bug Fixes
* [#2207](https://github.com/digitalocean/netbox/issues/2207) - Fixes deterministic ordering of interfaces
* [#2577](https://github.com/digitalocean/netbox/issues/2577) - Clarification of wording in API regarding filtering
* [#2924](https://github.com/digitalocean/netbox/issues/2924) - Add interface type for QSFP28 50GE
* [#2936](https://github.com/digitalocean/netbox/issues/2936) - Fix device role selection showing duplicate first entry
* [#2998](https://github.com/digitalocean/netbox/issues/2998) - Limit device query to non-racked devices if no rack selected when creating a cable
* [#3001](https://github.com/digitalocean/netbox/issues/3001) - Fix API representation of ObjectChange `action` and add `changed_object_type`
* [#3014](https://github.com/digitalocean/netbox/issues/3014) - Fixes VM Role filtering
* [#3019](https://github.com/digitalocean/netbox/issues/3019) - Fix tag population when running NetBox within a path
* [#3022](https://github.com/digitalocean/netbox/issues/3022) - Add missing cable termination types to DCIM `_choices` endpoint
* [#3026](https://github.com/digitalocean/netbox/issues/3026) - Tweak prefix/IP filter forms to filter using VRF ID rather than route distinguisher
* [#3027](https://github.com/digitalocean/netbox/issues/3027) - Ignore empty local context data when rendering config contexts
* [#3032](https://github.com/digitalocean/netbox/issues/3032) - Save assigned tags when creating a new secret
---
v2.5.8 (2019-03-11)
## Enhancements

View File

@@ -45,13 +45,13 @@ and run `upgrade.sh`.
## Supported SDK
- [pynetbox](https://github.com/digitalocean/pynetbox) Python API client library for Netbox.
- [pynetbox](https://github.com/digitalocean/pynetbox) - A Python API client library for Netbox
## Community SDK
- [netbox-client-ruby](https://github.com/ninech/netbox-client-ruby) A ruby client library for Netbox v2.
- [netbox-client-ruby](https://github.com/ninech/netbox-client-ruby) - A Ruby client library for Netbox
- [powerbox](https://github.com/BatmanAMA/powerbox) - A PowerShell library for Netbox
## Ansible Inventory
- [netbox-as-ansible-inventory](https://github.com/AAbouZaid/netbox-as-ansible-inventory) Ansible dynamic inventory script for Netbox.
- [netbox-as-ansible-inventory](https://github.com/AAbouZaid/netbox-as-ansible-inventory) - Ansible dynamic inventory script for Netbox

View File

@@ -261,7 +261,7 @@ A list of objects retrieved via the API can be filtered by passing one or more q
GET /api/ipam/prefixes/?status=1
```
The same filter can be incldued multiple times. These will effect a logical OR and return objects matching any of the given values. For example, the following will return all active and reserved prefixes:
Certain filters can be included multiple times within a single request. These will effect a logical OR and return objects matching any of the given values. For example, the following will return all active and reserved prefixes:
```
GET /api/ipam/prefixes/?status=1&status=2

View File

@@ -283,6 +283,7 @@ REDIS = {
'PASSWORD': '',
'DATABASE': 0,
'DEFAULT_TIMEOUT': 300,
'SSL': False,
}
```
@@ -315,3 +316,9 @@ The TCP port to use when connecting to the Redis server.
Default: None
The password to use when authenticating to the Redis server (optional).
### SSL
Default: False
Use secure sockets layer to encrypt the connections to the Redis server.

View File

@@ -11,7 +11,7 @@ CIRCUITTYPE_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.circuit.change_circuittype %}
<a href="{% url 'circuits:circuittype_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'circuits:circuittype_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""

View File

@@ -1,3 +1,4 @@
from django.contrib.contenttypes.models import ContentType
from rest_framework import serializers
from rest_framework.validators import UniqueTogetherValidator
from taggit_serializer.serializers import TaggitSerializer, TagListSerializerField
@@ -502,8 +503,12 @@ class InventoryItemSerializer(TaggitSerializer, ValidatedModelSerializer):
#
class CableSerializer(ValidatedModelSerializer):
termination_a_type = ContentTypeField()
termination_b_type = ContentTypeField()
termination_a_type = ContentTypeField(
queryset=ContentType.objects.filter(model__in=CABLE_TERMINATION_TYPES)
)
termination_b_type = ContentTypeField(
queryset=ContentType.objects.filter(model__in=CABLE_TERMINATION_TYPES)
)
termination_a = serializers.SerializerMethodField(read_only=True)
termination_b = serializers.SerializerMethodField(read_only=True)
status = ChoiceField(choices=CONNECTION_STATUS_CHOICES, required=False)

View File

@@ -1,7 +1,7 @@
from collections import OrderedDict
from django.conf import settings
from django.db.models import F, Q
from django.db.models import F
from django.http import HttpResponseForbidden
from django.shortcuts import get_object_or_404
from drf_yasg import openapi
@@ -35,7 +35,7 @@ from .exceptions import MissingFilterException
class DCIMFieldChoicesViewSet(FieldChoicesViewSet):
fields = (
(Cable, ['length_unit', 'status', 'type']),
(Cable, ['length_unit', 'status', 'termination_a_type', 'termination_b_type', 'type']),
(ConsolePort, ['connection_status']),
(Device, ['face', 'status']),
(DeviceType, ['subdevice_role']),
@@ -419,7 +419,9 @@ class PowerOutletViewSet(CableTraceMixin, ModelViewSet):
class InterfaceViewSet(CableTraceMixin, ModelViewSet):
queryset = Interface.objects.select_related(
queryset = Interface.objects.filter(
device__isnull=False
).select_related(
'device', '_connected_interface', '_connected_circuittermination', 'cable'
).prefetch_related(
'ip_addresses', 'tags'

View File

@@ -83,6 +83,7 @@ IFACE_FF_10GE_XENPAK = 1310
IFACE_FF_10GE_X2 = 1320
IFACE_FF_25GE_SFP28 = 1350
IFACE_FF_40GE_QSFP_PLUS = 1400
IFACE_FF_50GE_QSFP28 = 1420
IFACE_FF_100GE_CFP = 1500
IFACE_FF_100GE_CFP2 = 1510
IFACE_FF_100GE_CFP4 = 1520
@@ -164,6 +165,7 @@ IFACE_FF_CHOICES = [
[IFACE_FF_10GE_X2, 'X2 (10GE)'],
[IFACE_FF_25GE_SFP28, 'SFP28 (25GE)'],
[IFACE_FF_40GE_QSFP_PLUS, 'QSFP+ (40GE)'],
[IFACE_FF_50GE_QSFP28, 'QSFP28 (50GE)'],
[IFACE_FF_100GE_CFP, 'CFP (100GE)'],
[IFACE_FF_100GE_CFP2, 'CFP2 (100GE)'],
[IFACE_FF_200GE_CFP2, 'CFP2 (200GE)'],
@@ -316,6 +318,7 @@ DEVICE_STATUS_PLANNED = 2
DEVICE_STATUS_STAGED = 3
DEVICE_STATUS_FAILED = 4
DEVICE_STATUS_INVENTORY = 5
DEVICE_STATUS_DECOMMISSIONING = 6
DEVICE_STATUS_CHOICES = [
[DEVICE_STATUS_ACTIVE, 'Active'],
[DEVICE_STATUS_OFFLINE, 'Offline'],
@@ -323,6 +326,7 @@ DEVICE_STATUS_CHOICES = [
[DEVICE_STATUS_STAGED, 'Staged'],
[DEVICE_STATUS_FAILED, 'Failed'],
[DEVICE_STATUS_INVENTORY, 'Inventory'],
[DEVICE_STATUS_DECOMMISSIONING, 'Decommissioning'],
]
# Site statuses
@@ -343,6 +347,7 @@ STATUS_CLASSES = {
3: 'primary',
4: 'danger',
5: 'default',
6: 'warning',
}
# Console/power/interface connection statuses

View File

@@ -31,7 +31,7 @@ class MACAddressField(models.Field):
try:
return EUI(value, version=48, dialect=mac_unix_expanded_uppercase)
except AddrFormatError as e:
raise ValidationError(e)
raise ValidationError("Invalid MAC address format: {}".format(value))
def db_type(self, connection):
return 'macaddr'

View File

@@ -1,5 +1,7 @@
import django_filters
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q
from netaddr import EUI
from netaddr.core import AddrFormatError
@@ -967,6 +969,14 @@ class CableFilter(django_filters.FilterSet):
color = django_filters.MultipleChoiceFilter(
choices=COLOR_CHOICES
)
device = django_filters.CharFilter(
method='filter_connected_device',
field_name='name'
)
device_id = django_filters.CharFilter(
method='filter_connected_device',
field_name='pk'
)
class Meta:
model = Cable
@@ -977,6 +987,16 @@ class CableFilter(django_filters.FilterSet):
return queryset
return queryset.filter(label__icontains=value)
def filter_connected_device(self, queryset, name, value):
if not value.strip():
return queryset
try:
device = Device.objects.get(**{name: value})
except ObjectDoesNotExist:
return queryset.none()
cable_pks = device.get_cables(pk_list=True)
return queryset.filter(pk__in=cable_pks)
class ConsoleConnectionFilter(django_filters.FilterSet):
site = django_filters.CharFilter(

View File

@@ -1700,7 +1700,6 @@ class DeviceFilterForm(BootstrapMixin, CustomFieldFilterForm):
widget=APISelectMultiple(
api_url="/api/dcim/device-roles/",
value_field="slug",
null_option=True,
)
)
tenant = FilterChoiceField(
@@ -2707,12 +2706,12 @@ class CableBulkEditForm(BootstrapMixin, BulkEditForm):
status = forms.ChoiceField(
choices=add_blank_choice(CONNECTION_STATUS_CHOICES),
required=False,
widget=StaticSelect2(),
initial=''
)
label = forms.CharField(
max_length=100,
required=False,
widget=StaticSelect2()
required=False
)
color = forms.CharField(
max_length=6,
@@ -2767,6 +2766,10 @@ class CableFilterForm(BootstrapMixin, forms.Form):
required=False,
widget=ColorSelect()
)
device = forms.CharField(
required=False,
label='Device name'
)
#

View File

@@ -14,22 +14,6 @@ CHANNEL_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^.*:(\d{{1,9}})(\.\d{{1,9}})?$')
VC_RE = r"COALESCE(CAST(SUBSTRING({} FROM '^.*\.(\d{{1,9}})$') AS integer), 0)"
class DeviceComponentManager(Manager):
def get_queryset(self):
queryset = super().get_queryset()
table_name = self.model._meta.db_table
sql = r"CONCAT(REGEXP_REPLACE({}.name, '\d+$', ''), LPAD(SUBSTRING({}.name FROM '\d+$'), 8, '0'))"
# Pad any trailing digits to effect natural sorting
return queryset.extra(
select={
'name_padded': sql.format(table_name, table_name),
}
).order_by('name_padded', 'pk')
class InterfaceQuerySet(QuerySet):
def connectable(self):
@@ -64,11 +48,15 @@ class InterfaceManager(Manager):
The original `name` field is considered in its entirety to serve as a fallback in the event interfaces do not
match any of the prescribed fields.
The `id` field is included to enforce deterministic ordering of interfaces in similar vein of other device
components.
"""
sql_col = '{}.name'.format(self.model._meta.db_table)
ordering = [
'_slot', '_subslot', '_position', '_subposition', '_type', '_id', '_channel', '_vc', 'name',
'_slot', '_subslot', '_position', '_subposition', '_type', '_id', '_channel', '_vc', 'name', 'pk'
]
fields = {

View File

@@ -23,7 +23,7 @@ from utilities.utils import serialize_object, to_meters
from .constants import *
from .exceptions import LoopDetected
from .fields import ASNField, MACAddressField
from .managers import DeviceComponentManager, InterfaceManager
from .managers import InterfaceManager
class ComponentTemplateModel(models.Model):
@@ -1004,7 +1004,7 @@ class ConsolePortTemplate(ComponentTemplateModel):
max_length=50
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
class Meta:
ordering = ['device_type', 'name']
@@ -1027,7 +1027,7 @@ class ConsoleServerPortTemplate(ComponentTemplateModel):
max_length=50
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
class Meta:
ordering = ['device_type', 'name']
@@ -1050,7 +1050,7 @@ class PowerPortTemplate(ComponentTemplateModel):
max_length=50
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
class Meta:
ordering = ['device_type', 'name']
@@ -1073,7 +1073,7 @@ class PowerOutletTemplate(ComponentTemplateModel):
max_length=50
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
class Meta:
ordering = ['device_type', 'name']
@@ -1139,7 +1139,7 @@ class FrontPortTemplate(ComponentTemplateModel):
validators=[MinValueValidator(1), MaxValueValidator(64)]
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
class Meta:
ordering = ['device_type', 'name']
@@ -1188,7 +1188,7 @@ class RearPortTemplate(ComponentTemplateModel):
validators=[MinValueValidator(1), MaxValueValidator(64)]
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
class Meta:
ordering = ['device_type', 'name']
@@ -1211,7 +1211,7 @@ class DeviceBayTemplate(ComponentTemplateModel):
max_length=50
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
class Meta:
ordering = ['device_type', 'name']
@@ -1704,6 +1704,21 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
filter |= Q(device__virtual_chassis=self.virtual_chassis, mgmt_only=False)
return Interface.objects.filter(filter)
def get_cables(self, pk_list=False):
"""
Return a QuerySet or PK list matching all Cables connected to a component of this Device.
"""
cable_pks = []
for component_model in [
ConsolePort, ConsoleServerPort, PowerPort, PowerOutlet, Interface, FrontPort, RearPort
]:
cable_pks += component_model.objects.filter(
device=self, cable__isnull=False
).values_list('cable', flat=True)
if pk_list:
return cable_pks
return Cable.objects.filter(pk__in=cable_pks)
def get_children(self):
"""
Return the set of child Devices installed in DeviceBays within this Device.
@@ -1742,7 +1757,7 @@ class ConsolePort(CableTermination, ComponentModel):
blank=True
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager()
csv_headers = ['device', 'name']
@@ -1785,7 +1800,7 @@ class ConsoleServerPort(CableTermination, ComponentModel):
blank=True
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager()
csv_headers = ['device', 'name']
@@ -1834,7 +1849,7 @@ class PowerPort(CableTermination, ComponentModel):
blank=True
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager()
csv_headers = ['device', 'name']
@@ -1877,7 +1892,7 @@ class PowerOutlet(CableTermination, ComponentModel):
blank=True
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager()
csv_headers = ['device', 'name']
@@ -2198,7 +2213,7 @@ class FrontPort(CableTermination, ComponentModel):
blank=True
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager()
csv_headers = ['device', 'name', 'type', 'rear_port', 'rear_port_position', 'description']
@@ -2264,7 +2279,7 @@ class RearPort(CableTermination, ComponentModel):
blank=True
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager()
csv_headers = ['device', 'name', 'type', 'positions', 'description']
@@ -2311,7 +2326,7 @@ class DeviceBay(ComponentModel):
null=True
)
objects = DeviceComponentManager()
objects = NaturalOrderingManager()
tags = TaggableManager()
csv_headers = ['device', 'name', 'installed_device']

View File

@@ -44,7 +44,7 @@ REGION_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.dcim.change_region %}
<a href="{% url 'dcim:region_edit' pk=record.pk %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'dcim:region_edit' pk=record.pk %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
@@ -56,7 +56,7 @@ RACKGROUP_ACTIONS = """
<i class="fa fa-eye"></i>
</a>
{% if perms.dcim.change_rackgroup %}
<a href="{% url 'dcim:rackgroup_edit' pk=record.pk %}" class="btn btn-xs btn-warning" title="Edit">
<a href="{% url 'dcim:rackgroup_edit' pk=record.pk %}?return_url={{ request.path }}" class="btn btn-xs btn-warning" title="Edit">
<i class="glyphicon glyphicon-pencil"></i>
</a>
{% endif %}
@@ -67,7 +67,7 @@ RACKROLE_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.dcim.change_rackrole %}
<a href="{% url 'dcim:rackrole_edit' pk=record.pk %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'dcim:rackrole_edit' pk=record.pk %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
@@ -88,7 +88,7 @@ RACKRESERVATION_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.dcim.change_rackreservation %}
<a href="{% url 'dcim:rackreservation_edit' pk=record.pk %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'dcim:rackreservation_edit' pk=record.pk %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
@@ -97,7 +97,7 @@ MANUFACTURER_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.dcim.change_manufacturer %}
<a href="{% url 'dcim:manufacturer_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'dcim:manufacturer_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
@@ -106,7 +106,7 @@ DEVICEROLE_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.dcim.change_devicerole %}
<a href="{% url 'dcim:devicerole_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'dcim:devicerole_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
@@ -131,7 +131,7 @@ PLATFORM_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.dcim.change_platform %}
<a href="{% url 'dcim:platform_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'dcim:platform_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
@@ -168,7 +168,7 @@ VIRTUALCHASSIS_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.dcim.change_virtualchassis %}
<a href="{% url 'dcim:virtualchassis_edit' pk=record.pk %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'dcim:virtualchassis_edit' pk=record.pk %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
@@ -733,18 +733,18 @@ class InterfaceConnectionTable(BaseTable):
)
device_b = tables.LinkColumn(
viewname='dcim:device',
accessor=Accessor('connected_endpoint.device'),
args=[Accessor('connected_endpoint.device.pk')],
accessor=Accessor('_connected_interface.device'),
args=[Accessor('_connected_interface.device.pk')],
verbose_name='Device B'
)
interface_b = tables.LinkColumn(
viewname='dcim:interface',
accessor=Accessor('connected_endpoint.name'),
args=[Accessor('connected_endpoint.pk')],
accessor=Accessor('_connected_interface'),
args=[Accessor('_connected_interface.pk')],
verbose_name='Interface B'
)
description_b = tables.Column(
accessor=Accessor('connected_endpoint.description'),
accessor=Accessor('_connected_interface.description'),
verbose_name='Description'
)

View File

@@ -1,3 +1,4 @@
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from rest_framework import serializers
from taggit.models import Tag
@@ -15,7 +16,8 @@ from tenancy.api.nested_serializers import NestedTenantSerializer, NestedTenantG
from tenancy.models import Tenant, TenantGroup
from users.api.nested_serializers import NestedUserSerializer
from utilities.api import (
ChoiceField, ContentTypeField, get_serializer_for_model, SerializedPKRelatedField, ValidatedModelSerializer,
ChoiceField, ContentTypeField, get_serializer_for_model, SerializerNotFound, SerializedPKRelatedField,
ValidatedModelSerializer,
)
from .nested_serializers import *
@@ -53,10 +55,17 @@ class RenderedGraphSerializer(serializers.ModelSerializer):
#
class ExportTemplateSerializer(ValidatedModelSerializer):
template_language = ChoiceField(
choices=TEMPLATE_LANGUAGE_CHOICES,
default=TEMPLATE_LANGUAGE_JINJA2
)
class Meta:
model = ExportTemplate
fields = ['id', 'content_type', 'name', 'description', 'template_code', 'mime_type', 'file_extension']
fields = [
'id', 'content_type', 'name', 'description', 'template_language', 'template_code', 'mime_type',
'file_extension',
]
#
@@ -88,7 +97,9 @@ class TagSerializer(ValidatedModelSerializer):
#
class ImageAttachmentSerializer(ValidatedModelSerializer):
content_type = ContentTypeField()
content_type = ContentTypeField(
queryset=ContentType.objects.all()
)
parent = serializers.SerializerMethodField(read_only=True)
class Meta:
@@ -205,14 +216,25 @@ class ReportDetailSerializer(ReportSerializer):
#
class ObjectChangeSerializer(serializers.ModelSerializer):
user = NestedUserSerializer(read_only=True)
content_type = ContentTypeField(read_only=True)
changed_object = serializers.SerializerMethodField(read_only=True)
user = NestedUserSerializer(
read_only=True
)
action = ChoiceField(
choices=OBJECTCHANGE_ACTION_CHOICES,
read_only=True
)
changed_object_type = ContentTypeField(
read_only=True
)
changed_object = serializers.SerializerMethodField(
read_only=True
)
class Meta:
model = ObjectChange
fields = [
'id', 'time', 'user', 'user_name', 'request_id', 'action', 'content_type', 'changed_object', 'object_data',
'id', 'time', 'user', 'user_name', 'request_id', 'action', 'changed_object_type', 'changed_object',
'object_data',
]
def get_changed_object(self, obj):
@@ -221,9 +243,14 @@ class ObjectChangeSerializer(serializers.ModelSerializer):
"""
if obj.changed_object is None:
return None
serializer = get_serializer_for_model(obj.changed_object, prefix='Nested')
if serializer is None:
try:
serializer = get_serializer_for_model(obj.changed_object, prefix='Nested')
except SerializerNotFound:
return obj.object_repr
context = {'request': self.context['request']}
context = {
'request': self.context['request']
}
data = serializer(obj.changed_object, context=context).data
return data

View File

@@ -10,7 +10,7 @@ from taggit.models import Tag
from extras import filters
from extras.models import (
ConfigContext, CustomField, ExportTemplate, Graph, ImageAttachment, ObjectChange, ReportResult, TopologyMap,
ConfigContext, ExportTemplate, Graph, ImageAttachment, ObjectChange, ReportResult, TopologyMap,
)
from extras.reports import get_report, get_reports
from utilities.api import FieldChoicesViewSet, IsAuthenticatedOrLoginNotRequired, ModelViewSet
@@ -23,8 +23,9 @@ from . import serializers
class ExtrasFieldChoicesViewSet(FieldChoicesViewSet):
fields = (
(CustomField, ['type']),
(ExportTemplate, ['template_language']),
(Graph, ['type']),
(ObjectChange, ['action']),
)
@@ -115,7 +116,9 @@ class TopologyMapViewSet(ModelViewSet):
#
class TagViewSet(ModelViewSet):
queryset = Tag.objects.annotate(tagged_items=Count('taggit_taggeditem_items'))
queryset = Tag.objects.annotate(
tagged_items=Count('taggit_taggeditem_items', distinct=True)
)
serializer_class = serializers.TagSerializer
filterset_class = filters.TagFilter

View File

@@ -22,6 +22,7 @@ class ExtrasConfig(AppConfig):
port=settings.REDIS_PORT,
db=settings.REDIS_DATABASE,
password=settings.REDIS_PASSWORD or None,
ssl=settings.REDIS_SSL,
)
rs.ping()
except redis.exceptions.ConnectionError:

View File

@@ -56,6 +56,14 @@ EXPORTTEMPLATE_MODELS = [
'cluster', 'virtualmachine', # Virtualization
]
# ExportTemplate language choices
TEMPLATE_LANGUAGE_DJANGO = 10
TEMPLATE_LANGUAGE_JINJA2 = 20
TEMPLATE_LANGUAGE_CHOICES = (
(TEMPLATE_LANGUAGE_DJANGO, 'Django'),
(TEMPLATE_LANGUAGE_JINJA2, 'Jinja2'),
)
# Topology map types
TOPOLOGYMAP_TYPE_NETWORK = 1
TOPOLOGYMAP_TYPE_CONSOLE = 2

View File

@@ -82,7 +82,7 @@ class ExportTemplateFilter(django_filters.FilterSet):
class Meta:
model = ExportTemplate
fields = ['content_type', 'name']
fields = ['content_type', 'name', 'template_language']
class TagFilter(django_filters.FilterSet):

View File

@@ -4,7 +4,6 @@ from django import forms
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from mptt.forms import TreeNodeMultipleChoiceField
from taggit.forms import TagField
from taggit.models import Tag
@@ -12,7 +11,7 @@ from dcim.models import DeviceRole, Platform, Region, Site
from tenancy.models import Tenant, TenantGroup
from utilities.forms import (
add_blank_choice, APISelectMultiple, BootstrapMixin, BulkEditForm, BulkEditNullBooleanSelect, ContentTypeSelect,
FilterChoiceField, FilterTreeNodeMultipleChoiceField, LaxURLField, JSONField, SlugField,
FilterChoiceField, LaxURLField, JSONField, SlugField,
)
from .constants import (
CF_FILTER_DISABLED, CF_TYPE_BOOLEAN, CF_TYPE_DATE, CF_TYPE_INTEGER, CF_TYPE_SELECT, CF_TYPE_URL,

View File

@@ -37,7 +37,7 @@ def _record_object_deleted(request, instance, **kwargs):
if hasattr(instance, 'log_change'):
instance.log_change(request.user, request.id, OBJECTCHANGE_ACTION_DELETE)
enqueue_webhooks(instance, OBJECTCHANGE_ACTION_DELETE)
enqueue_webhooks(instance, request.user, request.id, OBJECTCHANGE_ACTION_DELETE)
class ObjectChangeMiddleware(object):
@@ -83,7 +83,7 @@ class ObjectChangeMiddleware(object):
obj.log_change(request.user, request.id, action)
# Enqueue webhooks
enqueue_webhooks(obj, action)
enqueue_webhooks(obj, request.user, request.id, action)
# Housekeeping: 1% chance of clearing out expired ObjectChanges
if _thread_locals.changed_objects and settings.CHANGELOG_RETENTION and random.randint(1, 100) == 1:

View File

@@ -0,0 +1,27 @@
# Generated by Django 2.1.7 on 2019-04-08 14:49
from django.db import migrations, models
def set_template_language(apps, schema_editor):
"""
Set the language for all existing ExportTemplates to Django (Jinja2 is the default for new ExportTemplates).
"""
ExportTemplate = apps.get_model('extras', 'ExportTemplate')
ExportTemplate.objects.update(template_language=10)
class Migration(migrations.Migration):
dependencies = [
('extras', '0017_exporttemplate_mime_type_length'),
]
operations = [
migrations.AddField(
model_name='exporttemplate',
name='template_language',
field=models.PositiveSmallIntegerField(default=20),
),
migrations.RunPython(set_template_language),
]

View File

@@ -1,7 +1,6 @@
from collections import OrderedDict
from datetime import date
import graphviz
from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
@@ -12,6 +11,8 @@ from django.db.models import F, Q
from django.http import HttpResponse
from django.template import Template, Context
from django.urls import reverse
import graphviz
from jinja2 import Environment
from dcim.constants import CONNECTION_STATUS_CONNECTED
from utilities.utils import deepmerge, foreground_color
@@ -355,6 +356,10 @@ class ExportTemplate(models.Model):
max_length=200,
blank=True
)
template_language = models.PositiveSmallIntegerField(
choices=TEMPLATE_LANGUAGE_CHOICES,
default=TEMPLATE_LANGUAGE_JINJA2
)
template_code = models.TextField()
mime_type = models.CharField(
max_length=50,
@@ -374,16 +379,36 @@ class ExportTemplate(models.Model):
def __str__(self):
return '{}: {}'.format(self.content_type, self.name)
def render(self, queryset):
"""
Render the contents of the template.
"""
context = {
'queryset': queryset
}
if self.template_language == TEMPLATE_LANGUAGE_DJANGO:
template = Template(self.template_code)
output = template.render(Context(context))
elif self.template_language == TEMPLATE_LANGUAGE_JINJA2:
template = Environment().from_string(source=self.template_code)
output = template.render(**context)
else:
return None
# Replace CRLF-style line terminators
output = output.replace('\r\n', '\n')
return output
def render_to_response(self, queryset):
"""
Render the template to an HTTP response, delivered as a named file attachment
"""
template = Template(self.template_code)
output = self.render(queryset)
mime_type = 'text/plain' if not self.mime_type else self.mime_type
output = template.render(Context({'queryset': queryset}))
# Replace CRLF-style line terminators
output = output.replace('\r\n', '\n')
# Build the response
response = HttpResponse(output, content_type=mime_type)
@@ -720,7 +745,7 @@ class ConfigContextModel(models.Model):
data = deepmerge(data, context.data)
# If the object has local config context data defined, merge it last
if self.local_context_data is not None:
if self.local_context_data:
data = deepmerge(data, self.local_context_data)
return data

View File

@@ -30,7 +30,7 @@ from .tables import ConfigContextTable, ObjectChangeTable, TagTable, TaggedItemT
class TagListView(ObjectListView):
queryset = Tag.objects.annotate(
items=Count('taggit_taggeditem_items')
items=Count('taggit_taggeditem_items', distinct=True)
).order_by(
'name'
)

View File

@@ -9,7 +9,7 @@ from utilities.api import get_serializer_for_model
from .constants import WEBHOOK_MODELS
def enqueue_webhooks(instance, action):
def enqueue_webhooks(instance, user, request_id, action):
"""
Find Webhook(s) assigned to this instance + action and enqueue them
to be processed
@@ -47,5 +47,7 @@ def enqueue_webhooks(instance, action):
serializer.data,
instance._meta.model_name,
action,
str(datetime.datetime.now())
str(datetime.datetime.now()),
user.username,
request_id
)

View File

@@ -10,7 +10,7 @@ from extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED, OBJ
@job('default')
def process_webhook(webhook, data, model_name, event, timestamp):
def process_webhook(webhook, data, model_name, event, timestamp, username, request_id):
"""
Make a POST request to the defined Webhook
"""
@@ -18,6 +18,8 @@ def process_webhook(webhook, data, model_name, event, timestamp):
'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event].lower(),
'timestamp': timestamp,
'model': model_name,
'username': username,
'request_id': request_id,
'data': data
}
headers = {

View File

@@ -128,6 +128,7 @@ class VLANSerializer(TaggitSerializer, CustomFieldModelSerializer):
#
class PrefixSerializer(TaggitSerializer, CustomFieldModelSerializer):
family = ChoiceField(choices=AF_CHOICES, read_only=True)
site = NestedSiteSerializer(required=False, allow_null=True)
vrf = NestedVRFSerializer(required=False, allow_null=True)
tenant = NestedTenantSerializer(required=False, allow_null=True)
@@ -189,6 +190,7 @@ class IPAddressInterfaceSerializer(WritableNestedSerializer):
class IPAddressSerializer(TaggitSerializer, CustomFieldModelSerializer):
family = ChoiceField(choices=AF_CHOICES, read_only=True)
vrf = NestedVRFSerializer(required=False, allow_null=True)
tenant = NestedTenantSerializer(required=False, allow_null=True)
status = ChoiceField(choices=IPADDRESS_STATUS_CHOICES, required=False)

View File

@@ -524,14 +524,12 @@ class PrefixFilterForm(BootstrapMixin, CustomFieldFilterForm):
label='Mask length',
widget=StaticSelect2()
)
vrf = FilterChoiceField(
vrf_id = FilterChoiceField(
queryset=VRF.objects.all(),
to_field_name='rd',
label='VRF',
null_label='-- Global --',
widget=APISelectMultiple(
api_url="/api/ipam/vrfs/",
value_field="rd",
null_option=True,
)
)
@@ -973,14 +971,12 @@ class IPAddressFilterForm(BootstrapMixin, CustomFieldFilterForm):
label='Mask length',
widget=StaticSelect2()
)
vrf = FilterChoiceField(
vrf_id = FilterChoiceField(
queryset=VRF.objects.all(),
to_field_name='rd',
label='VRF',
null_label='-- Global --',
widget=APISelectMultiple(
api_url="/api/ipam/vrfs/",
value_field="rd",
null_option=True,
)
)

View File

@@ -30,7 +30,7 @@ RIR_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.ipam.change_rir %}
<a href="{% url 'ipam:rir_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'ipam:rir_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
@@ -52,7 +52,7 @@ ROLE_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.ipam.change_role %}
<a href="{% url 'ipam:role_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'ipam:role_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
@@ -152,7 +152,7 @@ VLANGROUP_ACTIONS = """
{% endif %}
{% endwith %}
{% if perms.ipam.change_vlangroup %}
<a href="{% url 'ipam:vlangroup_edit' pk=record.pk %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'ipam:vlangroup_edit' pk=record.pk %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""

View File

@@ -147,18 +147,18 @@ class OptionalLimitOffsetPagination(LimitOffsetPagination):
# Miscellaneous
#
def get_view_name(view_cls, suffix=None):
def get_view_name(view, suffix=None):
"""
Derive the view name from its associated model, if it has one. Fall back to DRF's built-in `get_view_name`.
"""
if hasattr(view_cls, 'queryset'):
if hasattr(view, 'queryset'):
# Determine the model name from the queryset.
name = view_cls.queryset.model._meta.verbose_name
name = view.queryset.model._meta.verbose_name
name = ' '.join([w[0].upper() + w[1:] for w in name.split()]) # Capitalize each word
else:
# Replicate DRF's built-in behavior.
name = view_cls.__name__
name = view.__class__.__name__
name = formatting.remove_trailing_string(name, 'View')
name = formatting.remove_trailing_string(name, 'ViewSet')
name = formatting.camelcase_to_spaces(name)

View File

@@ -132,6 +132,7 @@ REDIS = {
'PASSWORD': '',
'DATABASE': 0,
'DEFAULT_TIMEOUT': 300,
'SSL': False,
}
# The file path where custom reports will be stored. A trailing slash is not needed. Note that the default value of

View File

@@ -22,7 +22,7 @@ except ImportError:
)
VERSION = '2.5.8'
VERSION = '2.5.11'
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -131,6 +131,7 @@ REDIS_PORT = REDIS.get('PORT', 6379)
REDIS_PASSWORD = REDIS.get('PASSWORD', '')
REDIS_DATABASE = REDIS.get('DATABASE', 0)
REDIS_DEFAULT_TIMEOUT = REDIS.get('DEFAULT_TIMEOUT', 300)
REDIS_SSL = REDIS.get('SSL', False)
# Email
EMAIL_HOST = EMAIL.get('SERVER')
@@ -291,6 +292,7 @@ RQ_QUEUES = {
'DB': REDIS_DATABASE,
'PASSWORD': REDIS_PASSWORD,
'DEFAULT_TIMEOUT': REDIS_DEFAULT_TIMEOUT,
'SSL': REDIS_SSL,
}
}

View File

@@ -155,10 +155,14 @@ $(document).ready(function() {
filter_for_elements.each(function(index, filter_for_element) {
var param_name = $(filter_for_element).attr(attr_name);
var is_nullable = $(filter_for_element).attr("nullable");
var is_visible = $(filter_for_element).is(":visible");
var value = $(filter_for_element).val();
if (param_name && value) {
if (param_name && is_visible && value) {
parameters[param_name] = value;
} else if (param_name && is_visible && is_nullable) {
parameters[param_name] = "null";
}
});
@@ -247,7 +251,7 @@ $(document).ready(function() {
ajax: {
delay: 250,
url: "/api/extras/tags/",
url: netbox_api_path + "extras/tags/",
data: function(params) {
// Paging. Note that `params.page` indexes at 1

View File

@@ -8,7 +8,7 @@ SECRETROLE_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.secrets.change_secretrole %}
<a href="{% url 'secrets:secretrole_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'secrets:secretrole_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""

View File

@@ -120,6 +120,8 @@ def secret_add(request, pk):
secret.plaintext = str(form.cleaned_data['plaintext'])
secret.encrypt(master_key)
secret.save()
form.save_m2m()
messages.success(request, "Added new secret: {}.".format(secret))
if '_addanother' in request.POST:
return redirect('dcim:device_addsecret', pk=device.pk)

View File

@@ -20,9 +20,11 @@
</ul>
</nav>
<form method="get">
{% for k, v in request.GET.items %}
{% for k, v_list in request.GET.lists %}
{% if k != 'per_page' %}
<input type="hidden" name="{{ k }}" value="{{ v }}" />
{% for v in v_list %}
<input type="hidden" name="{{ k }}" value="{{ v }}" />
{% endfor %}
{% endif %}
{% endfor %}
<select name="per_page" id="per_page">

View File

@@ -59,7 +59,7 @@
{% block content %}
<div class="row">
<div class="col-md-6">
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<strong>VLAN</strong>
@@ -136,7 +136,7 @@
{% include 'inc/custom_fields_panel.html' with obj=vlan %}
{% include 'extras/inc/tags_panel.html' with tags=vlan.tags.all url='ipam:vlan_list' %}
</div>
<div class="col-md-6">
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Prefixes</strong>

View File

@@ -8,7 +8,7 @@ TENANTGROUP_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.tenancy.change_tenantgroup %}
<a href="{% url 'tenancy:tenantgroup_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'tenancy:tenantgroup_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""

View File

@@ -1,7 +1,10 @@
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import login as auth_login, logout as auth_logout, update_session_auth_hash
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.contrib.auth.models import update_last_login
from django.contrib.auth.signals import user_logged_in
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
@@ -44,6 +47,11 @@ class LoginView(View):
if not is_safe_url(url=redirect_to, allowed_hosts=request.get_host()):
redirect_to = reverse('home')
# If maintenance mode is enabled, assume the database is read-only, and disable updating the user's
# last_login time upon authentication.
if settings.MAINTENANCE_MODE:
user_logged_in.disconnect(update_last_login, dispatch_uid='update_last_login')
# Authenticate user
auth_login(request, form.get_user())
messages.info(request, "Logged in as {}.".format(request.user))

View File

@@ -21,6 +21,10 @@ class ServiceUnavailable(APIException):
default_detail = "Service temporarily unavailable, please try again later."
class SerializerNotFound(Exception):
pass
def get_serializer_for_model(model, prefix=''):
"""
Dynamically resolve and return the appropriate serializer for a model.
@@ -32,7 +36,9 @@ def get_serializer_for_model(model, prefix=''):
try:
return dynamic_import(serializer_name)
except AttributeError:
return None
raise SerializerNotFound(
"Could not determine serializer for {}.{} with prefix '{}'".format(app_name, model_name, prefix)
)
#
@@ -100,6 +106,10 @@ class ChoiceField(Field):
return data
@property
def choices(self):
return self._choices
class ContentTypeField(RelatedField):
"""
@@ -110,10 +120,6 @@ class ContentTypeField(RelatedField):
"invalid": "Invalid value. Specify a content type as '<app_label>.<model_name>'.",
}
# Can't set this as an attribute because it raises an exception when the field is read-only
def get_queryset(self):
return ContentType.objects.all()
def to_internal_value(self, data):
try:
app_label, model = data.split('.')
@@ -234,9 +240,10 @@ class ModelViewSet(_ModelViewSet):
# exists
request = self.get_serializer_context()['request']
if request.query_params.get('brief', False):
serializer_class = get_serializer_for_model(self.queryset.model, prefix='Nested')
if serializer_class is not None:
return serializer_class
try:
return get_serializer_for_model(self.queryset.model, prefix='Nested')
except SerializerNotFound:
pass
# Fall back to the hard-coded serializer class
return self.serializer_class
@@ -256,10 +263,14 @@ class FieldChoicesViewSet(ViewSet):
self._fields = OrderedDict()
for cls, field_list in self.fields:
for field_name in field_list:
model_name = cls._meta.verbose_name.lower().replace(' ', '-')
key = ':'.join([model_name, field_name])
serializer = get_serializer_for_model(cls)()
choices = []
for k, v in cls._meta.get_field(field_name).choices:
for k, v in serializer.get_fields()[field_name].choices.items():
if type(v) in [list, tuple]:
for k2, v2 in v:
choices.append({

View File

@@ -348,7 +348,7 @@ class VirtualMachineForm(BootstrapMixin, TenancyForm, CustomFieldForm):
"role": APISelect(
api_url="/api/dcim/device-roles/",
additional_query_params={
"vm_role": "true"
"vm_role": "True"
}
),
'primary_ip4': StaticSelect2(),
@@ -480,7 +480,7 @@ class VirtualMachineBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldB
widget=APISelect(
api_url="/api/dcim/device-roles/",
additional_query_params={
"vm_role": "true"
"vm_role": "True"
}
)
)
@@ -582,7 +582,7 @@ class VirtualMachineFilterForm(BootstrapMixin, CustomFieldFilterForm):
value_field="slug",
null_option=True,
additional_query_params={
'vm_role': 'true'
'vm_role': "True"
}
)
)

View File

@@ -11,7 +11,7 @@ CLUSTERTYPE_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.virtualization.change_clustertype %}
<a href="{% url 'virtualization:clustertype_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'virtualization:clustertype_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
@@ -20,7 +20,7 @@ CLUSTERGROUP_ACTIONS = """
<i class="fa fa-history"></i>
</a>
{% if perms.virtualization.change_clustergroup %}
<a href="{% url 'virtualization:clustergroup_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="{% url 'virtualization:clustergroup_edit' slug=record.slug %}?return_url={{ request.path }}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""

View File

@@ -622,7 +622,7 @@ class InterfaceTest(APITestCase):
def test_delete_interface(self):
url = reverse('dcim-api:interface-detail', kwargs={'pk': self.interface1.pk})
url = reverse('virtualization-api:interface-detail', kwargs={'pk': self.interface1.pk})
response = self.client.delete(url, **self.header)
self.assertHttpStatus(response, status.HTTP_204_NO_CONTENT)

View File

@@ -1,4 +1,4 @@
Django>=2.1.5,<2.2
Django>=2.2,<2.3
django-cors-headers==2.4.0
django-debug-toolbar==1.11
django-filter==2.0.0
@@ -10,6 +10,7 @@ django-timezone-field==3.0
djangorestframework==3.9.0
drf-yasg[validation]==1.14.0
graphviz==0.10.1
Jinja2==2.10
Markdown==2.6.11
netaddr==0.7.19
Pillow==5.3.0