Skip to content

Commit

Permalink
Fixes: #14839 - Check for tunnel termination type in additional insta…
Browse files Browse the repository at this point in the history
…nces
  • Loading branch information
DanSheps committed Jan 31, 2024
1 parent 1b9e6be commit 1c2107e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion netbox/vpn/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,17 @@ class Meta:
def __init__(self, *args, initial=None, **kwargs):
super().__init__(*args, initial=initial, **kwargs)

if initial and initial.get('type') == TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE:
# If initial or self.data is set and the type is a VIRTUALMACHINE type, swap the field querysets.
if (
initial and initial.get('type') == TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE
) or (
self.data and self.data.get('type') == TunnelTerminationTypeChoices.TYPE_VIRTUALMACHINE
) or (
self.instance.pk and isinstance(self.instance.termination.parent_object, VirtualMachine)
):
self.fields['parent'].label = _('Virtual Machine')
self.fields['parent'].queryset = VirtualMachine.objects.all()
self.fields['parent'].widget.attrs['selector'] = 'virtualization.virtualmachine'
self.fields['termination'].queryset = VMInterface.objects.all()
self.fields['termination'].widget.add_query_params({
'virtual_machine_id': '$parent',
Expand Down

0 comments on commit 1c2107e

Please sign in to comment.