
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z dd	l	mZ dd
lmZ dZdZdZdZdddZ G d dej,                        Zy)zRevision-specific printer.    )absolute_import)division)print_function)unicode_literals)container_resource)revision)!container_and_volume_printer_util)k8s_object_printer_util)custom_printer_baser   zCPU is always allocatedz/CPU is only allocated during request processingh2czFirst GenerationzSecond Generation)gen1gen2c                       e Zd ZdZd Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zed        Ze	 ddej                   dej$                  fd       Zed        Zy)RevisionPrinterzPrints the run Revision in a custom human-readable format.

  Format specific to Cloud Run revisions. Only available on Cloud Run commands
  that print revisions.
  c           
         t        j                  t        j                  |      t        j                  |j
                        d| j                  |      t        j                  |      t        j                  |      g      }|S )z@Transform a service into the output structure of marker classes. )
cpLinesk8s_utilBuildHeader	GetLabelslabelsTransformSpecFormatReadyMessager   CurrentMinInstances)selfrecordfmts      ?lib/googlecloudsdk/command_lib/run/printers/revision_printer.py	TransformzRevisionPrinter.Transform*   si    
((V$6==)6"##F+++F3 C J    c                 R    | j                   dj                  | j                         S y )Nz{}s)timeoutformatr   s    r   
GetTimeoutzRevisionPrinter.GetTimeout6   s"    ~~!\\&..))r!   c                 V    | j                   j                  t        j                  d      S N )annotationsgetr   MIN_SCALE_ANNOTATIONr%   s    r   GetMinInstanceszRevisionPrinter.GetMinInstances<   !    !!("?"?DDr!   c                 V    | j                   j                  t        j                  d      S r(   )r*   r+   r   MAX_SCALE_ANNOTATIONr%   s    r   GetMaxInstanceszRevisionPrinter.GetMaxInstances@   r.   r!   c                     | j                   j                  t        j                        }|sy|j	                  d      d   }|S )Nr)   /)r*   r+   r   CMEK_KEY_ANNOTATIONsplit)r   cmek_key	cmek_names      r   GetCMEKzRevisionPrinter.GetCMEKD   s>    !!%%&8&L&LMHs#B'Ir!   c                     | j                   j                  t        j                        }|sy|j	                         dk(  rt
        S t        S )Nr)   false)r*   r+   r   CPU_THROTTLE_ANNOTATIONlowerCPU_ALWAYS_ALLOCATED_MESSAGECPU_THROTTLED_MESSAGE)r   cpu_throttleds     r   GetCpuAllocationz RevisionPrinter.GetCpuAllocationL   sF    &&**22M 				'	)))""r!   c                 d    | j                   j                  D ]  }|j                  t        k(  s y y)NEnabledr)   )	containerportsnameHTTP2_PORT_NAME)r   ports     r   GetHttp2EnabledzRevisionPrinter.GetHttp2EnabledX   s,      &&	o	% ' r!   c                 R    t        j                  |       }|t        v r	t        |   S |S N)r   GetExecutionEnvironmentEXECUTION_ENV_VALS)r   execution_env_values     r   GetExecutionEnvzRevisionPrinter.GetExecutionEnv_   s.    "::6B00 344r!   c                 V    | j                   j                  t        j                  d      S r(   )r*   r+   r   SESSION_AFFINITY_ANNOTATIONr%   s    r   GetSessionAffinityz"RevisionPrinter.GetSessionAffinityf   s!    !!("F"FKKr!   c                 ,    t        j                  |       S rK   )r   GetThreatDetectionEnabledr%   s    r   rT   z)RevisionPrinter.GetThreatDetectionEnabledj   s    --f55r!   r   returnc                 H   d| j                   j                  fd| j                  fg}|s=|j                  dt        j                  |       fdt        j                  |       fg       |j                  dt        j                  | j                        fdt        j                  |       fdt        j                  | j                        fdt        j                  |       fd	t        j                  |       fd
t        j                  |       fdt        j                  |       fdt        j!                  |       fdt#        j$                  |       fdt        j'                  |       fg
       t)        j*                  t#        j,                  |       t)        j.                  |      g      S )NzService accountConcurrencyzMin instanceszMax instanceszSQL connectionsTimeoutz
VPC accessCMEKzHTTP/2 EnabledzCPU AllocationzExecution EnvironmentzSession AffinityVolumeszThreat Detection)specserviceAccountNameconcurrencyextendr   r-   r1   r   GetCloudSqlInstancesr*   r&   GetVpcNetworkr9   rI   rA   rO   rR   container_util
GetVolumesrT   r   r   GetContainersLabeled)r   manual_scaling_enabledr   s      r   r   zRevisionPrinter.TransformSpecn   s}   
 
FKK::;	**+-F "mmO;;FC
DO;;FC
D 	 MM))&*<*<=	
 
O..v67	x--f.@.@AB	((01	?::6BC	?;;FCD#++F3	

 ..v6	
 
N--f56	_FFvNO' * 88^11&92::f;MNOOr!   c                 \    t        j                  dt        | j                  dd       fg      S )NzCurrent Min InstancesdesiredReplicas)r   rd   getattrstatusr%   s    r   r   z#RevisionPrinter.CurrentMinInstances   s1    ::#FMM#4d;	
  r!   N)F)__name__
__module____qualname____doc__r    staticmethodr&   r-   r1   r9   rA   rI   rO   rR   rT   r   Revisionr   r   r   r    r!   r   r   r   #   s   
  
 E E E E   	# 	#     L L 6 6 8= P P	xx P  PD  r!   r   N)rm   
__future__r   r   r   r   googlecloudsdk.api_lib.runr   r   'googlecloudsdk.command_lib.run.printersr	   ra   r
   r   googlecloudsdk.core.resourcer   r   REVISION_PRINTER_FORMATr>   r?   rG   rM   CustomPrinterBaser   rp   r!   r   <module>rw      s\    ! &  % ' 9 / g W B$ 8 I 0:MN ub** ur!   