
    >Tf                         d dl mZ d dlmZ d dlT d dlT d dlmZ dZ	 G d dej
                  Z G d d	ej
                  Zd
S )    )forms)gettext_lazy)*)get_field_value)InterfaceCommonFormModuleCommonFormc                        e Zd Z ej        dd ed                    Z ej        dee	 ed                    Z
 fdZ fdZ xZS )	r   NFzMAC address)empty_valuerequiredlabelMTU)r   	min_value	max_valuer   c                      t                      j        |i | t          | d          }|t          j        t          j        fv r
| j        d= d S |s| j        d= | j        d= | j        d= d S d S )Nmodetagged_vlans
vlan_groupuntagged_vlan)super__init__r   InterfaceModeChoicesMODE_ACCESSMODE_TAGGED_ALLfields)selfargskwargsinterface_mode	__class__s       6/var/www/html/netbox-4.1.3/netbox/dcim/forms/common.pyr   zInterfaceCommonForm.__init__   s    $)&))) )v66 2>@T@deeeN+++ 	,L)O,N+++	, 	,    c                    t                                                       d| j        v rdnd}| j                            d          }| j        d         t          j        k    r%|r#t          j        dt          d          i          | j        d         t          j	        k    rg | j        d<   d S | j        d         t          j
        k    rp|rpd | j        |         j        gfd|D             }|rNt          j        dt          d                              d                    |          	          i          d S d S d S )
Ndevicevirtual_machiner   r   z6An access interface cannot have tagged VLANs assigned.c                 @    g | ]}|j         vt          |          S  )sitestr).0vvalid_sitess     r    
<listcomp>z-InterfaceCommonForm.clean.<locals>.<listcomp><   s+    WWWQV;=V=VSVV=V=V=Vr!   zsThe tagged VLANs ({vlans}) must belong to the same site as the interface's parent device/VM, or they must be globalz, )vlans)r   cleancleaned_datagetr   r   r   ValidationError_r   MODE_TAGGEDr'   formatjoin)r   parent_fieldr   invalid_vlansr+   r   s       @r    r.   zInterfaceCommonForm.clean)   sl   #+t/@#@#@xxFW(,,^<< V$(<(HHH\H'RSS)   
 v&*>*NNN02Dn--- v&*>*JJJ|J!2<!@!EFKWWWW\WWWM +"A1% % f499]#;#;f<<	-    KJJJ r!   )__name__
__module____qualname__r   	CharFieldr2   mac_addressIntegerFieldINTERFACE_MTU_MININTERFACE_MTU_MAXmtur   r.   __classcell__r   s   @r    r   r      s        !%/a  K
 %
##ahh	  C, , , , ,        r!   r   c                   $     e Zd Zd Z fdZ xZS )r   c                     g }|r-|                     |           |j        r|j        j        }nd }|-|                                 |S )N)appendmodule
module_bayreverse)r   rG   module_bayss      r    _get_module_bay_treez%ModuleCommonForm._get_module_bay_treeI   sd     	"z***  "'.9

!
  	" 	r!   c           
         t                                                       | j                            d          }| j                            d          }| j                            d          }| j                            d          }| j                            d          }|rd| j        _        | j        s| j        j        s|sd| j        _        d S | 	                    |          }dD ]\  }}d t          ||                                          D             }	t          ||                                          D ]}
|
j        }t          |
j        v r|j        s!t          j        t#          d	                    t%          |          |
j                            t                    k    r`t          j        t#          d
                              t%          |          |
j                            t                                        |D ]#}|                    t          |j        d          }$|	                    |          }|rI|rG|j        r@t          j        t#          d                              |
j        j        |                    |sD||	v r@t          j        t#          d                              |
j        j        |                    d S )Nreplicate_componentsadopt_componentsr#   module_typerG   T))consoleporttemplatesconsoleports)consoleserverporttemplatesconsoleserverports)interfacetemplates
interfaces)powerporttemplates
powerports)poweroutlettemplatespoweroutlets)rearporttemplates	rearports)frontporttemplates
frontportsc                     i | ]
}|j         |S r&   )name)r)   	components     r    
<dictcomp>z*ModuleCommonForm.clean.<locals>.<dictcomp>s   s)     $ $ $.7		$ $ $r!   zWCannot install module with placeholder values in a module bay with no position defined.zsCannot install module with placeholder values in a module bay tree {level} in tree but {tokens} placeholders given.)leveltokens   z=Cannot adopt {model} {name} as it already belongs to a module)modelr^   z%A {model} named {name} already exists)r   r.   r/   r0   instance_adopt_componentserrorspk_disable_replicationrJ   getattrallr^   MODULE_TOKENpositionr   r1   r2   lencountr4   replacerF   component_modelr8   )r   rL   rM   r#   rN   rG   rI   	templatescomponent_attributeinstalled_componentstemplateresolved_nameexisting_itemr   s                r    r.   zModuleCommonForm.cleanU   s!   #0445KLL,001CDD"&&x00'++M::&**<88
 	3.2DM+ ; 	$-* 	2F 	15DM.F//
;;/
 4	 4	*I*$ $;B6K^;_;_;c;c;e;e$ $ $ 
 $K;;??AA % % (8=00%. #3wxx   ;''8=+>+>|+L+LLL#3  T  U  U  \  \&)+&6&6x}?R?RS_?`?` \     '2 d d
(5(=(=lJL_ab(c(c 4 8 8 G G $  -:N /YZZaa"*":"C!. b     ( M=Q,Q,Q/ABBII"*":"C!. J    A%4	 4	r!   )r8   r9   r:   rJ   r.   rA   rB   s   @r    r   r   G   sP        
 
 
H H H H H H H H Hr!   r   N)djangor   django.utils.translationr   r2   dcim.choicesdcim.constantsutilities.formsr   __all__Formr   r   r&   r!   r    <module>r      s          6 6 6 6 6 6         + + + + + +6 6 6 6 6%* 6 6 6rV V V V Vuz V V V V Vr!   