
    "$                     ,   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d	lmZ ddlmZ d Zd Zd Zd Zd Zd Zd Zd Zd Z e	j8                  e	j:                  j<                        e	j>                   G d de	j@                                      Z! e	j8                  e	j:                  jD                         G d de!             Z# e	j8                  e	j:                  jH                         G d de#             Z%y)z#Command for updating health checks.    )absolute_import)division)unicode_literals)base_classes)health_checks_utils)base)scope)
exceptions)flags)logc                      dddS )NUpdate a TCP health check.z      *{command}* is used to update an existing TCP health check. Only
      arguments passed in will be updated on the health check. Other
      attributes will remain unaffected.
      )briefDESCRIPTION r       /lib/surface/compute/health_checks/update/tcp.py_DetailedHelpr      s     '
		
 	r   c                    t        j                  d      }|j                  | d       t        j                  |        t        j
                  | d       |rt        j                  |        |rt        j                  |        y y )NTCPupdate)operation_type)r   HealthCheckArgumentAddArgumentr   AddTcpRelatedUpdateArgsAddProtocolAgnosticUpdateArgs&AddHealthCheckSourceRegionsRelatedArgs AddHealthCheckLoggingRelatedArgs)parserinclude_log_configinclude_source_regionshealth_check_args       r   _Argsr#   ,   sk    ..u5vh?--f533FEB>>vF88@ r   c                     | j                   j                  d| j                  j                  |j	                         |j
                        fS )9Returns a request for fetching the existing health check.Get)healthCheckproject)apitools_clienthealthChecksmessagesComputeHealthChecksGetRequestNamer(   clienthealth_check_refs     r   _GetGetRequestr1   7   sI    

 
 
-
-u
//
7
7*//1&.. 8 0
1 1r   c                     | j                   j                  d| j                  j                  |j	                         ||j
                        fS )0Returns a request for updating the health check.Update)r'   healthCheckResourcer(   )r)   r*   r+    ComputeHealthChecksUpdateRequestr-   r(   r/   r0   replacements      r   _GetSetRequestr9   ?   sL    

 
 
-
-x
//
:
:*//1"-&.. ; 0
1 1r   c                     | j                   j                  d| j                  j                  |j	                         |j
                  |j                        fS )r%   r&   )r'   r(   region)r)   regionHealthChecksr+   #ComputeRegionHealthChecksGetRequestr-   r(   r;   r.   s     r   _GetRegionalGetRequestr>   H   sR    

 
 
3
3U
//
=
=*//1&..%,, > .
/ /r   c                     | j                   j                  d| j                  j                  |j	                         ||j
                  |j                        fS )r3   r4   )r'   r5   r(   r;   )r)   r<   r+   &ComputeRegionHealthChecksUpdateRequestr-   r(   r;   r7   s      r   _GetRegionalSetRequestrA   Q   sV    

 
 
3
3X
//
@
@*//1"-&..%,,	 A .
/ /r   c                 r   |j                   | j                  j                  j                  j                  k7  r,t        j                  d|j                   j                  z         |j                  r|j                  }n|j                  |j                  }nd}t        j                  ||j                        \  }}}|j                  r|j                  }	n%|j                  |j                  j                  }	nd}	|j                  r|j                  }
n%|j                  |j                  j                  }
nd}
|j                  j                  }|j                  /| j                  j                   j#                  |j                        }| j                  j                  |j                  || j                  j                  j                  j                  | j                  j!                  |	|
||||      |j$                  xs |j&                  |j(                  xs |j*                  |j,                  xs |j.                  |j0                  xs |j2                        }|r&t        j4                  | ||j6                        |_        |r0|j8                  }|j;                  d      r|j<                  }||_        |S )z'Returns a modified HealthCheck message.z<update tcp subcommand applied to health check with protocol N)requestresponseportportNameportSpecificationproxyHeader)namedescriptiontypetcpHealthCheckcheckIntervalSec
timeoutSechealthyThresholdunhealthyThresholdsource_regions)rK   r+   HealthCheckTypeValueValuesEnumr   core_exceptionsErrorrI   rJ   r   HandlePortRelatedFlagsForUpdaterL   rC   rD   rH   proxy_headerTCPHealthCheckProxyHeaderValueValuesEnumcheck_intervalrM   timeoutrN   healthy_thresholdrO   unhealthy_thresholdrP   ModifyLogConfig	logConfigsourceRegionsIsSpecifiedrQ   )r/   argsexisting_checkr    r!   rJ   rE   	port_nameport_specificationrC   rD   rW   new_health_checkrQ   s                 r   _Modifyrg   [   si    oo!!5599:


F  	!" " 
""K ,,KK(;##D.*G*G)I%$	% 
\\llG||++33GG	]]}}H}},,55HH..::,	"??11LLL__00??&&::>>__33." 4 $ ++N~/N/N:!:!:.. 8&7722 <(;;! 1 & !4!D!Dn.."0 #11N()**n%3"	r   c                    t        j                  |        | j                  xsR | j                  xsD | j                  xs6 | j
                  xs( | j                  xs | j                  xs | j                   }|r| j                  du xr |}d}|r| j                  d      rd}| j                  B| j                  5| j                  (| j                  |s|rt        j                   d      yyyyyy)zBValidates given args and raises exception if any args are invalid.NFrQ   Tz'At least one property must be modified.)r   CheckProtocolAgnosticArgsrE   rZ   r[   r\   r]   rW   use_serving_portenable_loggingra   rJ   rC   rD   rd   r
   ArgumentError)rb   r    r!   
args_unsetsource_regions_modifieds        r   _ValidateArgsro      s
    //5II ?!4!4 ? ?**?.2.F.F?%%?)-)>)>@* %%-<*J! 0 01A B" 
,,

--

..
 %


"
"#L
MM  & !    r   c                 |   |j                   }t        | ||       t        j                  d      }|j	                  | |j
                  t        j                  j                        }t        j                  |      rt        ||      }nt        ||      }|j                  |g      }t        || |d   ||      }	|d   |	k(  r=t        j                   j#                  dj%                  |d   j&                               |S t        j                  |      rt)        |||	      }
nt+        |||	      }
|j                  |
g      S )z<Issues the requests necessary for updating the health check.r   )default_scoper   z/No change requested; skipping update for [{0}].)r/   ro   r   r   ResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALr   IsRegionalHealthCheckRefr>   r1   MakeRequestsrg   r   statusPrintformatrI   rA   r9   )rb   holderr    r!   r/   r"   r0   get_requestobjects
new_objectset_requests              r   _Runr      s0   ==&(*@A..u5%77
FM,C,C,J,J 8 L 112BC(1ABK )9:K.'dGAJ 24J* QZ:JJFMM
 N112BC(1A:NK )9:FK			k]	++r   c                   <    e Zd ZdZdZdZ e       Zed        Z	d Z
y)r4   r   Tc                 F    t        || j                  | j                         y N)r#   _include_log_config_include_source_regions)clsr   s     r   ArgszUpdate.Args   s    	&#))3+F+FGr   c                     t        j                  | j                               }t        ||| j                  | j
                        S r   )r   ComputeApiHolderReleaseTrackr   r   r   )selfrb   r|   s      r   Runz
Update.Run   s=    **4+<+<+>?Ffd..0L0L r   N)__name__
__module____qualname____doc__r   r   r   detailed_helpclassmethodr   r   r   r   r   r4   r4      s3     # /-H Hr   r4   c                       e Zd Zy)
UpdateBetaNr   r   r   r   r   r   r   r           r   r   c                       e Zd Zy)UpdateAlphaNr   r   r   r   r   r     r   r   r   N)&r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   rt   0googlecloudsdk.command_lib.compute.health_checksr
   r   googlecloudsdk.corerT   r   r   r#   r1   r9   r>   rA   rg   ro   r   ReleaseTracksr   GADefaultUniverseOnlyUpdateCommandr4   BETAr   ALPHAr   r   r   r   <module>r      s   * &  ' 7 > ( E G B = #
A11//HVN<",J D%%(()T   *$ D%%**+  ,
 D%%++,*  -r   