mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 12:06:53 -06:00
* Add primary_ip4 and primary_ip6 to bulk import form for VDC * Specify IPAddress querysets with address field accessor and labels * Filter primary_ip4/ip6 querysets to only those IPs available on the device * Fix comment * Make ipv6 help text more correct * Shorten IPv6 example --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
parent
f4d4483050
commit
2dd5c82845
@ -9,7 +9,7 @@ from dcim.choices import *
|
||||
from dcim.constants import *
|
||||
from dcim.models import *
|
||||
from extras.models import ConfigTemplate
|
||||
from ipam.models import VRF
|
||||
from ipam.models import VRF, IPAddress
|
||||
from netbox.forms import NetBoxModelImportForm
|
||||
from tenancy.models import Tenant
|
||||
from utilities.forms.fields import (
|
||||
@ -1435,9 +1435,33 @@ class VirtualDeviceContextImportForm(NetBoxModelImportForm):
|
||||
label=_('Status'),
|
||||
choices=VirtualDeviceContextStatusChoices,
|
||||
)
|
||||
primary_ip4 = CSVModelChoiceField(
|
||||
label=_('Primary IPv4'),
|
||||
queryset=IPAddress.objects.all(),
|
||||
required=False,
|
||||
to_field_name='address',
|
||||
help_text=_('IPv4 address with mask, e.g. 1.2.3.4/24')
|
||||
)
|
||||
primary_ip6 = CSVModelChoiceField(
|
||||
label=_('Primary IPv6'),
|
||||
queryset=IPAddress.objects.all(),
|
||||
required=False,
|
||||
to_field_name='address',
|
||||
help_text=_('IPv6 address with prefix length, e.g. 2001:db8::1/64')
|
||||
)
|
||||
|
||||
class Meta:
|
||||
fields = [
|
||||
'name', 'device', 'status', 'tenant', 'identifier', 'comments',
|
||||
'name', 'device', 'status', 'tenant', 'identifier', 'comments', 'primary_ip4', 'primary_ip6',
|
||||
]
|
||||
model = VirtualDeviceContext
|
||||
|
||||
def __init__(self, data=None, *args, **kwargs):
|
||||
super().__init__(data, *args, **kwargs)
|
||||
|
||||
if data:
|
||||
|
||||
# Limit primary_ip4/ip6 querysets by assigned device
|
||||
params = {f"interface__device__{self.fields['device'].to_field_name}": data.get('device')}
|
||||
self.fields['primary_ip4'].queryset = self.fields['primary_ip4'].queryset.filter(**params)
|
||||
self.fields['primary_ip6'].queryset = self.fields['primary_ip6'].queryset.filter(**params)
|
||||
|
Loading…
Reference in New Issue
Block a user