
                            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dlmZ ddlmZ d Zd ZddZd Zd Z d Z!d Z" ejF                  ejH                  jJ                  ejH                  jL                  ejH                  jN                         G d dejP                               Z)y)z#Import target HTTP Proxies command.    )absolute_import)division)unicode_literals)
exceptions)base_classes)base)flags)operation_utils)scope)target_http_proxies_utils)util)yaml_validator)
console_ioc                      ddddS )NzImport a target HTTP proxy.zM          Imports a target HTTP proxy's configuration from a file.
          zz          A target HTTP proxy can be imported by running:

            $ {command} NAME --source=<path-to-file>
          )briefDESCRIPTIONEXAMPLES r       1lib/surface/compute/target_http_proxies/import.py_DetailedHelpr   #   s     (
 r   c                 |    | t         j                  j                  k(  ry| t         j                  j                  k(  ryy)z3Returns the API version based on the release track.alphabetav1)r   ReleaseTrackALPHABETA)release_tracks    r   _GetApiVersionr    4   s3    d''---))...	r   c                 F    t        j                  dt        |       d|      S )z!Returns the resource schema path.computeTargetHttpProxyfor_help)export_utilGetSchemaPathr    )r   r%   s     r   _GetSchemaPathr(   =   s&    		"	"]#	
 r   c                    t        j                  |      rX| j                  j                  }|j	                  | j
                  j                  |j                  |j                  |            }nL| j                  j                  }|j	                  | j
                  j                  |j                  |            }t        ||||d      S )z'Sends Target HTTP Proxy insert request.)projectregiontargetHttpProxy)r*   r,   zInserting TargetHttpProxy)r   IsRegionalTargetHttpProxiesRefapitools_clientregionTargetHttpProxiesInsertmessages+ComputeRegionTargetHttpProxiesInsertRequestr*   r+   targetHttpProxies%ComputeTargetHttpProxiesInsertRequest_WaitForOperation)client	resourcestarget_http_proxy_reftarget_http_proxyservice	operations         r   _SendInsertRequestr<   F   s     ==$$<<GCC)11(//- 	D 	/0I $$66G==)11- 	> 	/0I
 
9gy:O6
8 8r   c                 T   t        j                  |      r*dj                  |j                               }t	        |      | j
                  j                  }|j                  | j                  j                  |j                  |j                         |            }t        ||||d      S )z%Make target HTTP proxy patch request.z)Target HTTP Proxy [{0}] cannot be updated)r*   r,   targetHttpProxyResourcezUpdating TargetHttpProxy)r   r-   formatNameNotImplementedErrorr.   r3   Patchr1   $ComputeTargetHttpProxiesPatchRequestr*   r5   )r6   r7   r8   r9   console_messager:   r;   s          r   _SendPatchRequestrE   \   s     ==BII""$&O
o
..""44'mmoo::'///446"3 ; 56) 
9gy:O5
7 7r   c                     t        j                  |      rt        j                         }nt        j                         }t        j
                  | |||||      S )z2Waits for the TargetHttpProxy operation to finish.)r   r-   r
   GetRegionalOperationsCollectionGetGlobalOperationsCollectionWaitForOperation)r7   r:   r;   r8   message
collections         r   r5   r5   p   sS     == @@BJ >>@J		)	))Wi*46K*1
3 3r   c                    |j                   }|j                  }|j                  | |j                  t        j                  j
                  t        j                  |            }t        j                  | j                  xs dd      }	 t        j                  |j                  j                  |t        |            }	 t)        j*                  ||      }
|
|k(  ryt        j4                  dj7                  |j9                               d	
       |
j:                  |_        |
j<                  |_        g }|j>                  |jA                  d       |jB                  |jA                  d       |tD        jF                  jH                  k7  r|jJ                  |jA                  d       |jL                  jO                  |      5  tQ        ||||      cddd       S # t         j"                  $ r#}	t%        j"                  t'        |	            d}	~	ww xY w# t,        j.                  $ r)}|j0                  dk7  r|t3        ||||      cY d}~S d}~ww xY w# 1 sw Y   yxY w)z8Issues requests necessary to import target HTTP proxies.)default_scopescope_lister-F)binary)message_typestreamschema_pathNi  z,Target Http Proxy [{0}] will be overwritten.T)rJ   cancel_on_nodescriptionurlMap	proxyBind))r6   r7   ResolveAsResourcecompute_scope	ScopeEnumGLOBALcompute_flagsGetDefaultScopeListerr   ReadFromFileOrStdinsourcer&   Importr1   r#   r(   r   ValidationErrorcompute_exceptionsstrr   SendGetRequestapitools_exceptions	HttpErrorstatus_coder<   PromptContinuer?   r@   idfingerprintrU   appendrV   r   r   GArW   r.   IncludeFieldsrE   )argsholdertarget_http_proxy_argr   r6   r7   r8   datar9   etarget_http_proxy_olderrorcleared_fieldss                r   _Runrv   ~   s)   ==&)/AA
!++22 66v>	 B @ 
	'	'(:s5	I$5#**__44"=1315DD%' //
=EE

$
$
&( /11"7"C"C .""*-(
 %(#d''***""*K(++N;VY0E.0 <;S 
	'	' 5

,
,SV
445 
	&	& 1Ckfi1F/1 1	1D <;sB   	5G ?H IH-HHI&I
I
IIc                   8    e Zd ZdZ e       ZdZed        Zd Z	y)r`   zImport a target HTTP Proxy.Nc                     t        j                         | _        | j                  j                  |d       t	        j
                  |t        | j                         d             y )Nimport)operation_typeTr$   )r	   TargetHttpProxyArgumentTARGET_HTTP_PROXY_ARGAddArgumentr&   AddImportFlagsr(   r   )clsparsers     r   ArgszImport.Args   sP     % = = ?C))&)Js//1DACr   c                     t        j                  | j                               }t        ||| j                  | j                               S )N)r   ComputeApiHolderr   rv   r|   )selfrn   ro   s      r   Runz
Import.Run   s;    **4+<+<+>?Ffd88$:K:K:MNNr   )
__name__
__module____qualname____doc__r   detailed_helpr|   classmethodr   r   r   r   r   r`   r`      s.     $/-C COr   r`   N)F)*r   
__future__r   r   r   apitools.base.pyr   re   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computerb   r	   r\   r
   r   rY   6googlecloudsdk.command_lib.compute.target_http_proxiesr   !googlecloudsdk.command_lib.exportr   r&   googlecloudsdk.corer   googlecloudsdk.core.consoler   r   r    r(   r<   rE   r5   rv   ReleaseTracksr   rl   r   r   UpdateCommandr`   r   r   r   <module>r      s    * &  ' > 7 ( O E > E H \ A . 2"8,7(3=0@ D%%(($*;*;*@*@%%++-OT O-Or   