fhrp.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import django_tables2 as tables
  2. from ipam.models import *
  3. from netbox.tables import NetBoxTable, columns
  4. __all__ = (
  5. 'FHRPGroupTable',
  6. 'FHRPGroupAssignmentTable',
  7. )
  8. IPADDRESSES = """
  9. {% for ip in record.ip_addresses.all %}
  10. <a href="{{ ip.get_absolute_url }}">{{ ip }}</a><br />
  11. {% endfor %}
  12. """
  13. class FHRPGroupTable(NetBoxTable):
  14. group_id = tables.Column(
  15. linkify=True
  16. )
  17. comments = columns.MarkdownColumn()
  18. ip_addresses = tables.TemplateColumn(
  19. template_code=IPADDRESSES,
  20. orderable=False,
  21. verbose_name='IP Addresses'
  22. )
  23. member_count = tables.Column(
  24. verbose_name='Members'
  25. )
  26. tags = columns.TagColumn(
  27. url_name='ipam:fhrpgroup_list'
  28. )
  29. class Meta(NetBoxTable.Meta):
  30. model = FHRPGroup
  31. fields = (
  32. 'pk', 'group_id', 'protocol', 'auth_type', 'auth_key', 'description', 'ip_addresses', 'member_count',
  33. 'tags', 'created', 'last_updated',
  34. )
  35. default_columns = ('pk', 'group_id', 'protocol', 'auth_type', 'description', 'ip_addresses', 'member_count')
  36. class FHRPGroupAssignmentTable(NetBoxTable):
  37. interface_parent = tables.Column(
  38. accessor=tables.A('interface__parent_object'),
  39. linkify=True,
  40. orderable=False,
  41. verbose_name='Parent'
  42. )
  43. interface = tables.Column(
  44. linkify=True,
  45. orderable=False
  46. )
  47. group = tables.Column(
  48. linkify=True
  49. )
  50. actions = columns.ActionsColumn(
  51. actions=('edit', 'delete')
  52. )
  53. class Meta(NetBoxTable.Meta):
  54. model = FHRPGroupAssignment
  55. fields = ('pk', 'group', 'interface_parent', 'interface', 'priority')
  56. exclude = ('id',)