
    *                     ,   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 HTTPS health check.z      *{command}* is used to update an existing HTTPS health check. Only
      arguments passed in will be updated on the health check. Other
      attributes will remain unaffected.
      )briefDESCRIPTION r       1lib/surface/compute/health_checks/update/https.py_DetailedHelpr      s     )
		
 	r   c                 4   t        j                  d      }|j                  | d       t        j                  | |       t        j
                  | d       t        j                  |        |rt        j                  |        |rt        j                  |        yy)z Adds all the args in the parser.HTTPSupdate)operation_typeN)	r   HealthCheckArgumentAddArgumentr   AddHttpRelatedUpdateArgsAddProtocolAgnosticUpdateArgsAddHttpRelatedResponseArg&AddHealthCheckSourceRegionsRelatedArgs AddHealthCheckLoggingRelatedArgs)parserinclude_log_configinclude_weighted_load_balancinginclude_source_regionshealth_check_args        r   _Argsr%   ,   s     ..w7vh?..v/NP33FGD//7>>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   _GetGetRequestr3   ?   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*   r1   r2   replacements      r   _GetSetRequestr;   G   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=   r0   s     r   _GetRegionalGetRequestr@   P   sR    

 
 
3
3U
//
=
=*//1&..%,, > .
/ /r   c                     | j                   j                  d| j                  j                  |j	                         ||j
                  |j                        fS )r5   r6   )r)   r7   r*   r=   )r+   r>   r-   &ComputeRegionHealthChecksUpdateRequestr/   r*   r=   r9   s      r   _GetRegionalSetRequestrC   Y   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}|j                  r|j                  }n%|j                  |j                  j                  }nd}t        j                  ||j                        \  }}	}
|rV|j                  j                  }|j                  d      r/| j                  j                  j!                  |j"                        }|j                  j$                  }|j&                  /| j                  j                  j)                  |j&                        }|j*                  r|j*                  }n%|j*                  |j                  j*                  }nd}| j                  j                  |||	|j,                  xs |j                  j.                  |
||      }|r|_        | j                  j                  |j                  || j                  j                  j                  j                  ||j0                  xs |j2                  |j4                  xs |j6                  |j8                  xs |j:                  |j<                  xs |j>                        }|r&t        j@                  | ||jB                        |_!        |r0|jD                  }|j                  d      r|jF                  }||_"        |S )z'Returns a modified HealthCheck message.z>update https subcommand applied to health check with protocol Nweight_report_mode)hostportportNamerequestPathportSpecificationproxyHeaderresponse)namedescriptiontypehttpsHealthCheckcheckIntervalSec
timeoutSechealthyThresholdunhealthyThresholdsource_regions)$rO   r-   HealthCheckTypeValueValuesEnumr   core_exceptionsErrorrM   rN   rF   rP   r   HandlePortRelatedFlagsForUpdateweightReportModeIsSpecifiedHTTPSHealthCheckWeightReportModeValueValuesEnumrE   rK   proxy_headerProxyHeaderValueValuesEnumrL   request_pathrI   check_intervalrQ   timeoutrR   healthy_thresholdrS   unhealthy_thresholdrT   ModifyLogConfig	logConfigsourceRegionsrU   )r1   argsexisting_checkr!   r"   r#   rN   rF   rG   	port_nameport_specificationrE   r_   rL   https_health_checknew_health_checkrU   s                    r   _Modifyro   c   s    oo!!55;;<


H  	!" " 
""K ,,KK	YY99Dyy**//DD(;##D.*I*I)K%$	% %'88II,-!??;;[[

!
!#  00<<,	"((CC	  
]]}}H}}..77HH77$$ ?!22>>* 8  %*<'__00??&&::@@)++N~/N/N:!:!:.. 8&7722 <(;; 1  !4!D!Dn.."0 #11N()**n%3"	r   c                 2   t        j                  |        | j                  xs` | 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}d}|r| j                  d      rd}| j                  E| j                  8| j                  +| j                  |s|s|rt!        j"                  d      yyyyyyy)zBValidates given args and raises exception if any args are invalid.NFrU   TrE   z'At least one property must be modified.)r   CheckProtocolAgnosticArgsrG   ra   rb   rc   rd   re   r_   use_serving_portenable_loggingr\   rN   rF   rL   rk   r
   ArgumentError)ri   r!   r"   r#   
args_unsetsource_regions_modifiedweight_report_mode_modifieds          r   _ValidateArgsrx      s>    //5II *!2!2 *d6I6I *LL*$($:$:*,,*040A0A* ))+*
 %%-<*J! 0 01A B" %$)9)9:N)O"& 
))

--

..
 )%


"
"#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}].)r1   rx   r   r   ResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALr   IsRegionalHealthCheckRefr@   r3   MakeRequestsro   r   statusPrintformatrM   rC   r;   )ri   holderr!   r"   r#   r1   r$   r2   get_requestobjects
new_objectset_requests               r   _Runr      s?    ==&
%	 ..w7%77
FM,C,C,J,J 8 L 112BC(1ABK )9:K.'
aj%* 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dZ e       Ze	d        Z
d Zy)r6   r   TFc                 \    t        || j                  | j                  | j                         y N)r%   _include_log_config _include_weighted_load_balancing_include_source_regions)clsr    s     r   ArgszUpdate.Args$  s(    	,,##	r   c                     t        j                  | j                               }t        ||| j                  | j
                  | j                        S r   )r   ComputeApiHolderReleaseTrackr   r   r   r   )selfri   r   s      r   Runz
Update.Run-  sI    **4+<+<+>?F  --$$ r   N)__name__
__module____qualname____doc__r   r   r   r   detailed_helpclassmethodr   r   r   r   r   r6   r6     s7     %%*" /- r   r6   c                       e Zd ZdZy)
UpdateBetaFNr   r   r   r   r   r   r   r   r   8  s
     &+"r   r   c                       e Zd ZdZy)UpdateAlphaTNr   r   r   r   r   r   >  s
     &*"r   r   N)&r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   r}   0googlecloudsdk.command_lib.compute.health_checksr
   r   googlecloudsdk.corerX   r   r   r%   r3   r;   r@   rC   ro   rx   r   ReleaseTracksr   GADefaultUniverseOnlyUpdateCommandr6   BETAr   ALPHAr   r   r   r   <module>r      s   * &  ' 7 > ( E G B = #
A&11//\~"NJ0,f D%%(()T   *8 D%%**++ + ,+
 D%%++,** * -*r   