
                             S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r
  SSKJr  SS	KJr  SSKJ	r	  SS
KJr  S rS rS rS rS rS rg)z2Common classes and functions for forwarding rules.    )absolute_import)division)unicode_literals)lister)utils)flags)scope)
exceptions)
propertiesc                 @   U R                   (       a  [        R                  " S5      eU R                  (       a  [        R                  " S5      e[	        U SS5      (       a  [        R                  " S5      e[	        U SS5      (       a  [        R                  " S5      eg)z*Validate the global forwarding rules args.zDYou cannot specify [--target-instance] for a global forwarding rule.z@You cannot specify [--target-pool] for a global forwarding rule.backend_serviceNzDYou cannot specify [--backend-service] for a global forwarding rule.target_vpn_gatewayzGYou cannot specify [--target-vpn-gateway] for a global forwarding rule.)target_instancer
   ArgumentErrortarget_poolgetattrargss    <lib/googlecloudsdk/api_lib/compute/forwarding_rules_utils.py_ValidateGlobalTargetArgsr      s    	

"
"	  


"
"	  T$d++

"
"	  T'..

"
"	  /    c                    [        U5        UR                  (       a;  [        R                  " 5       R	                  X[
        R                  R                  S9$ UR                  (       a;  [        R                  " 5       R	                  X[
        R                  R                  S9$ UR                  (       a;  [        R                  " 5       R	                  X[
        R                  R                  S9$ UR                  (       a  [        R                  R	                  X5      $ UR                  (       a6  [        R                  R	                  X[
        R                  R                  S9$ g)z;Return the forwarding target for a globally scoped request.default_scopeN)r   target_http_proxyr   TargetHttpProxyArgResolveAsResourcecompute_scope	ScopeEnumGLOBALtarget_https_proxyTargetHttpsProxyArgtarget_grpc_proxyTargetGrpcProxyArgtarget_ssl_proxyTARGET_SSL_PROXY_ARGtarget_tcp_proxyTARGET_TCP_PROXY_ARG)	resourcesr   s     r   GetGlobalTargetr*   4   s   D!	##%77}'>'>'E'E 8 G G	$$&88}'>'>'E'E 9 G G	##%77}'>'>'E'E 8 G G	%%77HH	%%77}'>'>'E'E 8   r   c                     [        U SS5      (       a  [        R                  " S5      eU R                  (       a(  U R                  (       d  [        R                  " S5      egg)zzValidate the regional forwarding rule target args.

Args:
    args: The arguments given to the create/set-target command.
globalNz=You cannot specify [--global] for a regional forwarding rule.zZYou cannot specify [--target-instance-zone] unless you are specifying [--target-instance].)r   r
   r   target_instance_zoner   r   s    r   _ValidateRegionalTargetArgsr.   I   s^     T8T""

"
"	  
t';';

"
"	*+ + (<r   c                 D   [        U5        UR                  nUR                  nUR                  (       a\  UR                  =(       d    UUl        [
        R                  R                  UU[        R                  " U 5      S9nUR                  nXg4$ UR                  (       a  [
        R                  R                  UU[        S/X@U=(       d2    [        R                  R                  R                  R!                  5       5      S9n["        R$                  " UR&                  5      nXg4$ [)        USS5      (       aH  UR*                  =(       d    UUl        [
        R,                  R                  X!5      nUR                  nXg4$ [)        USS5      (       aH  UR.                  =(       d    UUl        [
        R0                  R                  X!5      nUR                  nXg4$ UR2                  (       a@  [
        R4                  " 5       R                  X![6        R8                  R:                  S9nUnXg4$ UR<                  (       a@  [
        R>                  " 5       R                  X![6        R8                  R:                  S9nUnXg4$ UR@                  (       a$  [
        RB                  R                  X!5      nUnXg4$ URD                  (       a@  [
        RF                  " 5       R                  X![6        R8                  R:                  S9nUnXg4$ URH                  (       av  [
        RJ                  " 5       R                  X!5      nUR                  nXt:w  d(  URL                  (       a-  U(       a&  URL                  U:w  a  [N        RP                  " S5      eXg4$ [N        RP                  " S5      e)	z=Return the forwarding target for a regionally scoped request.)scope_listerz--target-instance-zoner   Nr   r   z_The region of the provided service attachment must equal the [--region] of the forwarding rule.a=  
For a regional forwarding rule, exactly one of  ``--target-instance``,
``--target-pool``, ``--target-http-proxy``, ``--target-https-proxy``,
``--target-grpc-proxy``, ``--target-ssl-proxy``, ``--target-tcp-proxy``,
``--target-service-attachment``, ``--target-vpn-gateway`` or
``--backend-service`` must be specified.
))r.   regionprojectr   target_pool_regionr   TARGET_POOL_ARGr   compute_flagsGetDefaultScopeListerr   TARGET_INSTANCE_ARG_GetZonesInRegionListerr   VALUEScore	GetOrFailr   ZoneNameToRegionNamezoner   target_vpn_gateway_regionTARGET_VPN_GATEWAY_ARGbackend_service_regionBACKEND_SERVICE_ARGr   r   r   r   r    r!   r"   r%   r&   r'   TargetTcpProxyArgtarget_service_attachmentTargetServiceAttachmentArg target_service_attachment_regionr
   r   )clientr)   r   forwarding_rule_ref
region_argproject_arg
target_reftarget_regions           r   GetRegionalTargetrL   _   sR   d#"))*#+++	"55CD&&88"88@ 9 BJ %%Mh 
	""g **<<,%&
K =7""**4468 = 9J ..z?MX 
	""W t)400%)%C%C%QzD"--??PJ%%MP 
	""O t&--"&"="="KD**<<TMJ%%MH 
	""G ))+==}'>'>'E'E > GJM@ 
	""? **,>>}'>'>'E'E ? GJM8 
	""7 ++==dNJM2 
	""1 ((*<<}'>'>'E'E = J M( 
	""' %%113EEJ%%M"--*--;$$/0 0 
	"" 
"
" $  r   c                     ^ ^^^ UU UU4S jnU$ )z&Lists all the zones in a given region.c            	        > T
(       a  SR                  T
5      nOSn/ n[        R                  " TR                  R                  T	UTR                  R
                  TR                  US9nU Vs/ s H  oDPM     nnU(       d  U(       dA  U(       a  SOSn[        R                  " USR                  SR                  T5      U5      5        [        R                  R                  U0$ s  snf )z/Returns a list of the zones for a given region.zname eq {0}.*N)servicer2   filter_exprhttp	batch_urlerrors:.zGUnable to fetch a list of zones. Specifying [{0}] may fix this issue{1}z, or )formatr   GetGlobalResourcesapitools_clientzonesrQ   rR   r   RaiseToolExceptionjoinr   r   ZONE)unused_argsrP   rS   global_resourcesresourcechoicespunctuationcompute_client
flag_namesr2   r1   s          r   Lister'_GetZonesInRegionLister.<locals>.Lister   s    #**62kkF00..44++00 ** )99(8Hx(8G9W!Csk
VGLL4kBD
 ##(('22 :s   .C& )rc   r1   rb   r2   rd   s   ```` r   r8   r8      s    3 34 
-r   c                 ^   UR                  5       S:X  aM  U R                  R                  R                  U R                  R
                  " S0 UR                  5       D65      $ U R                  R                  R                  U R                  R                  " S0 UR                  5       D65      $ )z!Send forwarding rule get request.zcompute.globalForwardingRulesrf   )	
CollectionrX   globalForwardingRulesGetmessages&ComputeGlobalForwardingRulesGetRequestAsDictforwardingRules ComputeForwardingRulesGetRequest)rF   rG   s     r   SendGetRequestrp      s    ##%)HH!!77;;>> 	,!((*	,- - !!115588 	,!((*	,- -r   N)__doc__
__future__r   r   r   googlecloudsdk.api_lib.computer   r   "googlecloudsdk.command_lib.computer   r5   r	   r   3googlecloudsdk.command_lib.compute.forwarding_rulesr
   googlecloudsdk.corer   r   r*   r.   rL   r8   rp   rf   r   r   <module>rw      sH    9 &  ' 1 0 E E J E *,*+,?#D@	-r   