
    >Tf&              	       ,   d dl mZ d dlmZ d dlmZ d dlmZ d dl	T d dl
mZ d dlmZmZmZ d dlmZmZmZmZmZmZ d d	lmZ d
Z G d de          Z G d deee          Z G d de          Z G d deeee          Z G d deeeee          ZdS )    )ValidationError)models)reverse)gettext_lazy)*)CabledObjectModel)ChangeLoggedModelOrganizationalModelPrimaryModel)ContactsMixinCustomFieldsMixinCustomLinksMixinExportTemplatesMixinImageAttachmentsMixin	TagsMixin)
ColorField)CircuitCircuitGroupCircuitGroupAssignmentCircuitTerminationCircuitTypec                   ^    e Zd ZdZ e ed          d          Zd Z G d d          ZdS )	r   z
    Circuits can be organized by their functional role. For example, a user might wish to define CircuitTypes named
    "Long Haul," "Metro," or "Out-of-Band".
    colorT)verbose_nameblankc                 0    t          d| j        g          S )Nzcircuits:circuittypeargsr   pkselfs    =/var/www/html/netbox-4.1.3/netbox/circuits/models/circuits.pyget_absolute_urlzCircuitType.get_absolute_url   s    -TWI>>>>    c                   >    e Zd ZdZ ed          Z ed          ZdS )CircuitType.Metanamezcircuit typezcircuit typesN__name__
__module____qualname__ordering_r   verbose_name_plural r%   r#   Metar'   "   s4        q((a00r%   r2   N)	r+   r,   r-   __doc__r   r/   r   r$   r2   r1   r%   r#   r   r      s{          JQwZZ  E
? ? ?1 1 1 1 1 1 1 1 1 1r%   r   c                       e Zd ZdZ ej        d ed           ed                    Z ej        dej	        d          Z
 ej        d	ej	        dd
d
          Z ej        dej	        d          Z ej         ed          deej                  Z ej        dej	        dd
d
          Z ej        d
d
 ed                    Z ej        d
d
 ed                    Z ej        d
d
 ed           ed                    Z ej        dej        ddd
d
          Z ej        dej        ddd
d
          ZdZdZ G d d          Zd Zd  Zd! Z fd"Z xZ S )#r   a:  
    A communications circuit connects two points. Each Circuit belongs to a Provider; Providers may have multiple
    circuits. Each circuit is also assigned a CircuitType and a Site, and may optionally be assigned to a particular
    ProviderAccount. Circuit port speed and commit rate are measured in Kbps.
    d   z
circuit IDzUnique circuit ID)
max_lengthr   	help_textcircuits.Providercircuitsto	on_deleterelated_namezcircuits.ProviderAccountTr;   r<   r=   r   nullr   status2   )r   r6   choicesdefaulttenancy.Tenant	installed)r   r?   r   
terminateszcommit rate (Kbps)zCommitted rater   r?   r   r7   zcircuits.CircuitTermination+F)r;   r<   r=   editabler   r?   )	providerprovider_accounttyper@   tenantinstall_datetermination_datecommit_ratedescription)zcircuits.CircuitTyper8   c                       e Zd Zg dZ ej        dd           ej        dd          fZ ed          Z ed          Z	d	S )
Circuit.Meta)rJ   rK   cid)rJ   rT   z+%(app_label)s_%(class)s_unique_provider_cidfieldsr)   )rK   rT   z2%(app_label)s_%(class)s_unique_provideraccount_cidcircuitr9   N
r+   r,   r-   r.   r   UniqueConstraintconstraintsr/   r   r0   r1   r%   r#   r2   rS   }   s{        :::#F#*B   $F#2I  	
 q||a
mmr%   r2   c                     | j         S N)rT   r!   s    r#   __str__zCircuit.__str__   s	    xr%   c                 0    t          d| j        g          S )Nzcircuits:circuitr   r   r!   s    r#   r$   zCircuit.get_absolute_url   s    )	::::r%   c                 J    t           j                            | j                  S r\   )CircuitStatusChoicescolorsgetr@   r!   s    r#   get_status_colorzCircuit.get_status_color   s    #*..t{;;;r%   c                     t                                                       | j        r&| j        | j        j        k    rt	          ddi          d S d S )NrK   z:The assigned account must belong to the assigned provider.)supercleanrK   rJ   r   r"   	__class__s    r#   rf   zCircuit.clean   sY      	vT]d6K6T%T%T!#57s"tuuu	v 	v%T%Tr%   )!r+   r,   r-   r3   r   	CharFieldr/   rT   
ForeignKeyPROTECTrJ   rK   rL   r`   STATUS_ACTIVEr@   rM   	DateFieldrN   rO   PositiveIntegerFieldrP   SET_NULLtermination_atermination_zclone_fieldsprerequisite_modelsr2   r]   r$   rc   rf   __classcell__rh   s   @r#   r   r   (   s        
 &
Q|__!'((  C
 !v .  H
 )v(%.   6.  D
 VQx[[$$2	  F V.  F $6#Q{^^  L
 (v'Q|__  
 .&-Q+,,!$%%	  K &F%(/  M &F%(/  ML
, , , , , , , ,  ; ; ;< < <v v v v v v v v vr%   r   c                   l    e Zd ZdZ ej        dej        ddd          Z G d d          Zd Z	d	 Z
d
S )r   z1
    An administrative grouping of Circuits.
    rD   circuit_groupsTr>   c                   >    e Zd ZdZ ed          Z ed          ZdS )CircuitGroup.Metar(   zcircuit groupzcircuit groupsNr*   r1   r%   r#   r2   ry      s5        q))a 011r%   r2   c                     | j         S r\   r(   r!   s    r#   r]   zCircuitGroup.__str__   s
    yr%   c                 0    t          d| j        g          S )Nzcircuits:circuitgroupr   r   r!   s    r#   r$   zCircuitGroup.get_absolute_url   s    .dgY????r%   N)r+   r,   r-   r3   r   rj   rk   rM   r2   r]   r$   r1   r%   r#   r   r      s          V.%  F2 2 2 2 2 2 2 2
  @ @ @ @ @r%   r   c                       e Zd ZdZ ej        eej        d          Z ej        e	ej        d          Z
 ej         ed          ded          ZdZ G d	 d
          Zd Zd ZdS )r   zN
    Assignment of a Circuit to a CircuitGroup with an optional priority.
    assignments)r<   r=   priorityrA   T)r   r6   rB   r   )circuits.Circuitzcircuits.CircuitGroupc                   d    e Zd ZdZ ej        dd          fZ ed          Z ed          Z	dS )CircuitGroupAssignment.Meta)grouprW   r~   r    )rW   r   z,%(app_label)s_%(class)s_unique_circuit_grouprU   zCircuit group assignmentzCircuit group assignmentsNrX   r1   r%   r#   r2   r      s\        9#F#+C  
 q344a ;<<r%   r2   c                 v    | j         r| j         d|                                  dS t          | j                  S )Nz ())r~   r   get_priority_displaystrr!   s    r#   r]   zCircuitGroupAssignment.__str__   s@    = 	CjBBD$=$=$?$?BBBB4:r%   c                 0    t          d| j        g          S )Nzcircuits:circuitgroupassignmentr   r   r!   s    r#   r$   z'CircuitGroupAssignment.get_absolute_url   s    8yIIIIr%   N)r+   r,   r-   r3   r   rj   r   CASCADErW   r   r   ri   r/   CircuitPriorityChoicesr~   rs   r2   r]   r$   r1   r%   r#   r   r      s           f."  G
 F."  E
  vQz]]&	  H
	= 	= 	= 	= 	= 	= 	= 	=  
J J J J Jr%   r   c                       e Zd Z ej        dej        d          Z ej        de e	d                    Z
 ej        dej        dd	d	
          Z ej        dej        dd	d	
          Z ej         e	d          d	d	 e	d                    Z ej        d	d	 e	d           e	d                    Z ej        dd	 e	d           e	d                    Z ej        dd	 e	d           e	d                    Z ej         e	d          dd	          Z G d d          Zd Zd Z fd Z fd!Zed"             Zd# Z xZS )$r   r   terminationsr:      termination)r6   rB   r   z	dcim.Sitecircuit_terminationsTr>   zcircuits.ProviderNetworkzport speed (Kbps)zPhysical circuit speed)r   r   r?   r7   zupstream speed (Kbps)z,Upstream speed, if different from port speedrG   rA   zcross-connect IDzID of the local cross-connect)r6   r   r   r7   r5   zpatch panel/port(s)z!Patch panel ID and port number(s)rQ      )r   r6   r   c                   h    e Zd ZddgZ ej        dd          fZ ed          Z ed          Z	dS )	CircuitTermination.MetarW   	term_siderW   r   z0%(app_label)s_%(class)s_unique_circuit_term_siderU   zcircuit terminationzcircuit terminationsNrX   r1   r%   r#   r2   r     sa        {+#F#/G  
 q.//a 677r%   r2   c                 $    | j          d| j         S )Nz: Termination r   r!   s    r#   r]   zCircuitTermination.__str__)  s    ,>>dn>>>r%   c                 0    t          d| j        g          S )Nzcircuits:circuitterminationr   r   r!   s    r#   r$   z#CircuitTermination.get_absolute_url,  s    4DG9EEEEr%   c                     t                                                       | j        #| j        t	          t          d                    | j        r#| j        rt	          t          d                    d S d S )NzIA circuit termination must attach to either a site or a provider network.zJA circuit termination cannot attach to both a site and a provider network.)re   rf   siteprovider_networkr   r/   rg   s    r#   rf   zCircuitTermination.clean/  s     9!6!>!!$o"p"pqqq9 	s. 	s!!$p"q"qrrr	s 	s 	s 	sr%   c                 b    t                                          |          }| j        |_        |S r\   )re   to_objectchangerW   related_object)r"   actionobjectchangerh   s      r#   r   z"CircuitTermination.to_objectchange8  s*    ww..v66&*l#r%   c                     | j         S r\   )rW   r!   s    r#   parent_objectz CircuitTermination.parent_object=  s
    |r%   c                     | j         dk    rdnd}	 t          j                            d                              | j        |          S # t          j        $ r Y d S w xY w)NAZr   r   )r   r   objectsprefetch_relatedrb   rW   DoesNotExist)r"   	peer_sides     r#   get_peer_terminationz'CircuitTermination.get_peer_terminationA  sz    >S00CCc		%->>vFFJJ# K    ". 	 	 	44	s   8A
 
AA)r+   r,   r-   r   rj   r   rW   ri   CircuitTerminationSideChoicesr/   r   rk   r   r   rn   
port_speedupstream_speedxconnect_idpp_inforQ   r2   r]   r$   rf   r   propertyr   r   rt   ru   s   @r#   r   r      s         f.#  G
 ! -Q}%%  I
 6.+  D )v(%.+   -,Q*++!,--	  J 1V0Q.//!BCC	  N #&"Q)**!344	  K fQ,--!788	  G #&"Q}%%  K	8 	8 	8 	8 	8 	8 	8 	8? ? ?F F Fs s s s s    
   X      r%   r   N)django.core.exceptionsr   	django.dbr   django.urlsr   django.utils.translationr   r/   circuits.choicesdcim.modelsr   netbox.modelsr	   r
   r   netbox.models.featuresr   r   r   r   r   r   utilities.fieldsr   __all__r   r   r   r   r   r1   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  N  N  N  N  N  N  N  N  N  N  N  N  N  N ' ' ' ' ' '1 1 1 1 1% 1 1 1&qv qv qv qv qvm2L qv qv qvh@ @ @ @ @& @ @ @0*J *J *J *J *J.0DiQb *J *J *JZh h h h hh h h h hr%   