
                            S 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                  R*                  5       " S S\5      5       5       rg)z0Command for creating Compute Engine commitments.    N)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.Args7   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.RunB   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)r>   r*   r+   r?   s       r   r,   Update._CreateReferences   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)%ComputeRegionCommitmentsUpdateRequestr0   	_GetPathsrT   rU   )r>   r!   rA   rC   s       r   r6   Update._GetUpdateRequestz   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$ )Nr2   r"   r5   )r2   appendr"   r5   )r>   rC   rS   s      r   rW   Update._GetPaths   sU    E$$0ll;+ll6--9ll'(Lr   Nc                 6    Uc  g [         R                  " X5      $ )N)r   TranslatePlanArg)r>   r!   r"   s      r   r3   !Update._TranslatePlanArgForUpdate   s    |##H33r    )NN)__name__
__module____qualname____firstlineno____doc__detailed_helpr   r   classmethodr   rH   r,   r6   rW   r3   __static_attributes__r_   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   Fr_   Nr`   ra   rb   rc   rd   r   r   rg   r_   r   r   ri   ri      s     +  r   ri   c                        \ rS rSrSrSrSrSrg)UpdateAlpha   r   Tr_   Nrk   r_   r   r   rm   rm      s     +r   rm   )rd   r:   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   rM   .googlecloudsdk.command_lib.compute.commitmentsr<   UniverseCompatibleReleaseTracksr)   GAUpdateCommandr	   BETAri   ALPHArm   r_   r   r   <module>ry      s    7 
 7 9 0 ( E @#D   D%%(()q4T q4 * q4h D%%**+! ! , ! D%%++, *   -  r   