|
@@ -2,7 +2,7 @@ from django.core.exceptions import ValidationError
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
|
|
from dcim.models import Device, Interface
|
|
from dcim.models import Device, Interface
|
|
|
-from ipam.models import VLAN, IPAddress
|
|
|
|
|
|
|
+from ipam.models import VLAN, VRF, IPAddress
|
|
|
from netbox.forms import NetBoxModelImportForm, OrganizationalModelImportForm, PrimaryModelImportForm
|
|
from netbox.forms import NetBoxModelImportForm, OrganizationalModelImportForm, PrimaryModelImportForm
|
|
|
from tenancy.models import Tenant
|
|
from tenancy.models import Tenant
|
|
|
from utilities.forms.fields import CSVChoiceField, CSVModelChoiceField, CSVModelMultipleChoiceField
|
|
from utilities.forms.fields import CSVChoiceField, CSVModelChoiceField, CSVModelMultipleChoiceField
|
|
@@ -289,14 +289,14 @@ class L2VPNTerminationImportForm(NetBoxModelImportForm):
|
|
|
queryset=Device.objects.all(),
|
|
queryset=Device.objects.all(),
|
|
|
required=False,
|
|
required=False,
|
|
|
to_field_name='name',
|
|
to_field_name='name',
|
|
|
- help_text=_('Parent device (for interface)')
|
|
|
|
|
|
|
+ help_text=_('Parent device (for interface or IP address)')
|
|
|
)
|
|
)
|
|
|
virtual_machine = CSVModelChoiceField(
|
|
virtual_machine = CSVModelChoiceField(
|
|
|
label=_('Virtual machine'),
|
|
label=_('Virtual machine'),
|
|
|
queryset=VirtualMachine.objects.all(),
|
|
queryset=VirtualMachine.objects.all(),
|
|
|
required=False,
|
|
required=False,
|
|
|
to_field_name='name',
|
|
to_field_name='name',
|
|
|
- help_text=_('Parent virtual machine (for interface)')
|
|
|
|
|
|
|
+ help_text=_('Parent virtual machine (for interface or IP address)')
|
|
|
)
|
|
)
|
|
|
interface = CSVModelChoiceField(
|
|
interface = CSVModelChoiceField(
|
|
|
label=_('Interface'),
|
|
label=_('Interface'),
|
|
@@ -319,25 +319,47 @@ class L2VPNTerminationImportForm(NetBoxModelImportForm):
|
|
|
to_field_name='address',
|
|
to_field_name='address',
|
|
|
help_text=_('Assigned IP address, with mask (e.g. the far-end PE of a pseudowire)')
|
|
help_text=_('Assigned IP address, with mask (e.g. the far-end PE of a pseudowire)')
|
|
|
)
|
|
)
|
|
|
|
|
+ ipaddress_vrf = CSVModelChoiceField(
|
|
|
|
|
+ label=_('IP address VRF'),
|
|
|
|
|
+ queryset=VRF.objects.all(),
|
|
|
|
|
+ required=False,
|
|
|
|
|
+ to_field_name='name',
|
|
|
|
|
+ help_text=_('VRF of the assigned IP address')
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
class Meta:
|
|
class Meta:
|
|
|
model = L2VPNTermination
|
|
model = L2VPNTermination
|
|
|
- fields = ('l2vpn', 'device', 'virtual_machine', 'interface', 'vlan', 'ipaddress', 'tags')
|
|
|
|
|
|
|
+ fields = ('l2vpn', 'device', 'virtual_machine', 'interface', 'vlan', 'ipaddress', 'ipaddress_vrf', 'tags')
|
|
|
|
|
|
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
def __init__(self, data=None, *args, **kwargs):
|
|
|
super().__init__(data, *args, **kwargs)
|
|
super().__init__(data, *args, **kwargs)
|
|
|
|
|
|
|
|
if data:
|
|
if data:
|
|
|
|
|
|
|
|
- # Limit interface queryset by device or VM
|
|
|
|
|
|
|
+ # Limit interface and IP address querysets by device or VM
|
|
|
if data.get('device'):
|
|
if data.get('device'):
|
|
|
self.fields['interface'].queryset = Interface.objects.filter(
|
|
self.fields['interface'].queryset = Interface.objects.filter(
|
|
|
**{f"device__{self.fields['device'].to_field_name}": data['device']}
|
|
**{f"device__{self.fields['device'].to_field_name}": data['device']}
|
|
|
)
|
|
)
|
|
|
|
|
+ self.fields['ipaddress'].queryset = IPAddress.objects.filter(
|
|
|
|
|
+ **{f"interface__device__{self.fields['device'].to_field_name}": data['device']}
|
|
|
|
|
+ )
|
|
|
elif data.get('virtual_machine'):
|
|
elif data.get('virtual_machine'):
|
|
|
self.fields['interface'].queryset = VMInterface.objects.filter(
|
|
self.fields['interface'].queryset = VMInterface.objects.filter(
|
|
|
**{f"virtual_machine__{self.fields['virtual_machine'].to_field_name}": data['virtual_machine']}
|
|
**{f"virtual_machine__{self.fields['virtual_machine'].to_field_name}": data['virtual_machine']}
|
|
|
)
|
|
)
|
|
|
|
|
+ self.fields['ipaddress'].queryset = IPAddress.objects.filter(
|
|
|
|
|
+ **{
|
|
|
|
|
+ f"vminterface__virtual_machine__{self.fields['virtual_machine'].to_field_name}":
|
|
|
|
|
+ data['virtual_machine']
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ # Limit IP address queryset by VRF
|
|
|
|
|
+ if data.get('ipaddress_vrf'):
|
|
|
|
|
+ self.fields['ipaddress'].queryset = self.fields['ipaddress'].queryset.filter(
|
|
|
|
|
+ **{f"vrf__{self.fields['ipaddress_vrf'].to_field_name}": data['ipaddress_vrf']}
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
def clean(self):
|
|
def clean(self):
|
|
|
super().clean()
|
|
super().clean()
|