bulk_edit.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. 'L2VPNBulkEditForm',
  16. 'L2VPNTerminationBulkEditForm',
  17. 'TunnelBulkEditForm',
  18. 'TunnelGroupBulkEditForm',
  19. 'TunnelTerminationBulkEditForm',
  20. )
  21. class TunnelGroupBulkEditForm(NetBoxModelBulkEditForm):
  22. description = forms.CharField(
  23. label=_('Description'),
  24. max_length=200,
  25. required=False
  26. )
  27. model = TunnelGroup
  28. nullable_fields = ('description',)
  29. class TunnelBulkEditForm(NetBoxModelBulkEditForm):
  30. status = forms.ChoiceField(
  31. label=_('Status'),
  32. choices=add_blank_choice(TunnelStatusChoices),
  33. required=False
  34. )
  35. group = DynamicModelChoiceField(
  36. queryset=TunnelGroup.objects.all(),
  37. label=_('Tunnel group'),
  38. required=False
  39. )
  40. encapsulation = forms.ChoiceField(
  41. label=_('Encapsulation'),
  42. choices=add_blank_choice(TunnelEncapsulationChoices),
  43. required=False
  44. )
  45. ipsec_profile = DynamicModelMultipleChoiceField(
  46. queryset=IPSecProfile.objects.all(),
  47. label=_('IPSec profile'),
  48. required=False
  49. )
  50. tenant = DynamicModelChoiceField(
  51. label=_('Tenant'),
  52. queryset=Tenant.objects.all(),
  53. required=False
  54. )
  55. description = forms.CharField(
  56. label=_('Description'),
  57. max_length=200,
  58. required=False
  59. )
  60. tunnel_id = forms.IntegerField(
  61. label=_('Tunnel ID'),
  62. required=False
  63. )
  64. comments = CommentField()
  65. model = Tunnel
  66. fieldsets = (
  67. (_('Tunnel'), ('status', 'group', 'encapsulation', 'tunnel_id', 'description')),
  68. (_('Security'), ('ipsec_profile',)),
  69. (_('Tenancy'), ('tenant',)),
  70. )
  71. nullable_fields = (
  72. 'group', 'ipsec_profile', 'tunnel_id', 'tenant', 'description', 'comments',
  73. )
  74. class TunnelTerminationBulkEditForm(NetBoxModelBulkEditForm):
  75. role = forms.ChoiceField(
  76. label=_('Role'),
  77. choices=add_blank_choice(TunnelTerminationRoleChoices),
  78. required=False
  79. )
  80. model = TunnelTermination
  81. class IKEProposalBulkEditForm(NetBoxModelBulkEditForm):
  82. authentication_method = forms.ChoiceField(
  83. label=_('Authentication method'),
  84. choices=add_blank_choice(AuthenticationMethodChoices),
  85. required=False
  86. )
  87. encryption_algorithm = forms.ChoiceField(
  88. label=_('Encryption algorithm'),
  89. choices=add_blank_choice(EncryptionAlgorithmChoices),
  90. required=False
  91. )
  92. authentication_algorithm = forms.ChoiceField(
  93. label=_('Authentication algorithm'),
  94. choices=add_blank_choice(AuthenticationAlgorithmChoices),
  95. required=False
  96. )
  97. group = forms.ChoiceField(
  98. label=_('Group'),
  99. choices=add_blank_choice(DHGroupChoices),
  100. required=False
  101. )
  102. sa_lifetime = forms.IntegerField(
  103. label=_('SA lifetime'),
  104. required=False
  105. )
  106. description = forms.CharField(
  107. label=_('Description'),
  108. max_length=200,
  109. required=False
  110. )
  111. comments = CommentField()
  112. model = IKEProposal
  113. fieldsets = (
  114. (None, (
  115. 'authentication_method', 'encryption_algorithm', 'authentication_algorithm', 'group', 'sa_lifetime',
  116. 'description',
  117. )),
  118. )
  119. nullable_fields = (
  120. 'sa_lifetime', 'description', 'comments',
  121. )
  122. class IKEPolicyBulkEditForm(NetBoxModelBulkEditForm):
  123. version = forms.ChoiceField(
  124. label=_('Version'),
  125. choices=add_blank_choice(IKEVersionChoices),
  126. required=False
  127. )
  128. mode = forms.ChoiceField(
  129. label=_('Mode'),
  130. choices=add_blank_choice(IKEModeChoices),
  131. required=False
  132. )
  133. preshared_key = forms.CharField(
  134. label=_('Pre-shared key'),
  135. required=False
  136. )
  137. description = forms.CharField(
  138. label=_('Description'),
  139. max_length=200,
  140. required=False
  141. )
  142. comments = CommentField()
  143. model = IKEPolicy
  144. fieldsets = (
  145. (None, (
  146. 'version', 'mode', 'preshared_key', 'description',
  147. )),
  148. )
  149. nullable_fields = (
  150. 'mode', 'preshared_key', 'description', 'comments',
  151. )
  152. class IPSecProposalBulkEditForm(NetBoxModelBulkEditForm):
  153. encryption_algorithm = forms.ChoiceField(
  154. label=_('Encryption algorithm'),
  155. choices=add_blank_choice(EncryptionAlgorithmChoices),
  156. required=False
  157. )
  158. authentication_algorithm = forms.ChoiceField(
  159. label=_('Authentication algorithm'),
  160. choices=add_blank_choice(AuthenticationAlgorithmChoices),
  161. required=False
  162. )
  163. sa_lifetime_seconds = forms.IntegerField(
  164. label=_('SA lifetime (seconds)'),
  165. required=False
  166. )
  167. sa_lifetime_data = forms.IntegerField(
  168. label=_('SA lifetime (KB)'),
  169. required=False
  170. )
  171. description = forms.CharField(
  172. label=_('Description'),
  173. max_length=200,
  174. required=False
  175. )
  176. comments = CommentField()
  177. model = IPSecProposal
  178. fieldsets = (
  179. (None, (
  180. 'encryption_algorithm', 'authentication_algorithm', 'sa_lifetime_seconds', 'sa_lifetime_data',
  181. 'description',
  182. )),
  183. )
  184. nullable_fields = (
  185. 'sa_lifetime_seconds', 'sa_lifetime_data', 'description', 'comments',
  186. )
  187. class IPSecPolicyBulkEditForm(NetBoxModelBulkEditForm):
  188. pfs_group = forms.ChoiceField(
  189. label=_('PFS group'),
  190. choices=add_blank_choice(DHGroupChoices),
  191. required=False
  192. )
  193. description = forms.CharField(
  194. label=_('Description'),
  195. max_length=200,
  196. required=False
  197. )
  198. comments = CommentField()
  199. model = IPSecPolicy
  200. fieldsets = (
  201. (None, ('pfs_group', 'description',)),
  202. )
  203. nullable_fields = (
  204. 'pfs_group', 'description', 'comments',
  205. )
  206. class IPSecProfileBulkEditForm(NetBoxModelBulkEditForm):
  207. mode = forms.ChoiceField(
  208. label=_('Mode'),
  209. choices=add_blank_choice(IPSecModeChoices),
  210. required=False
  211. )
  212. ike_policy = DynamicModelChoiceField(
  213. label=_('IKE policy'),
  214. queryset=IKEPolicy.objects.all(),
  215. required=False
  216. )
  217. ipsec_policy = DynamicModelChoiceField(
  218. label=_('IPSec policy'),
  219. queryset=IPSecPolicy.objects.all(),
  220. required=False
  221. )
  222. description = forms.CharField(
  223. label=_('Description'),
  224. max_length=200,
  225. required=False
  226. )
  227. comments = CommentField()
  228. model = IPSecProfile
  229. fieldsets = (
  230. (_('Profile'), (
  231. 'mode', 'ike_policy', 'ipsec_policy', 'description',
  232. )),
  233. )
  234. nullable_fields = (
  235. 'description', 'comments',
  236. )
  237. class L2VPNBulkEditForm(NetBoxModelBulkEditForm):
  238. type = forms.ChoiceField(
  239. label=_('Type'),
  240. choices=add_blank_choice(L2VPNTypeChoices),
  241. required=False
  242. )
  243. tenant = DynamicModelChoiceField(
  244. label=_('Tenant'),
  245. queryset=Tenant.objects.all(),
  246. required=False
  247. )
  248. description = forms.CharField(
  249. label=_('Description'),
  250. max_length=200,
  251. required=False
  252. )
  253. comments = CommentField()
  254. model = L2VPN
  255. fieldsets = (
  256. (None, ('type', 'tenant', 'description')),
  257. )
  258. nullable_fields = ('tenant', 'description', 'comments')
  259. class L2VPNTerminationBulkEditForm(NetBoxModelBulkEditForm):
  260. model = L2VPN