1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#8157: Clean up L2VPN assignment for VM interfaces

This commit is contained in:
jeremystretch
2022-07-06 13:31:31 -04:00
parent 5fd3eb82cd
commit 4d3278cb52
4 changed files with 21 additions and 8 deletions

View File

@ -9,8 +9,8 @@ from dcim.choices import *
from dcim.constants import * from dcim.constants import *
from dcim.models import * from dcim.models import *
from ipam.api.nested_serializers import ( from ipam.api.nested_serializers import (
NestedASNSerializer, NestedIPAddressSerializer, NestedVLANSerializer, NestedVRFSerializer, NestedASNSerializer, NestedIPAddressSerializer, NestedL2VPNTerminationSerializer, NestedVLANSerializer,
NestedL2VPNTerminationSerializer, NestedVRFSerializer,
) )
from ipam.models import ASN, VLAN from ipam.models import ASN, VLAN
from netbox.api import ChoiceField, ContentTypeField, SerializedPKRelatedField from netbox.api import ChoiceField, ContentTypeField, SerializedPKRelatedField

View File

@ -11,12 +11,12 @@
<div class="card-body"> <div class="card-body">
<table class="table table-hover"> <table class="table table-hover">
<tr> <tr>
<th scope="row">L2vPN</th> <th scope="row">L2VPN</th>
<td>{{ object.l2vpn.name|placeholder }}</td> <td>{{ object.l2vpn|linkify }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Assigned Object</th> <th scope="row">Assigned Object</th>
<td>{{ object.assigned_object.name|placeholder }}</td> <td>{{ object.assigned_object|linkify }}</td>
</tr> </tr>
</table> </table>
</div> </div>

View File

@ -5,7 +5,9 @@ from dcim.api.nested_serializers import (
NestedDeviceSerializer, NestedDeviceRoleSerializer, NestedPlatformSerializer, NestedSiteSerializer, NestedDeviceSerializer, NestedDeviceRoleSerializer, NestedPlatformSerializer, NestedSiteSerializer,
) )
from dcim.choices import InterfaceModeChoices from dcim.choices import InterfaceModeChoices
from ipam.api.nested_serializers import NestedIPAddressSerializer, NestedVLANSerializer, NestedVRFSerializer from ipam.api.nested_serializers import (
NestedIPAddressSerializer, NestedL2VPNTerminationSerializer, NestedVLANSerializer, NestedVRFSerializer,
)
from ipam.models import VLAN from ipam.models import VLAN
from netbox.api import ChoiceField, SerializedPKRelatedField from netbox.api import ChoiceField, SerializedPKRelatedField
from netbox.api.serializers import NetBoxModelSerializer from netbox.api.serializers import NetBoxModelSerializer
@ -121,6 +123,7 @@ class VMInterfaceSerializer(NetBoxModelSerializer):
many=True many=True
) )
vrf = NestedVRFSerializer(required=False, allow_null=True) vrf = NestedVRFSerializer(required=False, allow_null=True)
l2vpn_termination = NestedL2VPNTerminationSerializer(read_only=True)
count_ipaddresses = serializers.IntegerField(read_only=True) count_ipaddresses = serializers.IntegerField(read_only=True)
count_fhrp_groups = serializers.IntegerField(read_only=True) count_fhrp_groups = serializers.IntegerField(read_only=True)
@ -128,8 +131,8 @@ class VMInterfaceSerializer(NetBoxModelSerializer):
model = VMInterface model = VMInterface
fields = [ fields = [
'id', 'url', 'display', 'virtual_machine', 'name', 'enabled', 'parent', 'bridge', 'mtu', 'mac_address', 'id', 'url', 'display', 'virtual_machine', 'name', 'enabled', 'parent', 'bridge', 'mtu', 'mac_address',
'description', 'mode', 'untagged_vlan', 'tagged_vlans', 'vrf', 'tags', 'custom_fields', 'created', 'description', 'mode', 'untagged_vlan', 'tagged_vlans', 'vrf', 'l2vpn_termination', 'tags', 'custom_fields',
'last_updated', 'count_ipaddresses', 'count_fhrp_groups', 'created', 'last_updated', 'count_ipaddresses', 'count_fhrp_groups',
] ]
def validate(self, data): def validate(self, data):

View File

@ -440,6 +440,12 @@ class VMInterface(NetBoxModel, BaseInterface):
object_id_field='interface_id', object_id_field='interface_id',
related_query_name='+' related_query_name='+'
) )
l2vpn_terminations = GenericRelation(
to='ipam.L2VPNTermination',
content_type_field='assigned_object_type',
object_id_field='assigned_object_id',
related_query_name='vminterface',
)
class Meta: class Meta:
verbose_name = 'interface' verbose_name = 'interface'
@ -498,3 +504,7 @@ class VMInterface(NetBoxModel, BaseInterface):
@property @property
def parent_object(self): def parent_object(self):
return self.virtual_machine return self.virtual_machine
@property
def l2vpn_termination(self):
return self.l2vpn_terminations.first()