
                             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 Zd Zd Zd Zd Zd Zy)z2Common classes and functions for forwarding rules.    )absolute_import)division)unicode_literals)lister)utils)flags)scope)
exceptions)
propertiesc                    | j                   rt        j                  d      | j                  rt        j                  d      t	        | dd      rt        j                  d      t	        | dd      rt        j                  d      y)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                    t        |       |j                  r>t        j                         j	                  || t
        j                  j                        S |j                  r>t        j                         j	                  || t
        j                  j                        S |j                  r>t        j                         j	                  || t
        j                  j                        S |j                  r t        j                  j	                  ||       S |j                  r:t        j                  j	                  || t
        j                  j                        S y)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i}'>'>'E'E 8 G G	$$&88i}'>'>'E'E 9 G G	##%77i}'>'>'E'E 8 G G	%%77iHH	%%77i}'>'>'E'E 8   r   c                     t        | dd      rt        j                  d      | j                  r"| j                  st        j                  d      yy)zValidate 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                    t        |       |j                  }|j                  }|j                  rZ|j                  xs ||_        t
        j                  j                  ||t        j                  |             }|j                  }||fS |j                  rt
        j                  j                  ||t        dg|| |xs2 t        j                  j                  j                  j!                                     }t#        j$                  |j&                        }||fS t)        |dd      rE|j*                  xs ||_        t
        j,                  j                  ||      }|j                  }||fS t)        |dd      rE|j.                  xs ||_        t
        j0                  j                  ||      }|j                  }||fS |j2                  rDt        j4                         j                  ||t6        j8                  j:                        }|}||fS |j<                  rDt        j>                         j                  ||t6        j8                  j:                        }|}||fS |j@                  r&t
        jB                  j                  ||      }|}||fS |jD                  rDt        jF                         j                  ||t6        j8                  j:                        }|}||fS |jH                  rkt        jJ                         j                  ||      }|j                  }||k7  s|jL                  r&|r$|jL                  |k7  rtO        jP                  d      ||fS tO        jP                  d      )	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   _   sp   d#"))*#+++	"55CD&&88"88@ 9 BJ %%Mh 
]	""g **<<,%&
FK =7""**4468 = 9J ..z?MX 
]	""W t)40%)%C%C%QzD"--??iPJ%%MP 
]	""O t&-"&"="="KD**<<T9MJ%%MH 
]	""G ))+==i}'>'>'E'E > GJM@ 
]	""? **,>>i}'>'>'E'E ? GJM8 
]	""7 ++==dINJM2 
]	""1 ((*<<i}'>'>'E'E = J M( 
]	""' %%113EEiJ%%M
"--*--;$$/0 0 
]	"" 
"
" $  r   c                       fd}|S )z&Lists all the zones in a given region.c                     
rdj                  
      }nd}g }t        j                  j                  j                  	|j                  j
                  j                  |      }|D cg c]  }| }}|s|s;|rdnd}t        j                  |dj                  dj                        |             t        j                  j                  |iS c c}w )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   Listerz'_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    34 
-r   c                 \   |j                         dk(  rM| j                  j                  j                   | j                  j
                  di |j                               S | j                  j                  j                   | j                  j                  di |j                               S )z!Send forwarding rule get request.zcompute.globalForwardingRulesre   )	
CollectionrX   globalForwardingRulesGetmessages&ComputeGlobalForwardingRulesGetRequestAsDictforwardingRules ComputeForwardingRulesGetRequest)rF   rG   s     r   SendGetRequestro      s    ##%)HH!!77;;>>> 	,!((*	,- - !!11558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   ro   re   r   r   <module>rv      sH    9 &  ' 1 0 E E J E *,*+,?#D@	-r   