bulk_edit.py 6.8 KB

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