
    8                        S 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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S.rSr\S-   rS rS rS rS\R2                  S\\   S\R2                  4S jr\R8                  " \R:                  R<                  5      \R>                   " S S\R@                  5      5       5       r!g)z!'vmware clusters update' command.    )absolute_import)division)unicode_literals)List)clusters)actions)arg_parsers)base)flags)util)logz
          Adjust the number of nodes in the VMware Engine cluster. Successful addition or removal of a node results in a cluster in READY state. Check the progress of a cluster using `{parent_command} list`.
        a  
          To resize a cluster called `my-cluster` in private cloud `my-private-cloud` and zone `us-west2-a` to have `3` nodes of type `standard-72`, run:

            $ {command} my-cluster --location=us-west2-a --project=my-project --private-cloud=my-private-cloud --update-nodes-config=type=standard-72,count=3

            Or:

            $ {command} my-cluster --private-cloud=my-private-cloud --update-nodes-config=type=standard-72,count=3

           In the second example, the project and location are taken from gcloud properties core/project and compute/zone.

          To enable autoscale in a cluster called `my-cluster` in private cloud `my-private-cloud` and zone `us-west2-a`, run:

            $ {command} my-cluster --location=us-west2-a --project=my-project --private-cloud=my-private-cloud --autoscaling-min-cluster-node-count=3 --autoscaling-max-cluster-node-count=5 --update-autoscaling-policy=name=custom-policy,node-type-id=standard-72,scale-out-size=1,storage-thresholds-scale-in=10,storage-thresholds-scale-out=80
    )DESCRIPTIONEXAMPLESz
        Information about the type and number of nodes associated with the cluster.

        type (required): canonical identifier of the node type.

        count (required): number of nodes of this type in the cluster.
zx

        custom_core_count: can be passed, but the value will be ignored. Updating custom core count is not supported.
c           	         U R                   R                   Vs/ s H  o"R                  PM     nnU Vs/ s H  oDS   PM	     nn[        R                  " U5      nU(       a  [        R
                  " SU S35      e[        U5      [        U5      -
  nU(       a#  [        R
                  " S[        U5       S35      eU Vs/ s H  n[        R                  " US   US   SS9PM!     sn$ s  snf s  snf s  snf )	a  Parses the node configs parameters passed in the old format.

In the old format, the nodes configs are passed in a way that specifies what
exact node configs should be attached to the cluster after the operation. It's
not possible to remove existing node types. Even unchanged nodes configs have
to be specified in the parameters.

Args:
  existing_cluster: cluster whose nodes configs should be updated
  nodes_configs: nodes configs to be attached to the cluster

Returns:
  list of NodeTypeConfig objects prepared for further processing

Raises:
  InvalidNodeConfigsProvidedError:
    if duplicate node types were specified or if a config for an existing node
    type is not specified
typetypes:  provided more than once.zwhen using `--node-type-config` parameters you need to specify node counts for all node types present in the cluster. Missing node types: .countr   r   r   custom_core_count)	nodeTypeConfigsadditionalPropertieskeyr   FindDuplicatedTypesInvalidNodeConfigsProvidedErrorsetlistNodeTypeConfig)existing_clusternodes_configspropcurrent_node_typesconfigrequested_node_typesduplicated_typesunspecified_typess           4lib/surface/vmware/private_clouds/clusters/update.py_ParseOldNodesConfigsParametersr)   A   s   * ,;;PPP4hhP   8EE}V.}E--.BC

.
.
"##<=  ,-4H0II

.
.	)*+1	.  "	
 "& f~VG_ "	
 ' F 
s   C)C. &C3c           
         U Vs/ s H  o3S   PM	     snU-   n[         R                  " U5      nU(       a  [         R                  " SU S35      e0 nU R                  R                   H%  nUR
                  R                  XgR                  '   M'     U H  nUS   XcS   '   M     U H  nSXh'   M	     UR                  5        VV	s/ s H  u  p[         R                  " XSS9PM     sn	n$ s  snf s  sn	nf )a+  Parses the node configs parameters passed in the new format.

In the new format, the nodes configs are passed using two parameters. One of
them specifies which configs should be updated or created (unchanged configs
don't have to be specified at all). The other lists the configs to be removed.
This format is more flexible than the old one because it allows for config
removal and doesn't require re-specifying unchanged configs.

Args:
  existing_cluster: cluster whose nodes configs should be updated
  updated_nodes_configs: list of nodes configs to update or create
  removed_types: list of node types for which nodes configs should be removed

Returns:
  list of NodeTypeConfig objects prepared for further processing

Raises:
  InvalidNodeConfigsProvidedError:
    if duplicate node types were specified
r   r   r   r   r   r   )
r   r   r   r   r   value	nodeCountr   itemsr   )
r    updated_nodes_configsremoved_typesr$   r%   r&   
node_countr"   	node_typer   s
             r(   _ParseNewNodesConfigsParametersr2   p   s   0 $9#8Vn#8 --.BC

.
.
"##<=  *..CCd:://Jxx D &f!'Jf~ & !iJ !
 )..0
0
) yK0
 )(
s   C)!C.c                    U(       d  gU(       aC  UR                   (       a2  UR                    H"  nX2;   d  M
  [        R                  " SU S35      e   U R                  (       d  [        R                  " SU S35      eU R                  R                  R
                   Vs1 s H  nUR                  iM     nnU H"  nX5;  d  M
  [        R                  " SU S35      e   gs  snf )aR  Checks if the policies specified for removal actually exist and that they are not updated in the same call.

Args:
  existing_cluster: cluster before the update
  updated_settings: updated autoscale settings
  policies_to_remove: list of policy names to remove

Raises:
  InvalidAutoscalingSettingsProvidedError: if the validation fails.
Nzpolicy 'z'' specified both for update and removalznonexistent policies 'z' specified for removal)autoscaling_policiesr   'InvalidAutoscalingSettingsProvidedErrorautoscalingSettingsautoscalingPoliciesr   r   )r    updated_settingspolicies_to_removenamepexisting_policiess         r(   _ValidatePoliciesToRemover=      s     

*?? 55		#::tfCD
 	
 6 
	-	-

6
6
 !3 44KL   33GG\\\! ee\   !d$88"#5"66M
N  !	s    C!autoscaling_settingsr9   returnc                 D    U(       d  U $ U H  nU R                   U	 M     U $ )N)r4   )r>   r9   policys      r(   _RemoveAutoscalingPoliciesrB      s-     
"f11&9 # 
    c                   2    \ rS rSrSr\r\S 5       rS r	Sr
g)Update   z,Update a Google Cloud VMware Engine cluster.c                 h   [         R                  " U SS9  [        R                  R	                  U 5        [        R                  R                  U S5        U R                  R                  S5        U R                  SS[        R                  " [        [        [        S.SS9[        R                  " SS	SS
S9S[        S9  U R                  SS[!        5       [        R                  " [        [        S.SS9S
["        S9  U R                  SSS[!        5       [        S
SS9  U R%                  SS9nUR'                  5       nUR                  S[        SS9  UR                  S[        SS9  UR                  S[        SS9  UR                  S[        R                  " [        [        [        [        [        [        [        [        [        [        [        [        [        S.S/S9S
[!        5       SS 9  UR                  S![        R(                  " 5       S"S9  U R                  S#SS$[!        5       [        S
S%S9  g&)'z Register flags for this command.T)
positionalyamlz--node-type-configF)r   r   zcustom-core-count)r   r   )specrequired_keysziThe {flag_name} option is deprecated; please use --update-nodes-config and --remove-nodes-config instead.append)warnremovedactionz[count=COUNT],[type=TYPE])requiredr   rO   metavarhelpz--update-nodes-config)rP   defaultr   rO   rR   z--remove-nodes-configTYPEz4Type of node that should be removed from the cluster)rP   rQ   rS   r   rO   rR   )rP   z$--autoscaling-min-cluster-node-countz&Minimum number of nodes in the cluster)r   rR   z$--autoscaling-max-cluster-node-countz&Maximum number of nodes in the clusterz--autoscaling-cool-down-periodzQCool down period (in minutes) between consecutive cluster expansions/contractionsz--update-autoscaling-policy)r:   znode-type-idzscale-out-sizezmin-node-countzmax-node-countzcpu-thresholds-scale-inzcpu-thresholds-scale-outz"granted-memory-thresholds-scale-inz#granted-memory-thresholds-scale-outz#consumed-memory-thresholds-scale-inz$consumed-memory-thresholds-scale-outzstorage-thresholds-scale-inzstorage-thresholds-scale-outr:   z/Autoscaling policy to be applied to the cluster)r   rO   rS   rR   z --autoscaling-settings-from-filezLA YAML file containing the autoscaling settings to be applied to the clusterz--remove-autoscaling-policyNAMEzENames of autoscaling policies that should be removed from the clusterN)r   AddClusterArgToParserr
   
ASYNC_FLAGAddToParser
SetDefaultdisplay_info	AddFormatadd_argumentr	   ArgDictstrintr   DeprecationAction_OLD_NODE_TYPE_CONFIG_HELPr   _NODE_TYPE_CONFIG_HELPadd_mutually_exclusive_group	add_groupYAMLFileContents)parserautoscaling_settings_group"inlined_autoscaling_settings_groups      r(   ArgsUpdate.Args   s]    
48OO'OOvt,
!!&)
  #F+
 (( L 
 ,'#  &   ,+
 #  
 C   "(!D!D "E " *D)M)M)O&&33.5 4 
 '33.5 4 
 '33('	 4  '33%   #"%"%"%+.,/697:7:8;/203 "(!
$ >- 4 0 ++*))+	 ,  %  rC   c                    UR                   R                  R                  5       n[        R                  " 5       nUR
                  (       a8  UR                  (       d  UR                  (       a  [        R                  " S5      eUR                  U5      nUR
                  (       a  [        XAR
                  5      nOEUR                  (       d  UR                  (       a!  [        XAR                  UR                  5      nOS nUR                  (       a!  [        R                  " UR                  5      nOUR                  (       d3  UR                   (       d"  UR"                  (       d  UR$                  (       aB  [        R&                  " UR                  UR                   UR"                  UR$                  5      nOS n[)        XFUR*                  5        S nUc  UR*                  (       aA  [        R,                  " U5      n[        R.                  " X5      n[1        XqR*                  5      nUR3                  X%U5      n	UR4                  n
U
(       a!  [6        R8                  " U	R:                  SSS9  g UR=                  UR?                  U	5      SRA                  URC                  5       5      S9n[6        R8                  " URC                  5       SS9  U$ )Nzoflag `--node-type-config` is mutually exclusive with `--update-nodes-config` and `--remove-nodes-config` flags.clusterT)kindis_asyncz&waiting for cluster [{}] to be updated)operation_refmessage)rm   )"CONCEPTSrl   Parser   ClustersClientnode_type_configupdate_nodes_configremove_nodes_configr   r   Getr)   r2   autoscaling_settings_from_file&ParseAutoscalingSettingsFromFileFormat"autoscaling_min_cluster_node_count"autoscaling_max_cluster_node_countautoscaling_cool_down_periodupdate_autoscaling_policy)ParseAutoscalingSettingsFromInlinedFormatr=   remove_autoscaling_policy%ParseAutoscalingSettingsFromApiFormatMergeAutoscalingSettingsrB   rE   async_r   UpdatedResourcer:   WaitForOperationGetOperationRefformatRelativeName)selfargsrl   clientr    configsr8   r>   old_settings	operationrn   resources               r(   Run
Update.RunM  s@   mm##))+G$$&F  D$<$<00H 
 zz'*/
11g 
	!	!T%=%=/
44d6N6Ng g**DD

-
- 	//22,,))GG

1
1

1
1

+
+

(
(	 D,J,J  #t'E'E??
l "::
 8
 > > g0DEI{{H	)..y4H&&,,Y78??  "
 ' H ,,.Y?OrC    N)__name__
__module____qualname____firstlineno____doc__DETAILED_HELPdetailed_helpstaticmethodri   r   __static_attributes__r   rC   r(   rE   rE      s'     5-n n`KrC   rE   N)"r   
__future__r   r   r   typingr   googlecloudsdk.api_lib.vmwarer   googlecloudsdk.callioper   r	   r
   !googlecloudsdk.command_lib.vmwarer   *googlecloudsdk.command_lib.vmware.clustersr   googlecloudsdk.corer   r   rb   ra   r)   r2   r=   AutoscalingSettingsr^   rB   ReleaseTracksReleaseTrackGADefaultUniverseOnlyUpdateCommandrE   r   rC   r(   <module>r      s    ( &  '  2 + / ( 3 ; #	*  4 7  ,^.b$N
22
S	
 

 D%%(()AT A  *ArC   