
                            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dlmZ dd
lmZ d Zd Zd Zd Z ej4                  ej6                  j8                  ej6                  j:                  ej6                  j<                         G d dej>                               Z y)z)Command for updating target HTTP proxies.    )absolute_import)division)unicode_literals)encoding)base_classes)target_proxies_utils)base)
exceptions)flags)scope)target_http_proxies_utilsc                      ddddS )NUpdate a target HTTP proxy.a        *{command}* is used to change the URL map of existing target
      HTTP proxies. A target HTTP proxy is referenced by one or more
      forwarding rules which specify the network traffic that the proxy
      is responsible for routing. The target HTTP proxy points to a URL
      map that defines the rules for routing the requests. The URL map's
      job is to map URLs to backend services which handle the actual
      requests.
      aC        If there is an already-created URL map with the name URL_MAP, update a
      global target HTTP proxy pointing to this map by running:

        $ {command} PROXY_NAME --url-map=URL_MAP

      Update a regional target HTTP proxy by running:

        $ {command} PROXY_NAME --url-map=URL_MAP --region=REGION_NAME
      )briefDESCRIPTIONEXAMPLES r       1lib/surface/compute/target_http_proxies/update.py_DetailedHelpr   !   s    ,
	

 r   c           	         |j                   }|j                  | |j                  t        j                  j
                  t        j                  |            }t        j                  | |||j                        }t        j                  |      rd}| j                  d      rd}n| j                  d      rd}|t        j                  |d      |j                  j                  |j                   |j"                  |j%                         |j                  j'                  |j)                               	      }|j*                  j,                  }	|j/                  |	d
|fg      }
|
S t1        ||      }t3        j4                  |      }g }| j6                  r|j)                         |_        | j                  d      r| j:                  |_        n)| j                  d      rd|_        |j?                  d       ||k7  rtA        ||||      S y)z8Issues requests necessary to update Target HTTP Proxies.)default_scopescope_listerNhttp_keep_alive_timeout_secz--http-keep-alive-timeout-sec!clear_http_keep_alive_timeout_secz#--clear-http-keep-alive-timeout-seczIhttp keep alive timeout is not patchable for regional target HTTP proxies)urlMap)projectregiontargetHttpProxyurlMapReference	SetUrlMaphttpKeepAliveTimeoutSec)!clientResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALcompute_flagsGetDefaultScopeListerr   ResolveTargetHttpProxyUrlMapIsRegionalTargetHttpProxiesRefIsSpecifiedr
   InvalidArgumentExceptionmessages.ComputeRegionTargetHttpProxiesSetUrlMapRequestr   r   NameUrlMapReferenceSelfLinkapitools_clientregionTargetHttpProxiesMakeRequests_GetGlobalTargetHttpProxyr   CopyProtoMessageurl_mapr   r   r"   append_PatchGlobalTargetHttpProxy)argsholdertarget_http_proxy_argurl_map_argr#   	proxy_refurl_map_refinvalid_argrequest
collectionresold_resourcenew_resourcecleared_fieldss                 r   _RunrI   :   s   ==&#55
!++22 66v>	 6 ) *FF
KF$4$4+ ==iHK563k			=	>9k//
  ooLL!!!(77'') 8 
	 M G ''??J



KAB
CCJ,VY?L,,\:LN||'002l56-1-M-Ml*			=	>-1l*56|#(
)\>  $r   c           	          g }|j                  | j                  j                  d| j                  j	                  |j
                  |j                               f       | j                  |      }|d   S )z'Retrieves the Global target HTTP proxy.Get)r   r   r   )r:   r4   targetHttpProxiesr/   "ComputeTargetHttpProxiesGetRequestr   r1   r6   )r#   r@   requestsrE   s       r   r7   r7   u   sp     (
//..oo88##Y^^5E 9   	H%#	Q-r   c           	      B   g }|j                  | j                  j                  d| j                  j	                  |j
                  |j                         |      f       | j                  j                  |      5  | j                  |      cddd       S # 1 sw Y   yxY w)z%Patches the Global target HTTP proxy.Patch)r   r   targetHttpProxyResourceN)	r:   r4   rL   r/   $ComputeTargetHttpProxiesPatchRequestr   r1   IncludeFieldsr6   )r#   r@   rG   rH   rN   s        r   r;   r;      s     (
//..oo::###..*". ;   ++N;x( <;;s   :BBc                   <    e Zd ZdZdZdZ e       Zed        Z	d Z
y)Updater   Nc                 L   t        j                         | _        | j                  j                  |d       t	        j
                         | _        | j                  j                  |       |j                         }t        j                  |       t        j                  |       y )Nupdate)operation_type)r   TargetHttpProxyArgumentTARGET_HTTP_PROXY_ARGAddArgumenturl_map_flagsUrlMapArgumentForTargetProxyURL_MAP_ARGadd_mutually_exclusive_groupr   AddHttpKeepAliveTimeoutSecAddClearHttpKeepAliveTimeoutSec)clsparsergroups      r   ArgszUpdate.Args   sx     % = = ?C))&)J#@@BCOOO'//1E33E:88?r   c                     t        j                  | j                               }t        ||| j                  | j
                        S )N)r   ComputeApiHolderReleaseTrackrI   rZ   r^   )selfr<   r=   s      r   Runz
Update.Run   s@    **4+<+<+>?F""	 r   )__name__
__module____qualname____doc__rZ   r^   r   detailed_helpclassmethodre   rj   r   r   r   rU   rU      s2     $+/-@ @r   rU   N)!rn   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper	   r
   "googlecloudsdk.command_lib.computer   r)   r   r&   6googlecloudsdk.command_lib.compute.target_http_proxiesr   +googlecloudsdk.command_lib.compute.url_mapsr\   r   rI   r7   r;   ReleaseTracksrh   ALPHABETAGAUpdateCommandrU   r   r   r   <module>r}      s    0 &  ' % 7 ? ( . E E H \ N28v )$ T..33T5F5F5I5IT r   