
    :                         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 rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rSS jrS rS rSS jrS rS rS r g)z<Flags for the compute global vm extension policies commands.    N)arg_parsers)
exceptions)flags)labels_util)filesc                 $    U R                  SSS9  g)zAdds the Description flag.z--descriptionz>An optional textual description for the this extension policy.)helpNadd_argumentparsers    Llib/googlecloudsdk/command_lib/compute/global_vm_extension_policies/flags.pyAddPolicyDescriptionr      s    K      c           	      f    S[         4S jnU R                  S[        R                  " USSS9SSS	9  g
)zAdds the Priority flag.returnc           	           [        U 5      nXs=::  a  U::  d"  O  [        R                  " SU SU SU S35      eU$ ! [         a    [        R                  " SU  S35      ef = f)zECustom type function to validate an integer within a specified range.'z' is not a valid integer.zValue 'z' is not in the range [-z].)int
ValueErrorcompute_flagsBadArgumentException)	arg_valuemin_valmax_valvalues       r   ValidatePriority+AddPolicyPriority.<locals>.ValidatePriority%   s    )ne ''..E71'!G9B
G  L  ..i[1
2 s	   = %A"z
--priorityr   i  )r   r   i  a  
      The priority of the policy. Lower the number, higher the priority.
      When two policies tries to apply the same extension, the one with the higher priority takes precedence.
      If the priority is the same, the one with the more recent update timestamp takes precedence.
      When a policy is deleted, the extension would remain installed on the VM if a lower priority policy still applies.

      Range from 0 to 65535. Default is 1000.
      )typedefaultr	   N)r   r   	functoolspartial)r   r   s     r   AddPolicyPriorityr$   "   sA    s  	-q%H
	  r   c                 (    U R                  SS/ SS9  g)zAdds the InclusionLabels flag.z--inclusion-labelsappenda  
      A list of inclusion labels to select the target VMs.

      The expected format for a single selector is "key1=value1,key2=value2".
      A VM is selected if it has ALL the inclusion labels.

      When the option is specified multiple times, it assumes a logical OR between the selectors.

      For example, if the inclusion labels are ["env=prod,workload=frontend", "workload=backend"], the following VMs will be selected:
      - VM1: env=prod, workload=frontend, something=else
      - VM2: env=prod, workload=backend
      But not:
      - VM3: env=prod

      If not specified, ALL VMs in the project/folder will be selected.
      )actionr!   r	   Nr
   r   s    r   AddPolicyInclusionLabelsr(   C   s#    
	  r   c                 n    U R                  SS[        R                  / S[        R                  " SS9SS9  g)	zAdds the Extensions flag.z--extensionsTEXTENSION_NAME   
min_lengthz1One or more extensions to be added to the policy.)requiredr'   r!   metavarr    r	   N)r   r   StoreOnceActionArgListr   s    r   AddExtensionsr2   \   s;    ((!,>  r   c           
      n    U R                  S[        R                  " SS90 S[        R                  SSS9  g)	zAdds --version flag.	--versionr+   r,   	KEY=VALUEFa  
      A comma separated key:value list where the key is the extension name and the value is the
      desired version for the given extension. The extension name must be one of the extensions
      specified in the --extensions flag. If no version is specified for an
      extension, the latest version will be used and will be upgraded automatically.

      E.g. --version=filestore=123ABC,ops-agent=456DEF

      Raises:
        ArgumentTypeError: If the extension name is not specified in the
        --extensions flag.
      r    r!   r/   r'   r.   r	   Nr   r   ArgDictr0   r   s    r   AddExtensionVersionr9   i   s=    !,((
  r   c           
      n    U R                  S[        R                  " SS90 S[        R                  SSS9  g)	zAdds the --config flag.--configr+   r,   r5   Fa  
      A comma separated key:value list where the key is the extension name and the value is the
      desired config for the given extension. The extension name must be one of the extensions
      specified in the --extensions flag.

      E.g. --config=filestore='filestore config',ops-agent='ops agent config'

      Raises:
        ArgumentTypeError: If the extension name is not specified in the
        --extensions flag.
      r6   Nr7   r   s    r   AddExtensionConfigsr<      s=    !,((

  r   c           
      n    U R                  S[        R                  " SS90 S[        R                  SSS9  g)	z!Adds the --config-from-file flag.--config-from-filer+   r,   zKEY=FILE_PATHFa&  
      Same as --config except that the value for the entry will be read from a
      local file. The extension name must be one of the extensions specified in
      the --extensions flag.

      It is an error to specify the same extension in both --config and
      --config-from-file.
      r6   Nr7   r   s    r   AddExtensionConfigsFromFiler?      s=    !,((
  r   c           	      L    U R                  S/ SQS[        R                  SSS9  g)z(Adds the --rollout-predefined-plan flag.z--rollout-predefined-plan)fast_rolloutrollout_plan_unspecifiedslow_rolloutNFz
      Provide the name of a predefined rollout plan from
      [fast_rollout, slow_rollout] to be used for the rollout.

      One of either --rollout-predefined-plan or --rollout-custom-plan must be specified,
      but not both.
      )choicesr!   r'   r.   r	   r   r   r0   r   s    r   AddRolloutPredefinedPlanrF      s3    !
 ((
  r   c                 F    U R                  SS[        R                  SSS9  g)z$Adds the --rollout-custom-plan flag.z--rollout-custom-plan Fz
      Provide the name of a custom rollout plan to be used for the rollout.

      One of either --rollout-predefined-plan or --rollout-custom-plan must be specified,
      but not both.
      r!   r'   r.   r	   NrE   r   s    r   AddRolloutCustomPlanrJ      s,    ((
  
r   c                 F    U R                  SS[        R                  SSS9  g)z*Adds the --rollout-conflict-behavior flag.z--rollout-conflict-behaviorrH   Fa  
      Specifies the behavior of the Rollout if a conflict is detected in a
      project during a Rollout. Default behavior is to keep the local value
      if conflict happens. Specifying 'overwrite' will overwrite the local value
      if conflict happens.

      The default value for --rollout-conflict-behavior is ''. If you set this
      flag to overwrite and would like to go back to the default value,
      use the update command and omit the --rollout-conflict-behavior flag.
      rI   NrE   r   s    r   AddRolloutConflictBehaviorrL      s,    #((	
  r   c                 F    U R                  SS[        R                  SSS9  g)z#Adds the --rollout-retry-uuid flag.--rollout-retry-uuidrH   Fzr
      The UUID of the rollout retry action. Only set it if this is a retry
      for an existing resource.
      rI   NrE   r   s    r   AddRolloutRetryUUIDrO      s,    ((
  r   c                  0    [         R                  " SSSSS9$ )Nzglobal vm extension policyz!compute.globalVmExtensionPoliciesTF)resource_nameglobal_collectionr.   plural)r   ResourceArgument r   r   MakeGlobalVmExtensionPolicyArgrV      s!    		'	'0;	
 r   c                     [        U 5        [        U 5        [        U 5        [        U 5        [	        U 5        [        U 5        [        U 5        [        U 5        g)z)Adds the flags for a VM extension policy.N)r   r$   r(   r2   r9   r<   r?   AddRolloutInputArgsr   s    r   AddExtensionPolicyArgsrY      sB    vF6"fff%fr   c                 F    [        U 5        [        U 5        [        U 5        g)z"Adds the flags for a rollout plan.N)rF   rJ   rL   r   s    r   rX   rX     s    6"vV$r   c                    [        U 5      nU(       aA  [        UR                  5       5      nXC-
  nU(       a  [        R                  " SSU SU  35      eU(       aA  [        UR                  5       5      nXc-
  nU(       a  [        R                  " SSU SU  35      eU(       a^  U(       aV  [        UR                  5       5      [        UR                  5       5      -  nU(       a  [        R                  " SSU S35      eggg)	zParses the extension configs.r;   Extensions z; from --config are not specified in the --extensions flag. r>   zE from --config-from-file are not specified in the --extensions flag. z--config and --config-from-filez7 are specified in both --config and --config-from-file.Nsetkeysr   r   )
extensionsconfigsconfig_from_fileextensions_setconfig_extensions_setextra_extensionsconfig_from_file_extensions_setcommon_extensionss           r   ParseExtensionConfigsrh   	  s   z?./,=++
() *%%/L2 
 &)*:*?*?*A&B#6G++
() *22<? 
 !GLLN+c2B2G2G2I.JJ++
+)* +! !   "Wr   c                     U (       a  U(       a  [         R                  " SS5      eU (       d  U(       d  [         R                  " SS5      egg)zParses the rollout plan.z3--rollout-predefined-plan and --rollout-custom-planzQOnly one of --rollout-predefined-plan and --rollout-custom-plan can be specified.zMOne of --rollout-predefined-plan and --rollout-custom-plan must be specified.N)r   r   )rollout_predefined_planrollout_custom_plans     r   ParseRolloutPlanrl   (  sN    !4

)
)=	 
 
!)<

)
)=	  *=	 r   c                     U(       d  g[        U 5      n[        UR                  5       5      nX2-
  nU(       a  [        R                  " SSU SU  35      eg)zParses the extension versions.Nr4   r\   z< from --version are not specified in the --extensions flag. r]   )r`   versionsrc   versions_extensions_setre   s        r   ParseExtensionVersionsrp   8  sa    	
z?.0,=

)
)
&' (##-,	0  r   c                     U(       a  U(       a  [         R                  " SS5      eU R                  (       aG  U(       a&  U R                  UR                  R                  l        gU(       a  U R                  Ul        ggg)z6Inserts the retry UUID into the resource if it exists.rN   z>Only one of gve_policy and rollout_operation_input can be set.N)r   r   rollout_retry_uuidrolloutOperationrolloutInput	retryUuid)args
gve_policyrollout_operation_inputs      r   InsertRetryUuidry   G  sl    
 +

)
)H  


!
! !!..8 
!*.*A*A' 
! r   c           
      t   0 nU R                   (       a  UR                  U R                   5        [        U SS5      (       a<  U R                  R	                  5        H  u  p# [
        R                  " U5      X'   M      U$ ! [
        R                   a$  n[        R                  " SU SU SU 35      eSnAff = f)z*Returns a dictionary of extension configs.rb   NzCould not read config file [z] for extension [z]: )
configupdategetattrrb   itemsr   ReadFileContentsErrorr   BadFileException)rv   ra   	extension	file_pathes        r   _GetConfigsr   Z  s    '	[[NN4;;T%t,, $ 5 5 ; ; =	
"33I> !> 
. [[ 
))*9+ 63qc#
 	

s   !A??B7B22B7c                 <   [        U R                  U R                  5        SnU R                  (       a3  UR                  R	                  U R                  R                  5       5      nUR                  UU R                  =(       d    SU R                  =(       d    SS9$ )zQBuilds the RolloutOperation input resource given the resource reference and args.N)predefinedRolloutPlannameconflictBehavior)rl   rj   rk   3GlobalVmExtensionPolicyRolloutOperationRolloutInput$PredefinedRolloutPlanValueValuesEnumupperrollout_conflict_behavior)rv   messagesrj   s      r   BuildRolloutOperationInputr   k  s     4//1I1IJ 	!!&ZZ$$**,
 
	E	E3##+t55= 
F 
 r   c                 6  ^^ U4S jnUU4S jn[        TR                  TR                  TR                  5        [	        TR                  TR
                  5        TR                  U R                  5       TR                  TR                  TR                  R                  U" 5       S9TR                   Vs/ s H<  nTR                  TR                  TR                  R                  U" U5      S9S9S9PM>     snTR                  [!        TT5      S9S9$ s  snf )zLBuilds the VmExtensionPolicy resource given the resource reference and args.c           	         > [         R                  " U R                  S5      5      =(       d    0 R                  5        VVs/ s H)  u  pTR                  R
                  R                  UUS9PM+     snn$ s  snnf )N,keyr   )r   ValidateAndParseLabelssplitr~   $GlobalVmExtensionPolicyLabelSelectorInclusionLabelsValueAdditionalProperty)inclusion_labelsr   r   r   s      r   BuildInclusionLabelsValue?BuildGlobalVmExtensionPolicy.<locals>.BuildInclusionLabelsValue  s~     ../?/E/Ec/JK 
%'	
JC	 	55JJ]] 	^ 	
	 	 	s   0A5c                     > [        T5      n TR                   Vs/ s Hf  nTR                  R                  R	                  UTR                  U R                  U5      TR                  =(       d    0 R                  U5      S9S9PMh     sn$ s  snf )N)stringConfigpinnedVersionr   )r   r`   GlobalVmExtensionPolicyExtensionPoliciesValuer   &GlobalVmExtensionPolicyExtensionPolicygetversion)ra   r   rv   r   s     r   BuildExtensionPoliciesValueABuildGlobalVmExtensionPolicy.<locals>.BuildExtensionPoliciesValue  s    $G 	 )I 	((??RRAA$[[3#||1r66yA B  	S 	
 )	 	 	s   A-B)additionalProperties)inclusionLabels)labelSelector)rt   )r   descriptionpriorityextensionPoliciesinstanceSelectorsrs   )rh   r`   r{   rb   rp   r   r   Namer   r   r   r   'GlobalVmExtensionPolicyInstanceSelectorr   r   'GlobalVmExtensionPolicyRolloutOperationr   )resource_refrv   r   r   r   inclusion_labels    ``   r   BuildGlobalVmExtensionPolicyr   |  s$   
 d6K6KL$,,7		)	)""}} 88OO:< P  "&!6!6 "7o 
:
:$II"*"O"O"d"d+D), #e # J  ;  "7  GG1$A H ' 
* 
 s   6AD)N)NN)!__doc__r"   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.core.utilr   r   r$   r(   r2   r9   r<   r?   rF   rJ   rL   rO   rV   rY   rX   rh   rl   rp   ry   r   r   r   rU   r   r   <module>r      s    C  / . E < *B2
.,&*&
	%> B&""5r   