
                         &   d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 dd	l
mZ dd
lmZ dd
lmZ dZej"                   ej$                  ej&                  j(                         G d dej*                                      Zej"                   ej$                  ej&                  j.                         G d de                    Zej"                   ej$                  ej&                  j2                         G d de                    Zy)z0Command for creating Compute Engine commitments.    )absolute_import)division)unicode_literalsN)base_classes)request_helper)utils)base)flagszQuota .COMMITMENTS. exceeded.+c                   L    e Zd ZdZddiZdZed        Zd Zd Z	d Z
d	 ZddZy
)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                     t        j                  d      j                  |d       t        j                  || j                         t        j
                  |       y )NF)pluralupdate)operation_type)support_60_month_plan)r
   MakeCommitmentArgAddArgumentAddUpdateFlags_support_60_month_planAddCustomEndTime)clsparsers     )lib/surface/compute/commitments/update.pyArgszUpdate.Args9   sP    	5)55x 6  
c&@&@ 
6"    c                    t        j                  | j                               }|j                  }|j                  }| j                  |||      }|j                  j                  }|j                  j                  j                  }|j                  |j                               }t        j                  |      |_        | j                  ||j                        |_        t        j                   |      |_        | j%                  |||      }	|j                  j&                  }
|j                  j                  j(                  }g }t+        t-        j.                  |d|	fg||
|            }t1        |      D ]3  \  }}t3        j4                  t6        |d         s$|d   |d   dz   f||<   5 |rt9        j:                  |       |S )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   Runz
Update.RunC   s   **4+<+<+>?F]]F  I**69dCN}}%%Hmm++==G"-->3F3F3H-I$)$H$H$N!#>>		  ?   .3-L-L.* !% 6 6."5! ''I==((--DF##*CDE		
F f%5	2E!H	=!H!H;
q	 & v&Mr   c                 v    t        j                  d      j                  ||t        j                  |            S )NF)scope_lister)r
   r   ResolveAsResourcecompute_flagsGetDefaultScopeLister)r=   r)   r*   r>   s       r   r+   zUpdate._CreateReferencet   s9    ""5);;"88@ <  r   c                     |j                  |j                         || j                  |      |j                  |j                        S )N)
commitmentcommitmentResourcepathsprojectregion)%ComputeRegionCommitmentsUpdateRequestr/   	_GetPathsrQ   rR   )r=   r    r@   rB   s       r   r5   zUpdate._GetUpdateRequest{   sH    99!&&(.nn01&&$$ :  r   c                     g }|j                   |j                  d       |j                  |j                  d       |j                  |j                  d       |S )Nr1   r!   r4   )r1   appendr!   r4   )r=   rB   rP   s      r   rT   zUpdate._GetPaths   sU    E$$0ll;+ll6--9ll'(Lr   Nc                 4    |y t        j                  ||      S )N)r
   TranslatePlanArg)r=   r    r!   s      r   r2   z!Update._TranslatePlanArgForUpdate   s    |##Hd33r   )NN)__name__
__module____qualname____doc__detailed_helpr   classmethodr   rG   r+   r5   rT   r2    r   r   r   r   !   sJ     +  
 -" !# #/b4r   r   c                       e Zd ZdZdZy)
UpdateBetar   FNrY   rZ   r[   r\   r   r_   r   r   ra   ra      s     + r   ra   c                       e Zd ZdZdZy)UpdateAlphar   TNrb   r_   r   r   rd   rd      s     +r   rd   )r\   
__future__r   r   r   r9   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.computer
   rK   .googlecloudsdk.command_lib.compute.commitmentsr;   UniverseCompatibleReleaseTracksr(   GAUpdateCommandr   BETAra   ALPHArd   r_   r   r   <module>rp      s    7 &  ' 	 7 9 0 ( E @#D   D%%(()o4T o4 * o4d D%%**+! ! , ! D%%++, *   -  r   