
    '                     N   S r SSK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J	r	  SSK
Jr  SS	KJr  SS
KJr  SSS.r " S S5      r\R$                  \R&                  " \R(                  R*                  5      \R,                   " S S\R.                  5      5       5       5       rg)z<Command to get capacity advice for Compute Engine resources.    N)base_classes)utils)arg_parsers)base)
exceptions)
completers)flags)
propertiesa  
      Get capacity advice for Compute Engine resources.

      This command helps you view future resource availability for a specific
      number of VM instances, machine type, provisioning model, and zone. After
      you confirm resource availability, you can specify those configurations
      when you create VM instances. This action improves the success rate of
      your VM instance creation request.
    a  
      To check the availability of 100 `n2-standard-32` Spot VMs in any single
      zone in the `us-central1` region, run the following command:

        $ {command}             --region="us-central1"             --provisioning-model="SPOT"             --size=100             --instance-selection-machine-types="n2-standard-32"             --target-distribution-shape="any-single-zone"

      To check the availability of 50 Spot VMs, allowing either `e2-standard-8`
      or `e2-standard-16` machine types, distributed across `us-central1-a` and
      `us-central1-b`, run the following command:

        $ {command}             --region="us-central1"             --provisioning-model="SPOT"             --size=50             --instance-selection="name=my-selection,machine-type=e2-standard-8,machine-type=e2-standard-16"             --target-distribution-shape="any"             --zones="us-central1-a,us-central1-b"
      )DESCRIPTIONEXAMPLESc                   $    \ rS rSrSrS rS rSrg)ArgMultiValueDictB   zConverts argument values into multi-valued mappings.

Values for repeated keys are collected in a list. Ensures all values are
key-value pairs and handles invalid cases.
c                 z    SnSR                  US9n[        R                  " U[        R                  5      U l        g )N=z([^\s{ops}]+)\s*{ops}\s*(.*))ops)formatrecompileDOTALL_key_op_value)selfr   key_op_value_patterns      &lib/surface/compute/advice/capacity.py__init__ArgMultiValueDict.__init__I   s3    
C:AAcAJ$8"))DD    c                    UR                  S5       Vs/ s H  o"R                  5       PM     nn[        R                  " 5       nU GH2  nSU;  a%  [        R
                  " SR                  U5      5      eU R                  R                  U5      nU(       d%  [        R
                  " SR                  U5      5      eUR                  S5      R                  5       UR                  S5      R                  5       pU(       a  U(       d%  [        R
                  " SR                  U5      5      eSU;   a%  [        R
                  " SR                  U5      5      eUR                  U/ 5      R                  U5        GM5     U$ s  snf )N,r   zInvalid flag value [{0}]      )splitstripcollectionsOrderedDictr   ArgumentTypeErrorr   r   matchgroup
setdefaultappend)	r   	arg_valueitemarg_listarg_dictargr'   keyvalues	            r   __call__ArgMultiValueDict.__call__N   sE   )2)=>)=

)=H>&&(H	C++&--c2
 	
   &&s+e++&--c2
 	
 ;;q>'')5;;q>+?+?+A5++&--c2
 	
 
++&--c2
 	
 #r"))%0+ . O3 ?s   E?)r   N)__name__
__module____qualname____firstlineno____doc__r   r2   __static_attributes__ r   r   r   r   B   s    E
r   r   c                   J    \ rS rSrSr\r\R                  r	\
S 5       rS rSrg)Capacityk   z1Get capacity advice for Compute Engine resources.c           	         [         R                  " U 5        [         R                  " U 5        U R                  S[        SSS9  U R                  SSS9nUR                  S[        R                  " 5       SS	S
9  UR                  SSS[        5       S9  [         R                  " U 5        U R                  S[        R                  " 5       [        R                  SSSS9  g)z!Registers flags for this command.z--sizeTz>The total number of VMs being requested in the capacity query.)typerequiredhelpz=Specifies the machine types for which advice is being sought.)r@   rA   z"--instance-selection-machine-typesMACHINE_TYPEzZSpecifies a comma-separated list of preferred machine types for creating virtual machines.)r?   metavarrA   --instance-selectionzNamed selection of machine types. For example, --instance-selection="name=instance-selection-1,machine-type=e2-standard-8,machine-type=t2d-standard-8".INSTANCE_SELECTION)rA   rC   r?   z--zonesZONEFzA comma-separated list of zones to query within the specified region, for example, `us-central1-a,us-central1-b`. If you omit this flag, then you view availability for your requested capacity across all zones in the region.)r?   	completerrC   r@   rA   N)r	   AddRegionFlagAddProvisioningModelFlagadd_argumentint	add_groupr   ArgListr   AddTargetDistributionShapeFlagr   ZonesCompleter)parserinstance_selection_groups     r   ArgsCapacity.Argst   s     
	""6*
M	    &//L  0   )),  "%	 *  ))C %  *  
((0
  "++/  r   c                 D   [         R                  " U R                  5       5      nUR                  nUR                  n[
        R                  " XR                  5        UR                  S5      (       a,  UR                  S5      (       a  [        R                  " S5      eUR                  (       a7  UR                  R                  S5      (       d  [        R                  " SS5      e[        R                  R                   R"                  R%                  5       nUR&                  nU(       d4  UR(                  (       a#  [*        R,                  " UR(                  S   5      nU=(       d2    [        R                  R.                  R&                  R1                  5       nU(       d  [        R2                  " SS	5      eUR5                  UR4                  R7                  UR8                  5      S
9nUR;                  US9nSn	UR                  S5      (       a%  UR<                  R?                  UR@                  5      n	Sn
UR(                  (       a^  / n
UR(                   HL  nUR                  RC                  USU0SS9nU
RE                  URG                  URI                  5       S95        MN     UR=                  U	S9nU
(       a  Xl        0 nSnUR                  (       aT  UR                  R                  S5      nU(       a  US   OUnURK                  UR                  R                  S5      S9UU'   URL                  (       a  URK                  URL                  S9X'   / nURO                  5        H9  u  nnURE                  URP                  RR                  RU                  UUS95        M;     URP                  RS                  US9nURQ                  US9nURW                  UUUURX                  S9nUR[                  UUUS9nUR\                  R^                  Ra                  U5      $ )z!Runs the capacity advice command.instance_selection instance_selection_machine_typesz3Exactly one 'instance-selection' must be specified.zmachine-typerD   z.At least one 'machine-type' must be specified.r   z--regionz*The [compute/region] property must be set.)provisioningModel)
schedulingNtarget_distribution_shapeprojectzcompute.zones)params
collection)zone)targetShapezinstance-selection-1name)machineTypes)r0   r1   )additionalProperties)instanceSelections)distributionPolicyinstanceFlexibilityPolicyinstancePropertiessize)rZ   regioncapacityAdviceRequest)1r   ComputeApiHolderReleaseTrackclientmessagesr	   ValidateZonesAndRegionFlags	resourcesIsSpecifiedr   ConflictingArgumentsExceptionrU   getInvalidArgumentExceptionr
   VALUEScorerZ   	GetOrFailrg   zonesr   ZoneNameToRegionNamecomputeGetRequiredArgumentException1CapacityAdviceRequestInstancePropertiesScheduling ProvisioningModelValueValuesEnumprovisioning_model'CapacityAdviceRequestInstanceProperties'CapacityAdviceRequestDistributionPolicyTargetShapeValueValuesEnumrY   Parser*   8CapacityAdviceRequestDistributionPolicyZoneConfigurationSelfLink?CapacityAdviceRequestInstanceFlexibilityPolicyInstanceSelectionrV   items.CapacityAdviceRequestInstanceFlexibilityPolicyInstanceSelectionsValueAdditionalPropertyCapacityAdviceRequestrf   ComputeAdviceCapacityRequestapitools_clientadvicer<   )r   argsholderrk   rl   rZ   rg   rX   instance_propertiestarget_shapezone_configsr]   zone_refdistribution_policyselections_mapdefault_instance_selection_nameselection_name_listselection_nameadditional_propertiesr0   r1   instance_selections_valueinstance_flexibility_policyinner_requestouter_requests                            r   RunCapacity.Run   s   **4+<+<+>?F]]FH	%%d,<,<=,--$2B2B*3 3 44
?  t'>'>'B'B( ( //
 
: 
 $$,,668G[[Fdjj ))$**Q-8f=z((0077;;=F00
BD D KK"TTuu##
 L J
 #JJ K  L344

:
:
U
U,,.  Lzzl**$##))w'& * ( 	MM&&( N *	+  #JJ  K "".N&<# 3377? ! a
 .  
R
R2266~F S  ^$
 ,,

R
R@@ S  5 $**,
U""

A
A
Y
Y
l
lU m $ - 	??WW!6 	X 	
  	??8 	@ 	
   22."=.YY	 3 M 99+ : M !!((11-@@r   r:   N)r4   r5   r6   r7   r8   DETAILED_HELPdetailed_helpr   COMPUTE_CATEGORYcategorystaticmethodrR   r   r9   r:   r   r   r<   r<   k   s1     :-""(, ,\sAr   r<   )r8   r$   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper   r   r   "googlecloudsdk.command_lib.computer   )googlecloudsdk.command_lib.compute.advicer	   googlecloudsdk.corer
   r   r   DefaultUniverseOnlyReleaseTracksrj   ALPHAHiddenCommandr<   r:   r   r   <module>r      s    C  	 7 0 / ( . 9 ; *
!H& &R D%%++,hAt|| hA  - hAr   