|
@@ -9,7 +9,7 @@ from dcim.choices import *
|
|
|
from dcim.constants import *
|
|
from dcim.constants import *
|
|
|
from dcim.models import *
|
|
from dcim.models import *
|
|
|
from extras.models import ConfigTemplate
|
|
from extras.models import ConfigTemplate
|
|
|
-from ipam.models import VRF
|
|
|
|
|
|
|
+from ipam.models import VRF, IPAddress
|
|
|
from netbox.forms import NetBoxModelImportForm
|
|
from netbox.forms import NetBoxModelImportForm
|
|
|
from tenancy.models import Tenant
|
|
from tenancy.models import Tenant
|
|
|
from utilities.forms.fields import (
|
|
from utilities.forms.fields import (
|
|
@@ -1435,9 +1435,33 @@ class VirtualDeviceContextImportForm(NetBoxModelImportForm):
|
|
|
label=_('Status'),
|
|
label=_('Status'),
|
|
|
choices=VirtualDeviceContextStatusChoices,
|
|
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:
|
|
class Meta:
|
|
|
fields = [
|
|
fields = [
|
|
|
- 'name', 'device', 'status', 'tenant', 'identifier', 'comments',
|
|
|
|
|
|
|
+ 'name', 'device', 'status', 'tenant', 'identifier', 'comments', 'primary_ip4', 'primary_ip6',
|
|
|
]
|
|
]
|
|
|
model = VirtualDeviceContext
|
|
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)
|