
    "                         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rS rS rS rSS jrS rS rS rS rS rS rg
)z:Flags and helpers for the compute node templates commands.    )absolute_import)division)unicode_literals)arg_parsers)flags)	arg_utils)labels_util)scaled_integerNc                  J    [         R                  " SS[         R                  S9$ )Nznode templateszcompute.nodeTemplates)resource_nameregional_collectionregion_explanation)compute_flagsResourceArgumentREGION_PROPERTY_EXPLANATION     Klib/googlecloudsdk/command_lib/compute/sole_tenancy/node_templates/flags.pyMakeNodeTemplateArgr      s&    		'	'$1&BB
D Dr   c                 D   ^ ^ [         R                  " T 5      mUU 4S jnU$ )zFParses the value 'any' or a binary size converted to the default unit.c                    > U R                  5       n U S:X  a  U $ [        R                  " TS9" U 5      nUT-  n[        R                  " U5      $ )Nany)default_unit)lowerr   
BinarySizesix	text_type)valuesizeconverted_sizebytes_per_unitr   s      r   _Parse _BinarySizeOrAny.<locals>._Parse(   sH    KKME~l!!|<UCD^+N==((r   r
   GetBinaryUnitSize)r   r"   r!   s   ` @r   _BinarySizeOrAnyr&   $   s!     "33LA.) 
-r   c                      S n U $ )Nc                 t    U R                  5       n U S:X  a  U $ [        U 5      n [        R                  " U 5      $ )Nr   )r   intr   r   )r   s    r   r"   _IntOrAny.<locals>._Parse3   s1    KKME~lJE==r   r   )r"   s    r   	_IntOrAnyr+   2   s      
-r   c                 L   ^ ^^^ [         R                  " T 5      mUU UU4S jnU$ )z@Parses the value as a binary size converted to the default unit.c                 j   > U R                  5       n [        R                  " TTTS9" U 5      nUT-  nU$ )N)lower_boundupper_boundr   )r   r   r   )r   r   r    r!   r   r.   r/   s      r   r"   _BinarySize.<locals>._ParseA   s@    KKME!![!##(*D ^+Nr   r$   )r   r.   r/   r"   r!   s   ``` @r   _BinarySizer1   =   s&     "33LA.  
-r   c                    ^  U 4S jnU$ )Nc                    > [         R                  " U R                  5       5      n U T;  a4  [        R                  " SR                  SR                  T5      5      5      eU $ )Nz[type] must be one of [{0}],)r   r   r   r   ArgumentTypeErrorformatjoin)r   valid_choicess    r   r"   _Choice.<locals>._ParseL   sS    MM%++-(EM!))
'
.
.hh}%'( ( Lr   r   )r8   r"   s   ` r   _Choicer:   K   s     
-r   c           
         U R                  SSS9  U R                  SS[        R                  " [        R                  [        R
                  S9[        R                  SS9  U R                  S	S	S
9nUR                  SSS9  UR                  S[        R                  " [        5       [        S5      [        S5      S.S9SS9  g)z>Add flags for creating a node template to the argument parser.z--descriptionz)An optional description of this resource.)helpz--node-affinity-labelsz	KEY=VALUE)key_type
value_typezLabels to use for node affinity, which will be used in instance scheduling. This corresponds to the `--node-affinity` flag on `compute instances create` and `compute instance-templates create`.)metavartypeactionr<   T)mutexrequiredz--node-typea'            The node type to use for nodes in node groups using this template.
          The type of a node determines what resources are available to
          instances running on the node.

          See the following for more information:

              $ {grandparent_command} node-types listz--node-requirementsMBGB)vCPUmemorylocalSSDspeca7  The requirements for nodes. Google Compute Engine will automatically
choose a node type that fits the requirements on Node Group creation.
If multiple node types match your defined criteria, the NodeType with
the least amount of each resource will be selected. You can specify 'any'
to indicate any non-zero value for a certain resource.

The following keys are allowed:

*vCPU*:::: The number of committed cores available to the node.

*memory*:::: The amount of memory available to the node. This value
should include unit (eg. 3072MB or 9GB). If no units are specified,
*MB is assumed*.

*localSSD*:::: Optional. The amount of SSD space available on the
node. This value should include unit (eg. 3072MB or 9GB). If no
units are specified, *GB is assumed*. If this key is not specified, local SSD is
unconstrained.
      r@   r<   N)
add_argumentr   ArgDictr	   KEY_FORMAT_VALIDATORVALUE_FORMAT_VALIDATORUpdateAction	add_groupr+   r&   )parsernode_type_groups     r   AddCreateArgsToParserrT   V   s    6  8 	33 779 %%  
 $$4$$?/9  	: k(.*40
  r   c                 `    U R                  S[        R                  " [        [        S.S9SS9  g)zAdds Accelerator-related args.z--accelerator)r@   countrI   a        Attaches accelerators (e.g. GPUs) to the node template.

      *type*::: The specific type (e.g. nvidia-tesla-k80 for nVidia Tesla K80)
      of accelerator to attach to the node template. Use 'gcloud compute
      accelerator-types list' to learn about all available accelerator types.

      *count*::: Number of accelerators to attach to each
      node template. The default value is 1.
      rK   N)rL   r   rM   strr)   rR   s    r   AddAcceleratorArgsrY      s6    % 		
  r   c                     U R                  S[        R                  " [        S/5      [	        SSSS9[
        S.SS/S	9S
S9  g)z)Add flag for specifying disk information.z--diskz	local-ssdrE   375GB)r.   r/   )r@   r   rV   r@   rV   )rJ   required_keysa  Option to specify disk properties. It is mutually exclusive with
'--node-requirements=[localSSD=LOCALSSD]' but
'--node-requirements=[memory=MEMORY],[vCPU=VCPU],any' are still available.

*type*::: Specifies the desired disk type on the node. This disk type must be a
local storage type. This should be the name of the disk type. Currently
only `local-ssd` is allowed.

*size*::: The size of the disk in GiB. Currently you can specify only 375 GiB
or no value at all.

*count*::: Specifies the number of such disks. Set to `16` or `24`.

rK   N)rL   r   rM   r:   r1   r)   rX   s    r   AddDiskArgToParserr]      sZ    {m,!GB	 
  r   c                 `    [         R                  " SU R                  R                  SSS.SSS9$ )z:Helper to get a choice flag from server binding type enum.z--server-binding)restart-node-on-any-serverz\Nodes using this template will restart on any physical server following a maintenance event.)zrestart-node-on-minimal-serversa  Nodes using this template will restart on the same physical server following a
maintenance event, instead of being live migrated to or restarted on a new
physical server. This means that VMs on such nodes will experience outages while
maintenance is applied. This option may be useful if you are using software
licenses tied to the underlying server characteristics such as physical sockets
or cores, to avoid the need for additional licenses when maintenance occurs.

Note that in some cases, Google Compute Engine may need to move your VMs to a
new underlying server. During these situations your VMs will be restarted on a
new physical server and assigned a new sole tenant physical server ID.)RESTART_NODE_ON_ANY_SERVERRESTART_NODE_ON_MINIMAL_SERVERSzThe server binding policy for nodes using this template, which determines where the nodes should restart following a maintenance event.r_   )custom_mappingshelp_strdefault)r   ChoiceEnumMapperServerBindingTypeValueValuesEnum)messagess    r   GetServerBindingMapperFlagri      sB    		#	#00)2.KL$ +1
, ,r   c                 *    U R                  SSS/SS9  g )Nz--cpu-overcommit-typeenablednonea  CPU overcommit type for nodes created based on this template. To overcommit CPUs on a VM, set --cpu-overcommit-type equal to either standard or none, and then when creating a VM, specify a value for the --min-node-cpu flag. Lower values for --min-node-cpu specify a higher overcommit ratio, that is, proportionally more vCPUs in relation to physical CPUs. You can only overcommit CPUs on VMs that are scheduled on nodes that support it.)choicesr<   )rL   rX   s    r   AddCpuOvercommitTypeFlagrn      s%    &!  r   )NN)__doc__
__future__r   r   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   r   $googlecloudsdk.command_lib.util.apisr   $googlecloudsdk.command_lib.util.argsr	   googlecloudsdk.core.utilr
   r   r   r&   r+   r1   r:   rT   rY   r]   ri   rn   r   r   r   <module>rv      s[    A &  ' / E : < 3 
D6r(@,:r   