
    (                         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S jrS rS rS rg)z:Flags for the compute zone 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    Jlib/googlecloudsdk/command_lib/compute/zone_vm_extension_policies/flags.pyAddPolicyDescriptionr      s    K      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.)requiredactiondefaultmetavartyper	   N)r   r   StoreOnceActionArgListr   s    r   AddExtensionsr   "   s;    ((!,>  r   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>.ValidatePriority2   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.
      )r   r   r	   N)r#   r   	functoolspartial)r   r+   s     r   AddPolicyPriorityr/   /   sA    s  	-q%H
	  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   ArgDictr   r   s    r   AddExtensionVersionr6   P   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   r2   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.
      r3   Nr4   r   s    r   AddExtensionConfigsr9   g   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.
      r3   Nr4   r   s    r   AddExtensionConfigsFromFiler<   }   s=    !,((
  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 zone will be selected.
      )r   r   r	   Nr
   r   s    r   AddPolicyInclusionLabelsr?      s#    
	  r   c                 &    U R                  SSSS9  g)zAdds the zone flag.z--zoneTz;
      The zone to list the extension policies from.
      )r   r	   Nr
   r   s    r   AddZoneFlagrA      s     
  r   c                  N    [         R                  " SSSS[         R                  S9$ )Nzzone vm extension policyzcompute.zoneVmExtensionPoliciesTF)resource_namezonal_collectionr   pluralzone_explanation)r%   ResourceArgumentZONE_PROPERTY_EXPLANATION r   r   MakeZoneVmExtensionPolicyArgrJ      s*    		'	'.8$>>
 r   c                     [        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?   r   r6   r9   r<   r   s    r   AddExtensionPolicyArgsrL      s:    vF6"fff%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.r8   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   ParseExtensionConfigsrZ      s   z?./,=++
() *%%/L2 
 &)*:*?*?*A&B#6G++
() *22<? 
 !GLLN+c2B2G2G2I.JJ++
+)* +! !   "Wr   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.Nr1   rN   z< from --version are not specified in the --extensions flag. rO   )rR   versionsrU   versions_extensions_setrW   s        r   ParseExtensionVersionsr^      sa    	
z?.0,=

)
)
&' (##-,	0  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.rT   NzCould not read config file [z] for extension [z]: )
configupdategetattrrT   itemsr   ReadFileContentsErrorr   BadFileException)argsrS   	extension	file_pathes        r   _GetConfigsrk      s    '	[[NN4;;T%t,, $ 5 5 ; ; =	
"33I> !> 
. [[ 
))*9+ 63qc#
 	

s   !A??B7B22B7c                 p  ^^ U4S jnUU4S jn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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splitrc   VmExtensionPolicyLabelSelectorInclusionLabelsValueAdditionalProperty)inclusion_labelsrp   r*   messagess      r   BuildInclusionLabelsValue=BuildZoneVmExtensionPolicy.<locals>.BuildInclusionLabelsValue  s~     ../?/E/Ec/JK 
%'	
JC	 	//DDWW 	X 	
	 	 	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pinnedVersionro   )rk   rR   VmExtensionPolicyExtensionPoliciesValueru    VmExtensionPolicyExtensionPolicygetversion)rS   rh   rg   rw   s     r   BuildExtensionPoliciesValue?BuildZoneVmExtensionPolicy.<locals>.BuildExtensionPoliciesValue  s    $G 	 )I 	""99LL;;$[[3#||1r66yA <  	M 	
 )	 	 	s   A-B)additionalProperties)inclusionLabels)labelSelector)namedescriptionpriorityextensionPoliciesinstanceSelectors)	r}   Namer   r   r~   rv   !VmExtensionPolicyInstanceSelectorrs   rt   )resource_refrg   rw   rx   r   inclusion_labels    ``   r   BuildZoneVmExtensionPolicyr     s    
 
	#	#""}} 22II:< J  "&!6!6 "7o 
4
4$CC"*"I"I"^"^+D), #_ # D  5  "7 
$ 
 s   +AB3)N)__doc__r-   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer   r%   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.core.utilr   r   r   r/   r6   r9   r<   r?   rA   rJ   rL   rZ   r^   rk   r   rI   r   r   <module>r      sd    A  / . E < *
B.,&2&>"/r   