bulk_edit.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. from django import forms
  2. from django.utils.translation import gettext_lazy as _
  3. from netbox.forms import NetBoxModelBulkEditForm
  4. from tenancy.models import Tenant
  5. from utilities.forms import add_blank_choice
  6. from utilities.forms.fields import CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField
  7. from vpn.choices import *
  8. from vpn.models import *
  9. __all__ = (
  10. 'IKEPolicyBulkEditForm',
  11. 'IKEProposalBulkEditForm',
  12. 'IPSecPolicyBulkEditForm',
  13. 'IPSecProfileBulkEditForm',
  14. 'IPSecProposalBulkEditForm',
  15. 'TunnelBulkEditForm',
  16. 'TunnelTerminationBulkEditForm',
  17. )
  18. class TunnelBulkEditForm(NetBoxModelBulkEditForm):
  19. status = forms.ChoiceField(
  20. label=_('Status'),
  21. choices=add_blank_choice(TunnelStatusChoices),
  22. required=False
  23. )
  24. encapsulation = forms.ChoiceField(
  25. label=_('Encapsulation'),
  26. choices=add_blank_choice(TunnelEncapsulationChoices),
  27. required=False
  28. )
  29. ipsec_profile = DynamicModelMultipleChoiceField(
  30. queryset=IPSecProfile.objects.all(),
  31. label=_('IPSec profile'),
  32. required=False
  33. )
  34. tenant = DynamicModelChoiceField(
  35. label=_('Tenant'),
  36. queryset=Tenant.objects.all(),
  37. required=False
  38. )
  39. description = forms.CharField(
  40. label=_('Description'),
  41. max_length=200,
  42. required=False
  43. )
  44. tunnel_id = forms.IntegerField(
  45. label=_('Tunnel ID'),
  46. required=False
  47. )
  48. comments = CommentField()
  49. model = Tunnel
  50. fieldsets = (
  51. (_('Tunnel'), ('status', 'encapsulation', 'tunnel_id', 'description')),
  52. (_('Security'), ('ipsec_profile',)),
  53. (_('Tenancy'), ('tenant',)),
  54. )
  55. nullable_fields = (
  56. 'ipsec_profile', 'tunnel_id', 'tenant', 'description', 'comments',
  57. )
  58. class TunnelTerminationBulkEditForm(NetBoxModelBulkEditForm):
  59. role = forms.ChoiceField(
  60. label=_('Role'),
  61. choices=add_blank_choice(TunnelTerminationRoleChoices),
  62. required=False
  63. )
  64. model = TunnelTermination
  65. class IKEProposalBulkEditForm(NetBoxModelBulkEditForm):
  66. authentication_method = forms.ChoiceField(
  67. label=_('Authentication method'),
  68. choices=add_blank_choice(AuthenticationMethodChoices),
  69. required=False
  70. )
  71. encryption_algorithm = forms.ChoiceField(
  72. label=_('Encryption algorithm'),
  73. choices=add_blank_choice(EncryptionAlgorithmChoices),
  74. required=False
  75. )
  76. authentication_algorithm = forms.ChoiceField(
  77. label=_('Authentication algorithm'),
  78. choices=add_blank_choice(AuthenticationAlgorithmChoices),
  79. required=False
  80. )
  81. group = forms.ChoiceField(
  82. label=_('Group'),
  83. choices=add_blank_choice(DHGroupChoices),
  84. required=False
  85. )
  86. sa_lifetime = forms.IntegerField(
  87. label=_('SA lifetime'),
  88. required=False
  89. )
  90. description = forms.CharField(
  91. label=_('Description'),
  92. max_length=200,
  93. required=False
  94. )
  95. comments = CommentField()
  96. model = IKEProposal
  97. fieldsets = (
  98. (None, (
  99. 'authentication_method', 'encryption_algorithm', 'authentication_algorithm', 'group', 'sa_lifetime',
  100. 'description',
  101. )),
  102. )
  103. nullable_fields = (
  104. 'sa_lifetime', 'description', 'comments',
  105. )
  106. class IKEPolicyBulkEditForm(NetBoxModelBulkEditForm):
  107. version = forms.ChoiceField(
  108. label=_('Version'),
  109. choices=add_blank_choice(IKEVersionChoices),
  110. required=False
  111. )
  112. mode = forms.ChoiceField(
  113. label=_('Mode'),
  114. choices=add_blank_choice(IKEModeChoices),
  115. required=False
  116. )
  117. preshared_key = forms.CharField(
  118. label=_('Pre-shared key'),
  119. required=False
  120. )
  121. description = forms.CharField(
  122. label=_('Description'),
  123. max_length=200,
  124. required=False
  125. )
  126. comments = CommentField()
  127. model = IKEPolicy
  128. fieldsets = (
  129. (None, (
  130. 'version', 'mode', 'preshared_key', 'description',
  131. )),
  132. )
  133. nullable_fields = (
  134. 'preshared_key', 'description', 'comments',
  135. )
  136. class IPSecProposalBulkEditForm(NetBoxModelBulkEditForm):
  137. encryption_algorithm = forms.ChoiceField(
  138. label=_('Encryption algorithm'),
  139. choices=add_blank_choice(EncryptionAlgorithmChoices),
  140. required=False
  141. )
  142. authentication_algorithm = forms.ChoiceField(
  143. label=_('Authentication algorithm'),
  144. choices=add_blank_choice(AuthenticationAlgorithmChoices),
  145. required=False
  146. )
  147. sa_lifetime_seconds = forms.IntegerField(
  148. label=_('SA lifetime (seconds)'),
  149. required=False
  150. )
  151. sa_lifetime_data = forms.IntegerField(
  152. label=_('SA lifetime (KB)'),
  153. required=False
  154. )
  155. description = forms.CharField(
  156. label=_('Description'),
  157. max_length=200,
  158. required=False
  159. )
  160. comments = CommentField()
  161. model = IPSecProposal
  162. fieldsets = (
  163. (None, (
  164. 'encryption_algorithm', 'authentication_algorithm', 'sa_lifetime_seconds', 'sa_lifetime_data',
  165. 'description',
  166. )),
  167. )
  168. nullable_fields = (
  169. 'sa_lifetime_seconds', 'sa_lifetime_data', 'description', 'comments',
  170. )
  171. class IPSecPolicyBulkEditForm(NetBoxModelBulkEditForm):
  172. pfs_group = forms.ChoiceField(
  173. label=_('PFS group'),
  174. choices=add_blank_choice(DHGroupChoices),
  175. required=False
  176. )
  177. description = forms.CharField(
  178. label=_('Description'),
  179. max_length=200,
  180. required=False
  181. )
  182. comments = CommentField()
  183. model = IPSecPolicy
  184. fieldsets = (
  185. (None, ('pfs_group', 'description',)),
  186. )
  187. nullable_fields = (
  188. 'pfs_group', 'description', 'comments',
  189. )
  190. class IPSecProfileBulkEditForm(NetBoxModelBulkEditForm):
  191. mode = forms.ChoiceField(
  192. label=_('Mode'),
  193. choices=add_blank_choice(IPSecModeChoices),
  194. required=False
  195. )
  196. ike_policy = DynamicModelChoiceField(
  197. label=_('IKE policy'),
  198. queryset=IKEPolicy.objects.all(),
  199. required=False
  200. )
  201. ipsec_policy = DynamicModelChoiceField(
  202. label=_('IPSec policy'),
  203. queryset=IPSecPolicy.objects.all(),
  204. required=False
  205. )
  206. description = forms.CharField(
  207. label=_('Description'),
  208. max_length=200,
  209. required=False
  210. )
  211. comments = CommentField()
  212. model = IPSecProfile
  213. fieldsets = (
  214. (_('Profile'), (
  215. 'mode', 'ike_policy', 'ipsec_policy', 'description',
  216. )),
  217. )
  218. nullable_fields = (
  219. 'description', 'comments',
  220. )