
    i                        d 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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dlmZ ddlmZ ddlmZ ddlmZ ej6                   ej8                  ej:                  j<                  ej:                  j>                         G d dej@                                      Z!y)z>Command for updating instances split for worker-pool resource.    )apis)base)
exceptions)flags)pretty_print)resource_args)stages)instance_split_printer)config_changes)flags_parser)instance_split)worker_pools_operations)concept_parsers)presentation_specs)progress_tracker)resource_printerc                   F    e Zd ZdZdddZed        Zed        Zd Zd Z	y	)
AdjustInstanceSplitz<Adjust the instance assignments for a Cloud Run worker-pool.z"          {description}
          a*            To assign 10% of instances to revision my-worker-pool-s5sxn and
          90% of instances to revision my-worker-pool-cp9kw run:

              $ {command} my-worker-pool --to-revisions=my-worker-pool-s5sxn=10,my-worker-pool-cp9kw=90

          To increase the instances to revision my-worker-pool-s5sxn to 20% and
          by reducing the instances to revision my-worker-pool-cp9kw to 80% run:

              $ {command} my-worker-pool --to-revisions=my-worker-pool-s5sxn=20

          To rollback to revision my-worker-pool-cp9kw run:

              $ {command} my-worker-pool --to-revisions=my-worker-pool-cp9kw=100

          To assign 100% of instances to the current or future LATEST revision
          run:

              $ {command} my-worker-pool --to-latest

          You can also refer to the current or future LATEST revision in
          --to-revisions by the string "LATEST". For example, to set 10% of
          instances to always float to the latest revision:

              $ {command} my-worker-pool --to-revisions=LATEST=10

         )DESCRIPTIONEXAMPLESc                    t        j                  dt        j                  d      ddd      }t	        j
                  |g      j                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  t        j                  t        j                  d       |j                   j#                  t        j                         y )NWORKER_POOLT)promptz'WorkerPool to update instance split of.F)requiredprefixes)hidden)r   ResourcePresentationSpecr   GetV2WorkerPoolResourceSpecr   ConceptParserAddToParserr   AddAsyncFlagAddUpdateInstanceSplitFlagsAddBinAuthzBreakglassFlagr   RegisterFormatterr
   INSTANCE_SPLIT_PRINTER_FORMATInstanceSplitPrinterdisplay_info	AddFormat)clsparserworker_pool_presentations      5lib/surface/run/worker_pools/update_instance_split.py
CommonArgszAdjustInstanceSplit.CommonArgsI   s    1JJ11>1  !!#;"<=II 
v	%%f-	##F+&&<<33
 !!<<    c                 &    | j                  |       y )N)r-   )r)   r*   s     r,   ArgszAdjustInstanceSplit.Argsb   s    NN6r.   c                 ,   t        j                  || j                               }|st        j                  d      |j                  dt        j                  d             |j                  t        j                  | j                                      |S )zBReturns the worker pool config changes with some default settings.z1No instance split configuration change requested.r   N)breakglass_justification)
r   !GetWorkerPoolConfigurationChangesReleaseTrackserverless_exceptionsNoConfigurationChangeErrorinsertconfig_changes_modBinaryAuthorizationChangeappendSetLaunchStageChange)selfargschangess      r,   _GetBaseChangesz#AdjustInstanceSplit._GetBaseChangesf   s    <<d!G !<<
=  NN	44%)	
 NN%::4;L;L;NOPNr.   c                 l   j                   j                  j                         }t        j                  |       fd}t        j                  dd|      }t        j                  |      }| j                        }t        j                  dt        j                         dj                        5  |j                  ||      }j                  rt!        j"                  d       n8|j%                          t'        j(                  |j*                        cd	d	d	       S 	 d	d	d	       y	# 1 sw Y   y	xY w)
z)Update the instance split for the worker.c                 p    j                   j                  j                         j                  }|dz   | z   S )N-)CONCEPTSworker_poolParselocationsId)endpointregionr=   s     r,   DeriveRegionalEndpointz7AdjustInstanceSplit.Run.<locals>.DeriveRegionalEndpoint}   s0    }}((..0<<fc\H$$r.   runv2)address_override_funczUpdating instance split...zUpdating instance split failed)failure_messagesuppress_outputz'Updating instance split asynchronously.N)rC   rD   rE   r   ValidateResourcer   GetGapicClientInstancer   WorkerPoolsOperationsr?   r   StagedProgressTrackerr	   UpdateInstanceSplitStagesasync_UpdateInstanceSplitr   Successresultr   GetInstanceSplitPairsmetadata)r<   r=   worker_pool_refrI   
run_clientworker_pools_clientr   responses    `      r,   RunzAdjustInstanceSplit.Runx   s   mm//557O	?+% ,,t+AJ 2GG ))$/N		/	/$((*8	
 %88

h
 
FG33H4E4EF
 
 	H
 
 
s   3A#D**D3N)
__name__
__module____qualname____doc__detailed_helpclassmethodr-   r0   r?   r^    r.   r,   r   r   #   sM     E	-B  0  $Gr.   r   N)"rb   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   googlecloudsdk.command_lib.runr   r5   r   r   r   r	   *googlecloudsdk.command_lib.run.printers.v2r
   !googlecloudsdk.command_lib.run.v2r   r8   r   r   r   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   UniverseCompatibleReleaseTracksr4   ALPHABETACommandr   re   r.   r,   <module>rs      s    E , ( N 0 7 8 1 M R : < E D G 8 9 D%%++T->->-C-CDrG$,, rG E rGr.   