
    >Tf*                        d dl mZ d dlmZ d dlmZmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZ d dlmZmZ d d	lT d d	lT d
Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z  G d de          Z! G d de          Z" G d de          Z#dS )     )ValidationError)gettext_lazy)Device	Interface)	IPAddressVLAN)NetBoxModelImportForm)Tenant)CSVChoiceFieldCSVModelChoiceFieldCSVModelMultipleChoiceField	SlugField)VirtualMachineVMInterface)*)
IKEPolicyImportFormIKEProposalImportFormIPSecPolicyImportFormIPSecProfileImportFormIPSecProposalImportFormL2VPNImportFormL2VPNTerminationImportFormTunnelImportFormTunnelGroupImportFormTunnelTerminationImportFormc                   <    e Zd Z e            Z G d d          ZdS )r   c                       e Zd ZeZdZdS )TunnelGroupImportForm.Meta)nameslugdescriptiontagsN)__name__
__module____qualname__TunnelGroupmodelfields     :/var/www/html/netbox-4.1.3/netbox/vpn/forms/bulk_import.pyMetar      s        8r*   r,   N)r#   r$   r%   r   r    r,   r)   r*   r+   r   r      sG        9;;D9 9 9 9 9 9 9 9 9 9r*   r   c            	          e Zd Z e ed          e ed                    Z e ed          ej	        
                                dd          Z e ed          e ed	                    Z e ed
          ej	        
                                dd          Z e ed          ej	        
                                dd ed                    Z G d d          ZdS )r   StatuszOperational statuslabelchoices	help_textzTunnel groupFr   r0   querysetrequiredto_field_nameEncapsulationzTunnel encapsulationzIPSec profiler
   zAssigned tenantr0   r4   r5   r6   r2   c                       e Zd ZeZdZdS )TunnelImportForm.Meta)
r   statusgroupencapsulationipsec_profiletenant	tunnel_idr!   commentsr"   N)r#   r$   r%   Tunnelr'   r(   r)   r*   r+   r,   r:   B   s        
r*   r,   N)r#   r$   r%   r   _TunnelStatusChoicesr;   r   r&   objectsallr<   TunnelEncapsulationChoicesr=   IPSecProfiler>   r
   r?   r,   r)   r*   r+   r   r   #   si       ^akk#!())  F
  a$((**	  E #Na  *!*++  M
 ('a  %))++	  M ! akk##%%!%&&  F
 
 
 
 
 
 
 
 
 
r*   r   c            	           e Zd Z e ed          ej                                        d          Z e	 ed          e
 ed                    Z e ed          ej                                        dd ed	          
          Z e ed          ej                                        dd ed          
          Z e ed          ej                                        dd ed          
          Z e ed          ej                                        dd          Z G d d          Zd fd	Z fdZ xZS )r   rB   r   r0   r4   r6   RolezOperational roler/   r   Fz#Parent device of assigned interfacer8   Virtual machinezParent VM of assigned interfaceTerminationz#Device or virtual machine interfacez
Outside IPr3   c                       e Zd ZeZdZdS ) TunnelTerminationImportForm.Meta)tunnelrole
outside_ipr"   N)r#   r$   r%   TunnelTerminationr'   r(   r)   r*   r+   r,   rO   q   s        !
r*   r,   Nc                     t                      j        |g|R i | |r|                    d          rCt          j        j        di d| j        d         j         |d         i| j        d         _        d S |                    d          rEt          j        j        di d| j        d         j         |d         i| j        d         _        d S d S d S )Ndevicedevice__terminationvirtual_machinevirtual_machine__r)   
super__init__getr   rE   filterr(   r6   r4   r   selfdataargskwargs	__class__s       r+   r\   z$TunnelTerminationImportForm.__init__w   s   /////// 
	 xx!! 6?6G6N 7 7G$+h"7"EGGhX7 7M*333 +,, 6A6I6P 7 7Y4;7H+I+WYY[_`q[rs7 7M*333
	 
	 r*   c                     | j                             d          r| j         d         | j        _         t	                      j        |i |S )NrW   )cleaned_datar]   instancerW   r[   save)r`   rb   rc   rd   s      r+   rh   z TunnelTerminationImportForm.save   sL       // 	I(,(9-(HDM%uww|T,V,,,r*   N)r#   r$   r%   r   rC   rB   rE   rF   rP   r   TunnelTerminationRoleChoicesrQ   r   rU   r   rX   r   nonerW   r   rR   r,   r\   rh   __classcell__rd   s   @r+   r   r   J   s         akk##%%  F
 >aii,!&''  D
 ! akk##%%!9::  F *)a!""'++--!566  O &%a"''))!9::  K %$aoo"&&((	  J
 
 
 
 
 
 
 
     - - - - - - - - -r*   r   c                       e Zd Z e ed          e          Z e ed          e          Z e ed          e	d          Z
 e ed          e          Z G d d	          Zd
S )r   zAuthentication methodr0   r1   Encryption algorithmAuthentication algorithmFr0   r1   r5   Groupc                       e Zd ZeZdZdS )IKEProposalImportForm.Meta)	r   r!   authentication_methodencryption_algorithmauthentication_algorithmr<   sa_lifetimerA   r"   N)r#   r$   r%   IKEProposalr'   r(   r)   r*   r+   r,   ru      s        
r*   r,   N)r#   r$   r%   r   rC   AuthenticationMethodChoicesrv   EncryptionAlgorithmChoicesrw   AuthenticationAlgorithmChoicesrx   DHGroupChoicesr<   r,   r)   r*   r+   r   r      s        *Na'((+   *>a&''*    .~a*++.     
 Najj  E

 
 
 
 
 
 
 
 
 
r*   r   c                       e Zd Z e ed          e          Z e ed          ed          Z e	e
j                                        d ed                    Z G d	 d
          ZdS )r   Versionro   ModeFrr   r   zIKE proposal(s)r4   r6   r2   c                       e Zd ZeZdZdS )IKEPolicyImportForm.Meta)r   r!   versionmode	proposalspreshared_keyrA   r"   N)r#   r$   r%   	IKEPolicyr'   r(   r)   r*   r+   r,   r      s        
r*   r,   N)r#   r$   r%   r   rC   IKEVersionChoicesr   IKEModeChoicesr   r   rz   rE   rF   r   r,   r)   r*   r+   r   r      s        na	ll!  G >aii  D
 ,+$((**!%&&  I
 
 
 
 
 
 
 
 
 
r*   r   c                       e Zd Z e ed          ed          Z e ed          ed          Z G d d          Z	dS )r   rp   Frr   rq   c                       e Zd ZeZdZdS )IPSecProposalImportForm.Meta)r   r!   rw   rx   sa_lifetime_secondssa_lifetime_datarA   r"   N)r#   r$   r%   IPSecProposalr'   r(   r)   r*   r+   r,   r      s        
r*   r,   N)
r#   r$   r%   r   rC   r|   rw   r}   rx   r,   r)   r*   r+   r   r      s        )>a&''*  
  .~a*++.     
 
 
 
 
 
 
 
 
 
r*   r   c                       e Zd Z e ed          ed          Z eej	        
                                d ed                    Z G d d          Zd	S )
r   z0Diffie-Hellman group for Perfect Forward SecrecyFrr   r   zIPSec proposal(s)r   c                       e Zd ZeZdZdS )IPSecPolicyImportForm.Meta)r   r!   r   	pfs_grouprA   r"   N)r#   r$   r%   IPSecPolicyr'   r(   r)   r*   r+   r,   r      s        
r*   r,   N)r#   r$   r%   r   rC   r~   r   r   r   rE   rF   r   r,   r)   r*   r+   r   r      s        aBCC  I
 ,+&**,,!'((  I
 
 
 
 
 
 
 
 
 
r*   r   c                       e Zd Z e ed          e ed                    Z e ed          ej	        
                                d          Z e ed          ej	        
                                d          Z G d d	          Zd
S )r   r   zIPSec protocolr/   z
IKE policyr   rJ   zIPSec policyc                       e Zd ZeZdZdS )IPSecProfileImportForm.Meta)r   r   
ike_policyipsec_policyr!   rA   r"   N)r#   r$   r%   rH   r'   r(   r)   r*   r+   r,   r      s        
r*   r,   N)r#   r$   r%   r   rC   IPSecModeChoicesr   r   r   rE   rF   r   r   r   r,   r)   r*   r+   r   r      s        >aii !$%%  D
 %$aoo"&&((  J
 '&a$((**  L
 
 
 
 
 
 
 
 
 
r*   r   c                       e Zd Z e ed          ej                                        dd          Z e	 ed          e
 ed                    Z G d d	          Zd
S )r   r
   Fr   r3   Typez
L2VPN typer/   c                       e Zd ZeZdZdS )L2VPNImportForm.Meta)
identifierr   r    r?   typer!   rA   r"   N)r#   r$   r%   L2VPNr'   r(   r)   r*   r+   r,   r     s        &r*   r,   N)r#   r$   r%   r   rC   r
   rE   rF   r?   r   L2VPNTypeChoicesr   r,   r)   r*   r+   r   r      s          akk##%%	  F >aii !L//  D& & & & & & & & & &r*   r   c            	       j    e Zd Z eej                                        dd ed                    Z e ed          e	j                                        dd ed                    Z
 e ed	          ej                                        dd ed
                    Z e ed          ej                                        dd ed                    Z e ed          ej                                        dd ed                    Z G d d          Zd fd	Z fdZ xZS )r   Tr   r   )r4   r5   r6   r0   r   FzParent device (for interface)r8   rL   z&Parent virtual machine (for interface)r   z!Assigned interface (device or VM)r   zAssigned VLANc                       e Zd ZeZdZdS )L2VPNTerminationImportForm.Meta)l2vpnrU   rX   	interfacevlanr"   N)r#   r$   r%   L2VPNTerminationr'   r(   r)   r*   r+   r,   r   7  s         Tr*   r,   Nc                     t                      j        |g|R i | |r|                    d          rCt          j        j        di d| j        d         j         |d         i| j        d         _        d S |                    d          rEt          j        j        di d| j        d         j         |d         i| j        d         _        d S d S d S )NrU   rV   r   rX   rY   r)   rZ   r_   s       r+   r\   z#L2VPNTerminationImportForm.__init__;  s   /////// 
	 xx!! 4=4E4L 5 5G$+h"7"EGGhX5 5K(111 +,, 4?4G4N 5 5Y4;7H+I+WYY[_`q[rs5 5K(111
	 
	 r*   c                    t                                                       | j                            d          r6| j                            d          rt	          t          d                    | j        sP| j                            d          s6| j                            d          st	          t          d                    | j                            d          r6| j                            d          rt	          t          d                    | j                            d          s| j                            d          r@| j                            d          p| j                            d          | j        _        d S d S )NrU   rX   zBCannot import device and VM interface terminations simultaneously.r   r   z<Each termination must specify either an interface or a VLAN.z+Cannot assign both an interface and a VLAN.)r[   cleanrf   r]   r   rC   rg   assigned_object)r`   rd   s    r+   r   z L2VPNTerminationImportForm.cleanJ  sx     ** 	kt/@/D/DEV/W/W 	k!!$h"i"ijjj} 	ed&7&;&;K&H&H 	eDL]LaLabhLiLi 	e!!$b"c"cddd  -- 	T$2C2G2G2O2O 	T!!$Q"R"RSSS   -- 	p1B1F1Fv1N1N 	p,0,=,A,A+,N,N,oRVRcRgRghnRoRoDM)))	p 	pr*   ri   )r#   r$   r%   r   r   rE   rF   rC   r   r   rU   r   rX   r   rk   r   r   r   r,   r\   r   rl   rm   s   @r+   r   r     s       ""$$ajj	  E ! akk##%%!344  F *)a!""'++--!<==  O $#ann"''))!788  I aii!!##!O$$  DU U U U U U U U     p p p p p p p p pr*   r   N)$django.core.exceptionsr   django.utils.translationr   rC   dcim.modelsr   r   ipam.modelsr   r   netbox.formsr	   tenancy.modelsr
   utilities.forms.fieldsr   r   r   r   virtualization.modelsr   r   vpn.choices
vpn.models__all__r   r   r   r   r   r   r   r   r   r   r)   r*   r+   <module>r      s   2 2 2 2 2 2 6 6 6 6 6 6 ) ) ) ) ) ) ) ) ' ' ' ' ' ' ' ' . . . . . . ! ! ! ! ! ! n n n n n n n n n n n n = = = = = = = =        9 9 9 9 91 9 9 9$
 $
 $
 $
 $
, $
 $
 $
NB- B- B- B- B-"7 B- B- B-J
 
 
 
 
1 
 
 
6
 
 
 
 
/ 
 
 
.
 
 
 
 
3 
 
 
(
 
 
 
 
1 
 
 
&
 
 
 
 
2 
 
 
0& & & & &+ & & &&Cp Cp Cp Cp Cp!6 Cp Cp Cp Cp Cpr*   