2
0

bulk_import.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from django.utils.translation import gettext as _
  2. from dcim.choices import LinkStatusChoices
  3. from dcim.models import Interface
  4. from ipam.models import VLAN
  5. from netbox.forms import NetBoxModelCSVForm
  6. from tenancy.models import Tenant
  7. from utilities.forms import CSVChoiceField, CSVModelChoiceField, SlugField
  8. from wireless.choices import *
  9. from wireless.models import *
  10. __all__ = (
  11. 'WirelessLANCSVForm',
  12. 'WirelessLANGroupCSVForm',
  13. 'WirelessLinkCSVForm',
  14. )
  15. class WirelessLANGroupCSVForm(NetBoxModelCSVForm):
  16. parent = CSVModelChoiceField(
  17. queryset=WirelessLANGroup.objects.all(),
  18. required=False,
  19. to_field_name='name',
  20. help_text=_('Parent group')
  21. )
  22. slug = SlugField()
  23. class Meta:
  24. model = WirelessLANGroup
  25. fields = ('name', 'slug', 'parent', 'description', 'tags')
  26. class WirelessLANCSVForm(NetBoxModelCSVForm):
  27. group = CSVModelChoiceField(
  28. queryset=WirelessLANGroup.objects.all(),
  29. required=False,
  30. to_field_name='name',
  31. help_text=_('Assigned group')
  32. )
  33. status = CSVChoiceField(
  34. choices=WirelessLANStatusChoices,
  35. help_text='Operational status'
  36. )
  37. vlan = CSVModelChoiceField(
  38. queryset=VLAN.objects.all(),
  39. required=False,
  40. to_field_name='name',
  41. help_text=_('Bridged VLAN')
  42. )
  43. tenant = CSVModelChoiceField(
  44. queryset=Tenant.objects.all(),
  45. required=False,
  46. to_field_name='name',
  47. help_text=_('Assigned tenant')
  48. )
  49. auth_type = CSVChoiceField(
  50. choices=WirelessAuthTypeChoices,
  51. required=False,
  52. help_text=_('Authentication type')
  53. )
  54. auth_cipher = CSVChoiceField(
  55. choices=WirelessAuthCipherChoices,
  56. required=False,
  57. help_text=_('Authentication cipher')
  58. )
  59. class Meta:
  60. model = WirelessLAN
  61. fields = (
  62. 'ssid', 'group', 'status', 'vlan', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk', 'description',
  63. 'comments', 'tags',
  64. )
  65. class WirelessLinkCSVForm(NetBoxModelCSVForm):
  66. status = CSVChoiceField(
  67. choices=LinkStatusChoices,
  68. help_text=_('Connection status')
  69. )
  70. interface_a = CSVModelChoiceField(
  71. queryset=Interface.objects.all()
  72. )
  73. interface_b = CSVModelChoiceField(
  74. queryset=Interface.objects.all()
  75. )
  76. tenant = CSVModelChoiceField(
  77. queryset=Tenant.objects.all(),
  78. required=False,
  79. to_field_name='name',
  80. help_text=_('Assigned tenant')
  81. )
  82. auth_type = CSVChoiceField(
  83. choices=WirelessAuthTypeChoices,
  84. required=False,
  85. help_text=_('Authentication type')
  86. )
  87. auth_cipher = CSVChoiceField(
  88. choices=WirelessAuthCipherChoices,
  89. required=False,
  90. help_text=_('Authentication cipher')
  91. )
  92. class Meta:
  93. model = WirelessLink
  94. fields = (
  95. 'interface_a', 'interface_b', 'ssid', 'tenant', 'auth_type', 'auth_cipher', 'auth_psk', 'description',
  96. 'comments', 'tags',
  97. )