mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 17:08:41 -06:00
Merge branch 'develop' into develop-2.2
Conflicts: netbox/dcim/forms.py
This commit is contained in:
commit
3466da4338
@ -28,12 +28,6 @@ from .models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
FORM_STATUS_CHOICES = [
|
|
||||||
['', '---------'],
|
|
||||||
]
|
|
||||||
|
|
||||||
FORM_STATUS_CHOICES += STATUS_CHOICES
|
|
||||||
|
|
||||||
DEVICE_BY_PK_RE = '{\d+\}'
|
DEVICE_BY_PK_RE = '{\d+\}'
|
||||||
|
|
||||||
|
|
||||||
@ -633,13 +627,28 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldForm):
|
|||||||
|
|
||||||
# Compile list of choices for primary IPv4 and IPv6 addresses
|
# Compile list of choices for primary IPv4 and IPv6 addresses
|
||||||
for family in [4, 6]:
|
for family in [4, 6]:
|
||||||
ip_choices = []
|
ip_choices = [(None, '---------')]
|
||||||
interface_ips = IPAddress.objects.filter(family=family, interface__device=self.instance)
|
# Collect interface IPs
|
||||||
ip_choices += [(ip.id, '{} ({})'.format(ip.address, ip.interface)) for ip in interface_ips]
|
interface_ips = IPAddress.objects.select_related('interface').filter(
|
||||||
nat_ips = IPAddress.objects.filter(family=family, nat_inside__interface__device=self.instance)\
|
family=family, interface__device=self.instance
|
||||||
.select_related('nat_inside__interface')
|
)
|
||||||
ip_choices += [(ip.id, '{} ({} NAT)'.format(ip.address, ip.nat_inside.interface)) for ip in nat_ips]
|
if interface_ips:
|
||||||
self.fields['primary_ip{}'.format(family)].choices = [(None, '---------')] + ip_choices
|
ip_choices.append(
|
||||||
|
('Interface IPs', [
|
||||||
|
(ip.id, '{} ({})'.format(ip.address, ip.interface)) for ip in interface_ips
|
||||||
|
])
|
||||||
|
)
|
||||||
|
# Collect NAT IPs
|
||||||
|
nat_ips = IPAddress.objects.select_related('nat_inside').filter(
|
||||||
|
family=family, nat_inside__interface__device=self.instance
|
||||||
|
)
|
||||||
|
if nat_ips:
|
||||||
|
ip_choices.append(
|
||||||
|
('NAT IPs', [
|
||||||
|
(ip.id, '{} ({})'.format(ip.address, ip.nat_inside.address)) for ip in nat_ips
|
||||||
|
])
|
||||||
|
)
|
||||||
|
self.fields['primary_ip{}'.format(family)].choices = ip_choices
|
||||||
|
|
||||||
# If editing an existing device, exclude it from the list of occupied rack units. This ensures that a device
|
# If editing an existing device, exclude it from the list of occupied rack units. This ensures that a device
|
||||||
# can be flipped from one face to another.
|
# can be flipped from one face to another.
|
||||||
@ -839,7 +848,7 @@ class DeviceBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
|||||||
device_role = forms.ModelChoiceField(queryset=DeviceRole.objects.all(), required=False, label='Role')
|
device_role = forms.ModelChoiceField(queryset=DeviceRole.objects.all(), required=False, label='Role')
|
||||||
tenant = forms.ModelChoiceField(queryset=Tenant.objects.all(), required=False)
|
tenant = forms.ModelChoiceField(queryset=Tenant.objects.all(), required=False)
|
||||||
platform = forms.ModelChoiceField(queryset=Platform.objects.all(), required=False)
|
platform = forms.ModelChoiceField(queryset=Platform.objects.all(), required=False)
|
||||||
status = forms.ChoiceField(choices=FORM_STATUS_CHOICES, required=False, initial='', label='Status')
|
status = forms.ChoiceField(choices=add_blank_choice(STATUS_CHOICES), required=False, initial='')
|
||||||
serial = forms.CharField(max_length=50, required=False, label='Serial Number')
|
serial = forms.CharField(max_length=50, required=False, label='Serial Number')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -898,13 +898,25 @@ class Device(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Validate primary IPv4 address
|
# Validate primary IPv4 address
|
||||||
if self.primary_ip4 and (self.primary_ip4.interface is None or self.primary_ip4.interface.device != self):
|
if self.primary_ip4 and (
|
||||||
|
self.primary_ip4.interface is None or
|
||||||
|
self.primary_ip4.interface.device != self
|
||||||
|
) and (
|
||||||
|
self.primary_ip4.nat_inside.interface is None or
|
||||||
|
self.primary_ip4.nat_inside.interface.device != self
|
||||||
|
):
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'primary_ip4': "The specified IP address ({}) is not assigned to this device.".format(self.primary_ip4),
|
'primary_ip4': "The specified IP address ({}) is not assigned to this device.".format(self.primary_ip4),
|
||||||
})
|
})
|
||||||
|
|
||||||
# Validate primary IPv6 address
|
# Validate primary IPv6 address
|
||||||
if self.primary_ip6 and (self.primary_ip6.interface is None or self.primary_ip6.interface.device != self):
|
if self.primary_ip6 and (
|
||||||
|
self.primary_ip6.interface is None or
|
||||||
|
self.primary_ip6.interface.device != self
|
||||||
|
) and (
|
||||||
|
self.primary_ip6.nat_inside.interface is None or
|
||||||
|
self.primary_ip6.nat_inside.interface.device != self
|
||||||
|
):
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'primary_ip6': "The specified IP address ({}) is not assigned to this device.".format(self.primary_ip6),
|
'primary_ip6': "The specified IP address ({}) is not assigned to this device.".format(self.primary_ip6),
|
||||||
})
|
})
|
||||||
|
@ -25,11 +25,8 @@ IP_FAMILY_CHOICES = [
|
|||||||
(6, 'IPv6'),
|
(6, 'IPv6'),
|
||||||
]
|
]
|
||||||
|
|
||||||
PREFIX_MASK_LENGTH_CHOICES = [
|
PREFIX_MASK_LENGTH_CHOICES = add_blank_choice([(i, i) for i in range(1, 128)])
|
||||||
('', '---------'),
|
IPADDRESS_MASK_LENGTH_CHOICES = add_blank_choice([(i, i) for i in range(1, 129)])
|
||||||
] + [(i, i) for i in range(1, 128)]
|
|
||||||
|
|
||||||
IPADDRESS_MASK_LENGTH_CHOICES = PREFIX_MASK_LENGTH_CHOICES + [(128, 128)]
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -43,7 +43,7 @@ $(document).ready(function() {
|
|||||||
success: function (response, status) {
|
success: function (response, status) {
|
||||||
if (response.plaintext) {
|
if (response.plaintext) {
|
||||||
console.log("Secret retrieved successfully");
|
console.log("Secret retrieved successfully");
|
||||||
$('#secret_' + secret_id).html(response.plaintext);
|
$('#secret_' + secret_id).text(response.plaintext);
|
||||||
$('button.unlock-secret[secret-id=' + secret_id + ']').hide();
|
$('button.unlock-secret[secret-id=' + secret_id + ']').hide();
|
||||||
$('button.lock-secret[secret-id=' + secret_id + ']').show();
|
$('button.lock-secret[secret-id=' + secret_id + ']').show();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user