
                             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<                         G d de	j>                               Z  e	j8                  e	j:                  jB                         G d de              Z" e	j8                  e	j:                  jF                         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 SSL health check.z      *{command}* is used to update an existing SSL 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/ssl.py_DetailedHelpr      s     '
		
 	r   c                     t        j                  d      }|j                  | d       t        j                  |        t        j
                  | d       |rt        j                  |        y y )NSSLupdate)operation_type)r   HealthCheckArgumentAddArgumentr   AddTcpRelatedUpdateArgsAddProtocolAgnosticUpdateArgs AddHealthCheckLoggingRelatedArgs)parserinclude_log_confighealth_check_args      r   _Argsr!   ,   sZ    ..u5vh?--f533FEB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   _GetGetRequestr/   5   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-   r.   replacements      r   _GetSetRequestr7   =   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&   r9   r,   s     r   _GetRegionalGetRequestr<   F   sR    

 
 
3
3U
//
=
=*//1&..%,, > .
/ /r   c                     | j                   j                  d| j                  j                  |j	                         ||j
                  |j                        fS )r1   r2   )r%   r3   r&   r9   )r'   r:   r)   &ComputeRegionHealthChecksUpdateRequestr+   r&   r9   r5   s      r   _GetRegionalSetRequestr?   O   sV    

 
 
3
3X
//
@
@*//1"-&..%,,	 A .
/ /r   c                    |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                        |_        |S )z'Returns a modified HealthCheck message.z<update ssl subcommand applied to health check with protocol N)requestresponseportportNameportSpecificationproxyHeader)namedescriptiontypesslHealthCheckcheckIntervalSec
timeoutSechealthyThresholdunhealthyThreshold)rI   r)   HealthCheckTypeValueValuesEnumr   core_exceptionsErrorrG   rH   r   HandlePortRelatedFlagsForUpdaterJ   rA   rB   rF   proxy_headerSSLHealthCheckProxyHeaderValueValuesEnumcheck_intervalrK   timeoutrL   healthy_thresholdrM   unhealthy_thresholdrN   ModifyLogConfig	logConfig)r-   argsexisting_checkr   rH   rC   	port_nameport_specificationrA   rB   rT   new_health_checks               r   _Modifyrb   Y   s6    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	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 |}| j                  ?| j                  2| j                  %| j                  |rt        j                  d      yyyyy)zBValidates given args and raises exception if any args are invalid.Nz'At least one property must be modified.)r   CheckProtocolAgnosticArgsrC   rW   rX   rY   rZ   rT   use_serving_portenable_loggingrH   rA   rB   r_   r
   ArgumentError)r]   r   
args_unsets      r   _ValidateArgsri      s    //5II ?!4!4 ? ?**?.2.F.F?%%?)-)>)>@* %%-<*J
4<<#7
mm 6:

"
"#L
MM <F 6 $8r   c                 x   |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-   ri   r   r   ResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALr   IsRegionalHealthCheckRefr<   r/   MakeRequestsrb   r   statusPrintformatrG   r?   r7   )
r]   holderr   r-   r    r.   get_requestobjects
new_objectset_requests
             r   _Runr{      s'   ==&()..u5%77
FM,C,C,J,J 8 L 112BC(1ABK )9:K.'vtWQZ1CD*
 QZ:JJFMM
 N112BC(1A:NK )9:FK			k]	++r   c                   8    e Zd ZdZdZ e       Zed        Zd Z	y)r2   r   Tc                 0    t        || j                         y N)r!   _include_log_config)clsr   s     r   ArgszUpdate.Args   s    	&#))*r   c                 v    t        j                  | j                               }t        ||| j                        S r~   )r   ComputeApiHolderReleaseTrackr{   r   )selfr]   rv   s      r   Runz
Update.Run   s0    **4+<+<+>?Ffd6677r   N)
__name__
__module____qualname____doc__r   r   detailed_helpclassmethodr   r   r   r   r   r2   r2      s)    "/-+ +8r   r2   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	   rn   0googlecloudsdk.command_lib.compute.health_checksr
   r   googlecloudsdk.corerQ   r   r   r!   r/   r7   r<   r?   rb   ri   r{   ReleaseTracksr   GAUpdateCommandr2   BETAr   ALPHAr   r   r   r   <module>r      s    * &  ' 7 > ( E G B = #
A11//?DN ,D D%%(()8T 8 *8 D%%**+  ,
 D%%++,*  -r   