def get(self, request, pk): vminterface = get_object_or_404(self.queryset, pk=pk) # Get assigned IP addresses ipaddress_table = InterfaceIPAddressTable( data=vminterface.ip_addresses.restrict(request.user, 'view').prefetch_related( 'vrf', 'tenant'), orderable=False) # Get assigned VLANs and annotate whether each is tagged or untagged vlans = [] if vminterface.untagged_vlan is not None: vlans.append(vminterface.untagged_vlan) vlans[0].tagged = False for vlan in vminterface.tagged_vlans.restrict( request.user).prefetch_related('site', 'group', 'tenant', 'role'): vlan.tagged = True vlans.append(vlan) vlan_table = InterfaceVLANTable(interface=vminterface, data=vlans, orderable=False) return render( request, 'virtualization/vminterface.html', { 'vminterface': vminterface, 'ipaddress_table': ipaddress_table, 'vlan_table': vlan_table, })
def get_extra_context(self, request, instance): # Get assigned IP addresses ipaddress_table = InterfaceIPAddressTable( data=instance.ip_addresses.restrict(request.user, 'view').prefetch_related('vrf', 'tenant'), orderable=False ) # Get child interfaces child_interfaces = VMInterface.objects.restrict(request.user, 'view').filter(parent=instance) child_interfaces_tables = tables.VMInterfaceTable( child_interfaces, exclude=('virtual_machine',), orderable=False ) # Get assigned VLANs and annotate whether each is tagged or untagged vlans = [] if instance.untagged_vlan is not None: vlans.append(instance.untagged_vlan) vlans[0].tagged = False for vlan in instance.tagged_vlans.restrict(request.user).prefetch_related('site', 'group', 'tenant', 'role'): vlan.tagged = True vlans.append(vlan) vlan_table = InterfaceVLANTable( interface=instance, data=vlans, orderable=False ) return { 'ipaddress_table': ipaddress_table, 'child_interfaces_table': child_interfaces_tables, 'vlan_table': vlan_table, }