
    k                     &   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Jr  SS
KJr  Sr\R"                  \R$                  " \R&                  R(                  5       " S S\R*                  5      5       5       r\R"                  \R$                  " \R&                  R.                  5       " S S\5      5       5       r\R"                  \R$                  " \R&                  R2                  5       " S S\5      5       5       rg)z0Command for creating Compute Engine commitments.    )absolute_import)division)unicode_literalsN)base_classes)request_helper)utils)base)flagszQuota .COMMITMENTS. exceeded.+c                   Z    \ rS rSrSrSS0rSrSr\S 5       r	S r
S rS	 rS
 rSS jrSrg)Update!   "Update Compute Engine commitments.EXAMPLESaT  
        To enable auto renewal on a commitment called ``commitment-1'' in the ``us-central1''
        region, run:

          $ {command} commitment-1 --auto-renew --region=us-central1

        To disable auto renewal on a commitment called ``commitment-1''
        in the ``us-central1'' region, run:

          $ {command} commitment-1 --no-auto-renew --region=us-central1

        To upgrade the term of a commitment called ``commitment-1''
        from  12-month to 36-month, in the ``us-central1'' region, run:

          $ {command} commitment-1 --plan=36-month --region=us-central1
      Fc                     [         R                  " SS9R                  USS9  [         R                  " XR                  U R
                  S9  [         R                  " U5        g )NF)pluralupdate)operation_type)support_60_month_plansupport_24_month_plan)r
   MakeCommitmentArgAddArgumentAddUpdateFlags_support_60_month_plan_support_24_month_planAddCustomEndTime)clsparsers     )lib/surface/compute/commitments/update.pyArgsUpdate.Args:   sW    	5)55x 6  
&@&@!88 
6"    c           	         [         R                  " U R                  5       5      nUR                  nUR                  nU R                  X4U5      nUR                  R                  nUR                  R                  R                  nUR                  UR                  5       S9n[        R                  " U5      Ul        U R                  XaR                  S9Ul        [        R                   " U5      Ul        U R%                  XeU5      n	UR                  R&                  n
UR                  R                  R(                  n/ n[+        [,        R.                  " USU	4/UU
US95      n[1        U5       H9  u  p[2        R4                  " [6        US   5      (       d  M*  US   US   S-   4X'   M;     U(       a  [8        R:                  " U5        U$ )N)name)messagesplanr   )requestshttp	batch_urlerrors   r   z~ You can request commitments quota on https://cloud.google.com/compute/docs/instances/signing-up-committed-use-discounts#quota)r   ComputeApiHolderReleaseTrackclient	resources_CreateReferencer$   apitools_clientregionCommitments
CommitmentNamer
   TranslateAutoRenewArgForUpdate	autoRenew_TranslatePlanArgForUpdater%   TranslateCustomEndTimeArgcustomEndTimestamp_GetUpdateRequestr(   r'   listr   MakeRequests	enumeraterematch _MISSING_COMMITMENTS_QUOTA_REGEXr   RaiseToolException)selfargsholderr-   r.   commitment_refr$   servicecommitment_resourcecommitment_update_requestr(   r'   r)   resultierrors                   r   Run
Update.RunE   s   **4+<+<+>?F]]F  I**6dCN}}%%Hmm++==G"-->3F3F3H-I$)$H$H$N!#>>		  ?   .3-L-L.* !% 6 6"5! ''I==((--DF##*CDE		
F f%	2E!H	=	=!H!H;
	 & v&Mr!   c                 t    [         R                  " S5      R                  UU[        R                  " U5      S9$ )NF)scope_lister)r
   r   ResolveAsResourcecompute_flagsGetDefaultScopeLister)rA   r-   r.   rB   s       r   r/   Update._CreateReferencev   s9    ""5);;"88@ <  r!   c                     UR                  UR                  5       UU R                  U5      UR                  UR                  S9$ )N)
commitmentcommitmentResourcepathsprojectregion)%ComputeRegionCommitmentsUpdateRequestr3   	_GetPathsrW   rX   )rA   r$   rD   rF   s       r   r9   Update._GetUpdateRequest}   sH    99!&&(.nn01&&$$ :  r!   c                     / nUR                   b  UR                  S5        UR                  b  UR                  S5        UR                  b  UR                  S5        U$ )Nr5   r%   r8   )r5   appendr%   r8   )rA   rF   rV   s      r   rZ   Update._GetPaths   sU    E$$0ll;+ll6--9ll'(Lr!   Nc                 6    Uc  g [         R                  " X5      $ )N)r
   TranslatePlanArg)rA   r$   r%   s      r   r6   !Update._TranslatePlanArgForUpdate   s    |##H33r!    )NN)__name__
__module____qualname____firstlineno____doc__detailed_helpr   r   classmethodr   rK   r/   r9   rZ   r6   __static_attributes__rb   r!   r   r   r   !   sP     +  
 -" ! # #/b4r!   r   c                        \ rS rSrSrSrSrSrg)
UpdateBeta   r   Frb   Nrc   rd   re   rf   rg   r   r   rj   rb   r!   r   rl   rl      s     +  r!   rl   c                        \ rS rSrSrSrSrSrg)UpdateAlpha   r   Trb   Nrn   rb   r!   r   rp   rp      s     +r!   rp   )rg   
__future__r   r   r   r=   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.computer
   rP   .googlecloudsdk.command_lib.compute.commitmentsr?   UniverseCompatibleReleaseTracksr,   GAUpdateCommandr   BETArl   ALPHArp   rb   r!   r   <module>r}      s    7 &  ' 	 7 9 0 ( E @#D   D%%(()q4T q4 * q4h D%%**+! ! , ! D%%++, *   -  r!   