
    v                     J   S r SSKJr  SSKJr  SSKJr  SSK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KrS
 rS rS rS rS rS rS rS rSS jrS rS rS rS rS rS rS rS rS rS r S r!S r"S  r#\RH                  " S!/ S"Q5      r%0 S#\%" S$/ S%QS&\
RL                  4S'\
RN                  4/SS"9_S(\%" S)/ S*QS+\
RL                  4S,\
RL                  4/SS"9_S-\%" S./ S/QS0S1 4/S2S0/S"9_S3\%" S4S5S6\ 4S7/S8\
RN                  4// S9QS"9_S:\%" S;/ S<\
RN                  4/SS"9_S=\%" S>/ S?QS@\
RL                  4SA\
RL                  4S+\
RL                  4/SS"9_SB\%" SC/ SDQS+\
RL                  4/SS"9_SE\%" SFS5SGSH\4SI\4SJ\4SK\4/SL\
RL                  4/SS"9_SM\%" SNS5SOSPSQSR\4/S&\
RL                  4S,\
RN                  4/SS"9_SS\%" STS5SU\4SV// / S"9_SW\%" SXS5SY// SS"9_SZ\%" S[/ S\Q/ SS"9_S]\%" S^/ S\Q/ SS"9_S_\%" S`/ SaQ/ SS"9_Sb\%" ScS5Sd\4SeSfSg// SS"9_Sh\%" Si/ SjQS+\
RL                  4Sk\(4/SS"9_Sl\%" Sm/ SnQS+\
RL                  4So\
RL                  4Sp\
RL                  4/SS"9_0 Sq\%" SrS5SsSt\4SuSvSwSg/Sx\
RL                  4Sy\
RL                  4Sz\
RL                  4S+\
RL                  4/SS"9_S{\%" S|S5St\4S}S~// SS"9_S\%" SS5SsSS\4Sf/S+\
RL                  4/SS"9_S\%" S/ SQ/ SS"9_S\%" S/ / SS"9_S\%" SS5SSS\4SgS/S\
RN                  4/SS"9_S\%" SSVS\4SgS/S\
RN                  4/SS"9_S\%" S4S5S6\ 4S7/S8\
RN                  4// SQS"9_S\%" SS5S\" SSS94S\" SSS94S\" SSS94S\" SSS94S\4S\4/S\
RL                  4/SS"9_S\%" SS5SGSS\!4S/SL\
RL                  4/SS"9_S\%" S/ SQS\
RN                  4/SS"9_S\%" SS5S~// SS"9_S\%" S/ SQSL\
RL                  4S&\
RL                  4/SS"9_S\%" SS5S/S\
RL                  4/SS"9_S\%" SS5S\"4S/S\
RL                  4S\
RL                  4/SS"9_S\%" SS5SSS\"4/S\
RL                  4S\
RL                  4/SS"9_S\%" S/ SQS\
RL                  4S+\
RL                  4/SS"9_E\%" S/ S<\
RN                  4/SS"9\%" SS5SOSSS\4/S\
RL                  4S\
RL                  4S\
RN                  4S&\
RL                  4/SS"9\%" S/ SQSL\
RL                  4S&\
RL                  4/SS"9\%" S/ SQ/ / S"9\%" SS5SOS\4S\4/S&\
RL                  4/SS"9\%" S/ SQS&\
RL                  4S\
RL                  4/SS"9\%" S/ SQSL\
RL                  4S&\
RL                  4/SS"9S.Er)\)RU                  5       r+\%" S4S5S6\ 4S7/S8\
RN                  4// SQS"9\+S3'   \%" S/ SQ/ / S"9\+S'   \+RU                  5       r,\%" SiS5S\4S\4SGSS/Sk\(4/SS"9\,Sh'   \%" SmS5S\4S\4SSSSS/So\
RL                  4Sp\
RL                  4/SS"9\,Sl'   S r-\RH                  " S!/ SQ5      r.S r/g)z4Annotates the resource types with extra information.    )absolute_import)division)unicode_literalsN)messages)instance_utils)path_simplifier)property_selectorc                 6   / nU R                  S/ 5       Hq  nUR                  S5      nU(       d  M  UR                  S5      nU(       a+  U H#  nUR                  SR                  X55      5        M%     M`  UR                  U5        Ms     SR                  U5      $ )z7Returns a compact string describing the firewall rules.allowed
IPProtocolportsz{0}:{1},)getappendformatjoin)firewallrulesr   protocolport_ranges
port_ranges         4lib/googlecloudsdk/api_lib/compute/resource_specs.py_FirewallRulesToCellr       s    
%i,g{{<(H++g&K#*Y%%h;< $ ll8 - 
%    c                 R    SR                  S U R                  S/ 5       5       5      $ )z@Comma-joins the names of health checks of the given target pool.r   c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fNr   Name).0checks     r   	<genexpr>0_TargetPoolHealthChecksToCell.<locals>.<genexpr>4   s%      75 38/&&u--5   #%healthChecksr   r   )target_pools    r   _TargetPoolHealthChecksToCellr(   2   s+    	 7//."57 
7 7r   c                 D    SR                  U R                  S/ 5      5      $ )z9Comma-joins the source ranges of the given firewall rule.r   sourceRangesr&   r   s    r   _FirewallSourceRangesToCellr,   8   s    	(,,~r2	33r   c                 D    SR                  U R                  S/ 5      5      $ )z7Comma-joins the source tags of the given firewall rule.r   
sourceTagsr&   r+   s    r   _FirewallSourceTagsToCellr/   =       	(,,|R0	11r   c                 D    SR                  U R                  S/ 5      5      $ )z7Comma-joins the target tags of the given firewall rule.r   
targetTagsr&   r+   s    r   _FirewallTargetTagsToCellr3   B   r0   r   c                 T    U R                  SS5      nUb  U$ U R                  SS5      $ )z?Gets the API-level target or backend-service of the given rule.backendServiceNtargetr   )forwarding_rulebackend_services     r   _ForwardingRuleTargetr:   G   s4    #''(8$?/ x..r   c                     U R                  SS5      nU(       a0  SR                  U R                  S5      UR                  S5      5      $ U R                  S5      $ )zGReturns status of a machine with deprecation information if applicable.
deprecated z	{0} ({1})statusstate)r   r   zone_or_regionr<   s     r   _StatusToCellrB   P   sV    !!,3*n00:(nnW57 7 h''r   c                 X    U R                  SS5      nU(       a  UR                  S5      $ g)z=Returns the turndown timestamp of a deprecated machine or ''.r<   r=   deletedr7   r@   s     r   _DeprecatedDateTimeToCellrE   Z   s)    !!,3*>>)$$r   Tc                    ^ ^ UU 4S jnU$ )zBReturns a function that can format the given quota as usage/limit.c           	      \  > U R                  S/ 5       H  nUR                  S5      T:w  a  M  T(       aD  SR                  [        UR                  S5      5      [        UR                  S5      5      5      s  $ SR                  UR                  S5      UR                  S5      5      s  $    g)z,Formats the metric from the parent function.quotasmetricz	{0:6}/{1}usagelimitz{0:7.2f}/{1:.2f}r=   )r   r   int)regionquota
is_integerrI   s     r   QuotaToCell!_QuotaToCell.<locals>.QuotaToCellf   s    Hb)	8		&	!!		'"#		'"#% 	% "((IIgIIg  	  * r    )rI   rO   rP   s   `` r   _QuotaToCellrS   c   s    " 
r   c                     SU ;   a  [         R                  " U S   5      $ SU ;   a  [         R                  " U S   5      $ g)z;Returns a location name, could be region name or zone name.zonerM   Nr   instance_groups    r   _LocationNamerX   z   sA    ~v 677>!x 899r   c                      SU ;   a  gSU ;   a  gg)z7Returns a location scope type, could be region or zone.rU   rM   NrR   rV   s    r   _LocationScopeTyperZ      s    ~>!r   c                 n    U R                  S5      nU(       a  SR                  [        U5      S-  5      $ g)z3Returns the memory of the given machine type in GB.memoryMbz{0:5.2f}   r=   )r   r   float)machine_typememorys     r   _MachineTypeMemoryToCellra      s2    J'&U6]U233r   c                     [         R                  " U 5      u  pnU(       a4  U(       a-  U(       a&  SR                  US-  5      nSR                  XU5      n U $ )a  Checks for custom machine type and modifies output.

Args:
  mt: machine type to be formatted

Returns:
  If mt was a custom type, then it will be formatted into the desired custom
    machine type output. Otherwise, it is returned unchanged.

Helper function for _MachineTypeNameToCell
z{0:.2f}r]   zcustom ({0}, {1} vCPU, {2} GiB))r   GetCpuRamVmFamilyFromCustomNamer   )mtcustom_family
custom_cpu
custom_ramcustom_ram_gbs        r   _FormatCustomMachineTypeNameri      sR     2226 (-ZJ=$$Z5%9:M	*	1	1-2?
AB	)r   c                 l    U R                  SU 5      R                  S5      nU(       a  [        U5      $ U$ )aN  Returns the formatted name of the given machine type.

Most machine types will be untouched, with the exception of the custom machine
type. This modifies the 'custom-N-M' custom machine types with
'custom (N vCPU, M GiB)'.

For example, given the following custom machine_type:

  custom-2-3500

This function will return:

  custom (2 vCPU, 3.41 GiB)

in the MACHINE_TYPE field when listing out the current instances.

Args:
  machine_type: The machine type of the given instance

Returns:
  A formatted version of the given custom machine type (as shown in example
  in docstring above).

propertiesmachineType)r   ri   )r_   rd   s     r   _MachineTypeNameToCellrm      s4    0 l377F"'++	)r   c                     SU;   aU  SU;   aO  U (       d  gSU ;  a  gU S   R                  S5      nUS   nSU;  a  g[        U5      nXBS'   SR                  U5      $ g)a/  Formats a custom machine type when 'instances describe' is called.

Args:
  resources: dict of resources available for the instance in question
  com_path: command path of the calling command

Returns:
  If input is a custom type, returns the formatted custom machine type.
    Otherwise, returns None.
	instancesdescribeNrl   /custom)splitri   r   )	resourcescom_pathmt_splitlistrd   formatted_mts        r   FormatDescribeMachineTypeNamery      sr     XJ($:I%]+11#6L	b	Br/3L#88L!!r   c                     U R                  S5      S:X  a<  U R                  S5      =(       d$    [        R                  R                  R                  $ g)z6Returns the HTTP response code of the given operation.r>   DONEhttpErrorStatusCoder=   )r   sixmoveshttp_clientOK)	operations    r   _OperationHttpStatusToCellr      s;    ]]8&==./K3993H3H3K3KKr   c                     U R                  S5      nU(       a(  [        R                  " U5      R                  S5      S   $ g)z/Returns the project name of the given resource.selfLinkrq   r   r=   )r   r   ProjectSuffixrt   )resource	self_links     r   _ProjectToCellr      s7    ll:&)((399#>qAAr   c                 J    U R                  S5      nU(       a  [        U5      $ g)Nmembers0)r   len)groupr   s     r   _MembersToCellr      s     IIi 'w<	r   c                 R    SR                  S U R                  S/ 5       5       5      $ )z.Comma-joins the names of the backend services.r   c              3   D   #    U  H  nUR                  S 5      v   M     g7f)r   Nr7   )r    backends     r   r"   "_BackendsToCell.<locals>.<genexpr>  s$      F!Dg ++g&&!Ds    backendsr&   )r9   s    r   _BackendsToCellr      s1    	 F!0!4!4Z!DF 
F Fr   c                    U R                  S5      (       a%  [        R                  " U R                  S5      5      $ U R                  S5      (       a%  [        R                  " U R                  S5      5      $ U R                  S5      (       a  U R                  S5      $ U R                  S5      (       a%  [        R                  " U R                  S5      5      $ U R                  S5      (       a  U R                  S5      $ g)z-Returns the next hop value in a compact form.nextHopInstancenextHopGateway	nextHopIpnextHopVpnTunnelnextHopPeeringr=   )r   r   ScopedSuffix)routes    r   _RoutesNextHopToCellr     s    
YY !!''		2C(DEEyy!""''		2B(CDDyy99[!!yy#$$''		2D(EFFyy!""99%&&r   c                 R    SR                  S U R                  S/ 5       5       5      $ )zDJoins the names of ssl certificates of the given HTTPS or SSL proxy.r   c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fr   r   )r    certs     r   r"   4_TargetProxySslCertificatesToCell.<locals>.<genexpr>  s%      ;9 26/&&t,,9r$   sslCertificatesr&   )target_proxys    r   !_TargetProxySslCertificatesToCellr     s.    	 ;""#4b9; 
; ;r   c              #     #    [        U R                  5       S S9 H  n[        U[        R                  5      (       aY  [        UR                  5       H>  nUR                  (       a  UR                  S-   U-   v   M*  UR                  S-   U-   v   M@     M{  UR                  (       a  UR                  S-   v   M  UR                  v   M     g7f)aV  Flattens the fields in a protocol buffer definition.

For example, given the following definition:

  message Point {
    required int32 x = 1;
    required int32 y = 2;
    optional string label = 3;
  }

  message Polyline {
    repeated Point point = 1;
    optional string label = 2;
  }

a call to this function with the Polyline class would produce:

  ['label',
   'point[].label',
   'point[].x',
   'point[].y']

Args:
  message_class: A class that inherits from protorpc.self.messages.Message
      and defines a protocol buffer.

Yields:
  The flattened fields, in non-decreasing order.
c                     U R                   $ r   )name)fields    r   <lambda>-_ProtobufDefinitionToFields.<locals>.<lambda>9  s    EJJr   )keyz[]..z[]N)	sorted
all_fields
isinstancer   MessageField_ProtobufDefinitionToFieldstyperepeatedr   )message_classr   	remainders      r   r   r     s     < m..06NOe%..//25::>)>>

U"Y.
.

S 9,
,	 ? 
jj4jj Ps   CCSpec)message_class_name
table_colstransformations	editables	addressesAddress)NAMEr   REGIONrM   )ADDRESSaddressSTATUSr>   rM   zusers[]autoscalers
Autoscaler)r   )TARGETr6   )POLICYautoscalingPolicyrU   r6   backendBucketsBackendBucket)r   )GCS_BUCKET_NAME
bucketName)
ENABLE_CDN	enableCdnr   c                 4    [        U 5      R                  5       $ r   )strlower)xs    r   r   r   q  s    CFLLNr   bucketNamedescriptionbackendServicesBackendServicer   BACKENDS)PROTOCOLr   zbackends[].group)r   description	enableCDNr%   iap.enablediap.oauth2ClientIdiap.oauth2ClientSecretportportNamer   
timeoutSecbackendServiceGroupHealthBackendServiceGroupHealthzhealthStatus[].instancedisksDisk)r   ZONErU   )SIZE_GBsizeGb)TYPEr   r   sourceSnapshotr   	diskTypesDiskType)r   r   )VALID_DISK_SIZESvalidDiskSize	firewallsFirewallNETWORKnetwork
SRC_RANGESRULESSRC_TAGSTARGET_TAGSr   forwardingRulesForwardingRuler   )
IP_ADDRESS	IPAddress)IP_PROTOCOLr   r   groupsGroupNUM_MEMBERSDESCRIPTIONr   r%   HealthCheck)r   r   httpHealthChecksHttpHealthCheck)r   )HOSThost)PORTr   )REQUEST_PATHrequestPathhttpsHealthChecksHttpsHealthCheckiapBackendServiceIAP)r   )ENABLEDenabled)OAUTH2_CLIENT_IDoauth2ClientId)OAUTH2_CLIENT_SECREToauth2ClientSecret)OAUTH2_CLIENT_SECRET_SHA256oauth2ClientSecretSha256imagesImagePROJECT)FAMILYfamily)
DEPRECATEDzdeprecated.stater   instanceGroupsInstanceGroup)r   r   r   MANAGED	isManaged	INSTANCESsizer#  instanceGroupManagersInstanceGroupManager)r   r   BASE_INSTANCE_NAMEbaseInstanceNameSIZEr#  TARGET_SIZE
targetSizeINSTANCE_TEMPLATEinstanceTemplate
AUTOSCALED
autoscaledinstanceGroupr0  ro   Instancer   MACHINE_TYPE)PREEMPTIBLEzscheduling.preemptible)INTERNAL_IPz.networkInterfaces[].networkIP.notnull().list())EXTERNAL_IPz;networkInterfaces[].accessConfigs[0].natIP.notnull().list()zdisks[].sourcerl   znetworkInterfaces[].networkinstanceTemplatesInstanceTemplate)r7  z!properties.scheduling.preemptible)CREATION_TIMESTAMPcreationTimestampmachineTypesMachineType)CPUS	guestCpus	MEMORY_GBnetworksNetwork)r   )MODEx_gcloud_mode)
IPV4_RANGE	IPv4Range)GATEWAY_IPV4gatewayIPv4projectsProject
operations	Operation)r   operationType)r   
targetLinkHTTP_STATUS)	TIMESTAMP
insertTimerP  invalidationsregionBackendServices)r   r   r   r%   r   r   r   r   regionsRegionr@  F)rO   DISKS_GBDISKS_TOTAL_GB	ADDRESSESIN_USE_ADDRESSESRESERVED_ADDRESSESSTATIC_ADDRESSESr   TURNDOWN_DATEzzones[]routesRoute)
DEST_RANGE	destRangeNEXT_HOP)PRIORITYpriority	snapshotsSnapshot)r   )DISK_SIZE_GB
diskSizeGb)SRC_DISK
sourceDiskr   rk  r   subnetworks
Subnetwork)r   r   r   )RANGEipCidrRangetargetHttpProxiesTargetHttpProxy)URL_MAPurlMaprs  targetHttpsProxiesTargetHttpsProxySSL_CERTIFICATESzsslCertificates[]targetSslProxiesTargetSslProxy)PROXY_HEADERproxyHeader)SERVICEservicer|  targetInstancesTargetInstance)r   r   )INSTANCEinstance)
NAT_POLICY	natPolicyr  TargetPoolInstanceHealth
TargetPool)SESSION_AFFINITYsessionAffinity)BACKUP
backupPoolHEALTH_CHECKSr  zhealthChecks[]zinstances[]TargetVpnGateway)r   r   r   User)r   )OWNERownerr   Zone	VpnTunnel)r   r   )GATEWAYtargetVpnGateway)PEER_ADDRESSpeerIpr  Router)r   r   r   )targetPoolInstanceHealthtargetPoolstargetVpnGatewaysuserszones
vpnTunnelsrouters)r   r   r   r  affinityCookieTTLr%   r   r   r   r   r   r   r   
Commitment)r   )ENDSendTimestampr   r   commitmentsLOCATIONSCOPEr  r!  r&  r)  r+  r.  r1  c                 J    U S:X  d  U S:X  a  [         $ SU ;   a  [        $ [        $ )aN  Get Specs for the given API version.

This currently always returns _SPECS_V1, but is left here for the future,
as a pattern for providing different specs for different versions.

Args:
  api_version: A string identifying the API version, e.g. 'v1'.

Returns:
  A map associating each message class name with an _InternalSpec object.
v1v2beta1alpha)	_SPECS_V1_SPECS_ALPHA_SPECS_BETA)api_versions    r   _GetSpecsForVersionr    s-     DK94	r   r   fieldsr   r   r   c                    [        U5      nX;  a  [        SU < SU< S35      eX0   n/ nUR                   H  u  pV[        U[        R
                  5      (       a)  UR                  U[        R                  " U5      45        MM  [        U5      (       a  UR                  XV45        Mq  [        SR                  U5      5      e   [        XR                  5      n[        [        U5      5      n[!        UUUUR"                  UR$                  S9$ )z+Returns a Spec for the given resource type."z"" not found in Specs for version "z5expected function or property in table_cols list: {0}r  )r  KeyErrorr   r   r}   string_typesr   r	   PropertyGettercallable
ValueErrorr   getattrr   listr   r   r   r   )	resource_typemessage_classesr  specr   r   actionr   r  s	            r   GetSpecr    s    	[	)$
!;0 1 1 
	$*oold&#**++0??GHI	&		'Nt& & & /+B+BC-+M:;&	M#"22	
( (r   )T)0__doc__
__future__r   r   r   collectionsapitools.base.protorpcliter   googlecloudsdk.api_lib.computer   r   r	   r}   six.moves.http_clientr   r(   r,   r/   r3   r:   rB   rE   rS   rX   rZ   ra   ri   rm   ry   r   r   r   r   r   r   r   
namedtuple_InternalSpecr   r   r   r  copyr  r  r  r   r  rR   r   r   <module>r     sz   ; &  '  / 9 : < 
 $74
2
2
/(.,<6F ;)X &&
HJR	$
 ++,445
 R	  ='
 _))*++,
 !R	< m*
 23

=R	\ }+)$
  !=!=>

]R	N  6 '(D(DE
 "OR	b ]!
 334_))*_))*

 cR	D %
 _))*
 ER	^ %"67*+2356
 ,,-
 _R	~ }+ '),-
 ++,334
 R	^ m"N+*

 	_R	t M( 
 uR	H ,
IR	b -
cR	| 
=.
 }R	V m"' . 
 WR	p m*
 _))*SM
 qR	P ]1
 _))*o223!5!56

 !QR	v %345ML 	
 334O001*O,@,@A_))*	
 %wR	` -34@7	
 
aR	x M(!23.
 _))*
 yR	V	 $
 
W	R	n	 $o	R	B
 -&%$67 '
 ?778
 C
R	b
 ]&*67 '	
 ?778
 c
R	~
 ]+)$
  !=!=>
	

R	j }#\&U;<&64HI,'9dKL!,>@}%78	
 ,,-
 kR	N m""'-.$
 ,,-
 OR	l %
 ?778
 mR	H }$7
 IR	\ ='
 ,,-++,
 ]R	z ,!

 ++,
 
{R	R --!BC!
 !/"6"67++,
 SR	n ++"!BC	
 !/"6"67,,-
 oR	L }+
 --._))*
 MR	j !.5 '(D(DE
 ! !' 3$;<
 ?//0334O889++,	
 $ '-
 ,,-++,.  !

 	 ! }%78	
 ++,
   &
 ++,!5!568  #
 ,,-++,
 KR		j nn!.'	_%  
_99:" 2 +# 	M  !!.&	]#	$%  
 "  )6-	]#	$%2%1$	 
/../	_112 !)$ %(& 
MO
(r   