bulk_import.py 3.7 KB

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