bulk_import.py 3.6 KB

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