
    %                     >   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
  \R                  " S5      \R                  " S5      S	.r\R                  \R                  " \R                  R                   5       " S
 S\R"                  5      5       5       r\\l        g)z6Command to update a cluster-director cluster resource.    N)utils)base)flags)loga|  
        *{command}* facilitates the updation of a cluster resource.

        There are following ways to update a cluster:
        - [Preferred] Use granular flags to update cluster specs, based on read-modify-update pattern.
          - Read the existing cluster specs through `get` cluster request.
          - Modify the cluster specs through granular flags.
          - Update the cluster specs through `patch` cluster request.
        - Use --config with cluster specs and --update-mask flags, both in JSON format.
          - Map and repeated fields update requires existing and new values.
          - For e.g. if we want to update a cluster to add a new nodeset, then we will use the update_mask "orchestrator.slurm.node_sets", and the patch cluster must include all the existing nodesets as well as the new one.

        Please refer to the examples below for more details.
        aa  
        To update a cluster `my-cluster` in location `us-central1-a` with granular flags, run the following example:

        Add labels, compute instances, slurm node sets, slurm partitions and update description and default partition:

        $ {command} my-cluster --location us-central1-a         --description "My updated cluster description"         --add-labels env=prod,client=gcloud-cli         --add-on-demand-instances id=compute1,zone=us-central1-a,machineType=n2-standard-2         --add-reserved-instances id=compute2,reservation=zones/us-central1-a/reservations/{reservation},machineType={machineType}         --add-spot-instances id=compute3,zone=us-central1-a,machineType=n2-standard-2         --add-dws-flex-instances id=compute4,zone=us-central1-a,machineType=a4-highgpu-8g,maxDuration=10000s         --add-new-lustre-instances lustre=locations/us-central1-a/instances/lustre1,capacityGb=1024,filesystem=lustre1         --add-lustre-instances locations/us-central1-a/instances/lustre0         --add-slurm-node-sets id=nodeset1,computeId=compute1         --add-slurm-node-sets id=nodeset2,computeId=compute2         --add-slurm-node-sets id=nodeset3,computeId=compute3         --add-slurm-node-sets id=nodeset4,computeId=compute4         --add-slurm-partitions id=partition1,nodesetIds=[nodeset1]         --add-slurm-partitions id=partition2,nodesetIds=[nodeset2,nodeset3,nodeset4]         --slurm-default-partition partition1

        Update slurm node sets and slurm partitions:

        $ {command} my-cluster --location us-central1-a         --update-slurm-node-sets id=nodeset1,staticNodeCount=2,maxDynamicNodeCount=10         --update-slurm-partitions id=partition1,nodesetIds=[nodeset0],exclusive=true

        Remove slurm node sets, slurm partitions and compute instances and update default partition:

        $ {command} my-cluster --location us-central1-a         --slurm-default-partition partition0         --remove-labels env,client         --remove-lustre-instances locations/us-central1-a/instances/lustre0         --remove-slurm-partitions partition1         --remove-slurm-partitions partition2         --remove-slurm-node-sets nodeset1         --remove-slurm-node-sets nodeset2         --remove-slurm-node-sets nodeset3         --remove-slurm-node-sets nodeset4         --remove-on-demand-instances compute1         --remove-reserved-instances compute2         --remove-spot-instances compute3         --remove-dws-flex-instances compute4

        Or cluster `my-cluster` in location `us-central1-a` with config JSON run the following JSON example:

        $ {command} my-cluster --location=us-central1-a --update-mask=labels --config='{"key": "value"}'

        Or create a JSON file `my-cluster-config.json` with the cluster specs and run the following file example:

        $ {command} my-cluster --location=us-central1-a --update-mask=labels --config-from-file=my-cluster-config.json

        Or create a JSON file with the update mask and run the following file example:

        $ {command} my-cluster --location=us-central1-a --update-mask-from-file=my-update-mask.json --config-from-file=my-cluster-config.json
        )DESCRIPTIONEXAMPLESc                   .    \ rS rSrSr\S 5       rS rSrg)Updatef   z$Updates a Cluster Director resource.c                     [         R                  R                  U5        [        R                  " U R                  5       5      n[        R                  " XS9  UR                  SSSS9nUR                  SS9n[        R                  " XBSS9  [        R                  " XBSS9  UR                  SS9n[        R                  " XRS9  [        R                  " XRSS	9  [        R                  " XRSS	9  [        R                  " XRSS	9  [        R                   " XRSS	9  [        R"                  " XRSS	9  [        R$                  " XRSS	9  [        R&                  " XRSS	9  [        R(                  " XRSS	9  [        R*                  " XRSS	9  [        R,                  " XRSS	9  [        R.                  " XRSS	9  [        R0                  " XRSS	9  [        R2                  " XRSS	9  [        R4                  " XRS9  [        R6                  " XRSS	9  g
)zbSpecifies command flags.

Args:
  parser: argparse.Parser: Parser object for command line inputs.
)parserapi_versionz4Cluster configuration for provisioning with updates.T)helpmutexrequiredz"Cluster configuration for updates.)r   )r   r   r   z.Flag Configurations to define cluster updates.)r   r   include_update_flagsN)r   
ASYNC_FLAGAddToParser	api_utilsGetApiVersionReleaseTrackr   AddClusterNameArgToParser	add_groupr   	AddConfigAddUpdateMaskAddDescription	AddLabelsAddCreateFilestoresAddFilestoresAddGcsBucketsAddCreateGcsBucketsAddCreateLustres
AddLustresAddOnDemandInstancesAddSpotInstancesAddReservedInstancesAddDwsFlexInstancesAddSlurmNodeSetsAddSlurmPartitionsAddSlurmDefaultPartitionAddSlurmLoginNode)clsr   r   groupconfig_group
flag_groups         /lib/surface/cluster_director/clusters/update.pyArgsUpdate.Argsk   s    	OO'))#*:*:*<=K	##6KC  E
 ??1 # L 
OO<4P	t = ! J 

D	OO 
 
 
 
 
 
 
 
 
 
 
 
 
""*N	    c                 z   U R                  5       n[        R                  " U5      n[        R                  " U5      nSnUR	                  S5      (       d  [        R
                  " X1U5      n[        R                  " XUS9nUR                  nUR	                  S5      (       a  UR                  5       u  pOUR                  5       u  pUR                  R                  UR                  UR                  5       UU	S95      n
[        R                   R#                  SR%                  UR'                  5       5      5        UR(                  (       a  U
$ [        R*                  " UU
SR%                  U
R,                  5      SS9n[        R                   R#                  S	R%                  UR'                  5       5      5        U$ )
zConstructs and sends request.

Args:
  args: argparse.Namespace, An object that contains the values for the
    arguments specified in the .Args() method.

Returns:
  ProcessHttpResponse of the request made.
Nconfig)argsmessage_moduleexisting_cluster)namecluster
updateMaskz Update request issued for: [{0}]z'Waiting for operation [{0}] to completei  )client	operationmessagemax_wait_seczUpdated cluster [{0}].)r   r   GetClientInstanceGetMessagesModuleIsSpecified
GetClusterr   ClusterUtilcluster_refMakeClusterPatchFromConfigMakeClusterPatchprojects_locations_clustersPatch8HypercomputeclusterProjectsLocationsClustersPatchRequestRelativeNamer   statusPrintformatNameasync_WaitForOperationr9   )selfr6   release_trackr<   messagesr8   cluster_utilrE   cluster_patchupdate_maskr=   responses               r0   Run
Update.Run   s    %%'M((7F**=9HH%%"--fHE$$=ML **K!!#/#J#J#L m[#/#@#@#B m2288II))+!" 	J 	
I JJ*11+2B2B2DE {{))9@@NN
 H JJ-44[5E5E5GHIOr3    N)	__name__
__module____qualname____firstlineno____doc__classmethodr1   rY   __static_attributes__r[   r3   r0   r
   r
   f   s!     -C CJ0r3   r
   )r`   textwrap*googlecloudsdk.api_lib.hypercomputeclusterr   r   googlecloudsdk.callioper   4googlecloudsdk.command_lib.cluster_director.clustersr   googlecloudsdk.corer   dedentDETAILED_HELPDefaultUniverseOnlyReleaseTracksr   ALPHAUpdateCommandr
   detailed_helpr[   r3   r0   <module>ro      s     =  I ( F F # ?? $   8! 8HV D%%++,yT y - yx % r3   