
    0                     n   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rS+S
 jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jr0 S\_S\_S\_S\_S\_S\_S \_S!\_S"\_S#\_S$\_S%\_S&\_S'\_S(\_S)\_rS* rg	),a  Compute resource transforms and symbols dict.

A resource transform function converts a JSON-serializable resource to a string
value. This module contains built-in transform functions that may be used in
resource projection and filter expressions.

NOTICE: Each TransformFoo() method is the implementation of a foo() transform
function. Even though the implementation here is in Python the usage in resource
projection and filter expressions is language agnostic. This affects the
Pythonicness of the Transform*() methods:
  (1) The docstrings are used to generate external user documentation.
  (2) The method prototypes are included in the documentation. In particular the
      prototype formal parameter names are stylized for the documentation.
  (3) The 'r', 'kwargs', and 'projection' args are not included in the external
      documentation. Docstring descriptions, other than the Args: line for the
      arg itself, should not mention these args. Assume the reader knows the
      specific item the transform is being applied to. When in doubt refer to
      the output of $ gcloud topic projections.
  (4) The types of some args, like r, are not fixed until runtime. Other args
      may have either a base type value or string representation of that type.
      It is up to the transform implementation to silently do the string=>type
      conversions. That's why you may see e.g. int(arg) in some of the methods.
  (5) Unless it is documented to do so, a transform function must not raise any
      exceptions related to the resource r. The `undefined' arg is used to
      handle all unusual conditions, including ones that would raise exceptions.
      Exceptions for arguments explicitly under the caller's control are OK.
    )absolute_import)division)unicode_literals)	constants)instance_utils)path_simplifier)resource_transformNc                 (   [         R                  " U SS5      nUc  U$ / n[         R                  " U SS5      n U H#  nUR                  SR                  X%5      5        M%     SR                  U5      $ ! [         a    UR                  U5         N.f = f)az  Returns a compact string describing a firewall rule.

The compact string is a comma-separated list of PROTOCOL:PORT_RANGE items.
If a particular protocol has no port ranges then only the protocol is listed.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  A compact string describing the firewall rule in r.

IPProtocolNports{0}:{1},r	   GetKeyValueappendformat	TypeErrorjoin)r	undefinedprotocolruleport_ranges
port_ranges         0lib/googlecloudsdk/api_lib/compute/transforms.pyTransformFirewallRuler   7   s      ++A|TB(	$"..q'4@+!

kk)""889 " 
$ 
 KK   )A3 3BBc                 (   [         R                  " U SS5      nUc  U$ / n[         R                  " U SS5      n U H#  nUR                  SR                  X%5      5        M%     SR                  U5      $ ! [         a    UR                  U5         N.f = f)a  Returns a compact string describing an organization firewall rule.

The compact string is a comma-separated list of PROTOCOL:PORT_RANGE items.
If a particular protocol has no port ranges then only the protocol is listed.

Args:
  rule: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  A compact string describing the organizatin firewall rule in the rule.

ipProtocolNr   r   r   r   )r   r   r   resultr   r   s         r   !TransformOrganizationFirewallRuler!   Q   s      ++D,E(&"..tWdC+!
mmI$$X:; " 
&	 
 
MM(r   c                    [         R                  " U SS5      nUc  U$ [         R                  " [         R                  " U SS5      S5      R                  S5      S   n[        R
                  R                  5        VVs/ s H;  u  pEUR                  UR                  5      (       d  M'  UR                  U:X  d  M9  UPM=     nnnSR                  U5      $ s  snnf )	zReturns a comma-separated list of alias names for an image.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  A comma-separated list of alias names for the image in r.
nameNselfLink projects/r   r   )r	   r   TransformScopesplitr   IMAGE_ALIASESitems
startswithname_prefixprojectr   )r   r   r#   r.   aliasvaluealiasess          r   TransformImageAliasr2   k   s     
	'	'64	8$	\--$$Q
B7%*Q ' (1'>'>'D'D'F +'F|u 1 12 ') 'F' + 
'	+s   >&C(C:Cc                     S H9  n[         R                  " XS5      nU(       d  M#  [         R                  " X15      s  $    U$ )zReturn the region or zone name.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  The region or zone name.
zoneregionN)r	   r   TransformBaseNamer   r   scopelocations       r   TransformLocationr;      s>     "e!--a=Hx11(FF " 
    c                 \    S H%  n[         R                  " XS5      nU(       d  M#  Us  $    U$ )zReturn the location scope name, either region or zone.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  The location scope name, either region or zone.
r4   Nr	   r   r8   s       r   TransformLocationScoper?      s2     "e!--a=Hxl " 
r<   c                    [        U [        R                  5      (       d  U$ [        R                  " U 5      u  p#nU(       a  U(       a  U(       d  U $ SR                  [        U5      S-  5      nSR                  X#U5      $ )zReturn the formatted name for a machine type.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  The formatted name for a machine type.
z{0:.2f}i   zcustom ({0}, {1} vCPU, {2} GiB))
isinstancesixstring_typesr   GetCpuRamVmFamilyFromCustomNamer   float)r   r   custom_family
custom_cpu
custom_ramcustom_ram_gbs         r   TransformMachineTyperJ      st     
As''	(	(2215 (-Z	j
H""5#4#>?-	*	1	1-2?
A Ar<   c                     U (       d  U$ [        U S S9nUc  U$ UR                  SS5      nUc  U$ UR                  SS5      nUc  U$ SR                  X45      $ )a4  Returns the timestamps of the next scheduled maintenance.

All timestamps are assumed to be ISO strings in the same timezone.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  The timestamps of the next scheduled maintenance or undefined.
c                 &    U R                  SS 5      $ )N	beginTime)get)xs    r   <lambda>*TransformNextMaintenance.<locals>.<lambda>   s    AEE+t$<r<   )keyNrM   endTimez{0}--{1})minrN   r   )r   r   
next_event
begin_timeend_times        r   TransformNextMaintenancerX      so     
1<=*~~k40*^^It,(			:	00r<   c                     [         R                  " U SS5      S:X  a!  [         R                  " U SS5      =(       d    S$ U$ )zReturns the HTTP response code of an operation.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if there is no response code.

Returns:
  The HTTP response code of the operation in r.
statusNDONEhttpErrorStatusCode   r>   r   r   s     r   TransformOperationHttpStatusr_      sA     ##Ax6&@**1.CTJ 	r<   c                     [         R                  " [         R                  " U SS5      S5      R                  S5      S   nU=(       d    U$ )zReturns a project name from a selfLink.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  A project name for selfLink from r.
r$   r%   r&   r'   r   r	   r(   r   r)   r   r   r.   s      r   TransformProjectrc      sF     --$$Q
B7%*Q ' 
	Ir<   c                 `    U (       a   U R                  S5      S   $ U$ ! [         a     U$ f = f)zReturns a resource name from an URI.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  A project name for selfLink from r.
r'   )r)   AttributeErrorr^   s     r   TransformNamerg      sA     WWS\" 
  
	s    
--c                 L   [         R                  " U SS5      nUc  U$ [         R                  " U SS5      nUc  U$  U[        U5      :X  a3  U[        U5      :X  a$  SR                  [        U5      [        U5      5      $ SR                  X#5      $ ! [        [
        4 a     U$ f = f)zFormats a quota as usage/limit.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  The quota in r as usage/limit.
usageNlimitz{0}/{1}z{0:.2f}/{1:.2f})r	   r   intr   r   
ValueError)r   r   ri   rj   s       r   TransformQuotarm     s     
(
(GT
:%
]

(
(GT
:%
]	E
uE
2c%j#e*55##E11
Z	  			s   AB >B B#"B#c                     U (       a1   [        U  Vs/ s H  n[        R                  " U5      PM     sn5      $ U$ s  snf ! [         a     U$ f = f)z9Get just the scoped part of the object the uri refers to.)sortedr   ScopedSuffixr   )urisr   uris      r   TransformScopedSuffixesrs     sW     
$G$3_11#6$GHH 
 H 
	s   	A   ;A  A   
AAc                     [         R                  " U SS5      n[         R                  " U SS5      nU(       a!  SR                  X#R                  SS5      5      $ U=(       d    U$ )a  Returns the machine status with deprecation information if applicable.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  The machine status in r with deprecation information if applicable.
rZ   N
deprecatedr%   z	{0} ({1})state)r	   r   r   rN   )r   r   rZ   ru   s       r   TransformStatusrw   )  sV     ))!Xt<&!--arB*fnnWb&ABB		9r<   c                 z    [         R                  " U SS5      nUb  U$ [         R                  " U SS5      nUb  U$ U$ )a  Returns the gateway for the specified VPN tunnel resource if applicable.

Args:
  vpn_tunnel: JSON-serializable object of a VPN tunnel.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  The VPN gateway information in the VPN tunnel object.
targetVpnGatewayN
vpnGatewayr>   )
vpn_tunnelr   target_vpn_gatewayvpn_gateways       r   TransformVpnTunnelGatewayr~   :  sO     *55j6H$P#"..z<N+	r<   c                     [         R                  " [         R                  " U SS5      S5      R                  S5      S   nU=(       d    U$ )zReturns a zone name from a selfLink.

Args:
  r: JSON-serializable object.
  undefined: Returns this value if the resource cannot be formatted.

Returns:
  A zone name for selfLink from r.
r$   r%   zonesr'   r   ra   rb   s      r   TransformZoner   P  sE     --$$Q
B7BBG%*QP'		Ir<   c                      SR                  U R                  S5      SS 5      =(       d    U$ ! [        [        [        4 a     U$ f = f)z:Get the type and the name of the object the uri refers to.r'   N)r   r)   rf   
IndexErrorr   )rr   r   s     r   TransformTypeSuffixr   _  sI    	88CIIcN23'(5I5
*i	0 			s   +. AAfirewall_ruleorg_firewall_ruleimage_aliasr:   location_scopemachine_typenext_maintenancer#   operation_http_statusr.   quotascoped_suffixesrZ   type_suffixvpn_tunnel_gatewayr5   c                      [         $ )z=Returns the compute specific resource transform symbol table.)_TRANSFORMS r<   r   GetTransformsr   ~  s    	r<   )r%   )__doc__
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.core.resourcer	   rB   r   r!   r2   r;   r?   rJ   rX   r_   rc   rg   rm   rs   rw   r~   r   r   r   r   r   r<   r   <module>r      sI   8 '  ' 4 9 : ; 
44,""A,14  $2",*: & !	
 , ( 0 M 9  ^ . o & 3  M!(r<   