
    ;                         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
rS	rS
rS rSS jrS rS rS rS rg)z7Flags and helpers for Immersive Stream for XR commands.    )absolute_import)division)unicode_literals)arg_parsers)
exceptions)logNa    Flag used to specify region and capacity required for the service instance's availability.

  'region' is the region in which the instance is deployed.

  'capacity' is the maxium number of concurrent streaming sessions that the instance can support in the given region.
z    Flag used to specify the fallback url to redirect users to when this service instance is unable to provide the streaming experience.
c                     U $ )zDRegionValidator is a no-op. The validation is handled in CLH server. )regions    ;lib/googlecloudsdk/command_lib/immersive_stream/xr/flags.pyRegionValidatorr   '   s    	-    c                 (   [         R                  " SS5      nU(       a  SOSnUR                  U [        U-   [         R                  " [
        U[         R                  " 5       [         R                  " SS9[         R                  " SS9S.SS	/S
9USS9  g )Nz[0-9]+zcapacity must be a numberz
This is a repeatable flag.    )lower_bound)r   capacityenable_autoscalingautoscaling_bufferautoscaling_min_capacityr   r   )specrequired_keysappend)helptyperequiredaction)r   RegexpValidatoradd_argument_REGION_CONFIG_ARG_HELP_TEXTArgDictr   
ArgBoolean
BoundedInt)nameparser
repeatabler   capacity_validatorrepeatable_helps         r   AddRegionConfigArgr)   ,   s    "22, 7A2b/
'/9',$/$:$:$<$/$:$:q$I*5*@*@Q*O ":.	   r   c                 
   [         R                  R                  R                  R	                  U 5      nUR
                  (       d  [        R                  " S5        gUR                  (       d  [        R                  " S5        gg)zRudimentary url validator.

Args:
  url: String

Returns:
  Whether the input string contains both a scheme and a network location. Note
  that this is a very rudimentary validator and does not work on all cases.
  Invalid urls may still pass this check.
z+Invalid URL - The URL must contain a schemeFz5Invalid URL - The URL must contain a network locationT)	sixmovesurllibparseurlsplitschemer   errornetloc)url
parsed_urls     r   ValidateUrlr5   C   sY     yy%%..s3*			II;<			IIEF	r   c                 j    U R                  5       n U S:X  d  U S:X  a  g[        R                  " SS5      e)zValidates the mode input.

Args:
  mode: String indicating the rendering mode of the instance. Allowed values
    are 3d and ar.

Returns:
  True if the mode is supported by ISXR, False otherwise.
3darTz--modezmode must be 3d or arlowerr   InvalidArgumentException)modes    r   ValidateModer=   X   s3     
$	T\TT\++H6MNNr   c                     U R                  5       n U S:X  a  gU S:X  a3  U(       a  UR                  5       S:w  a  [        R                  " SS5      eg[        R                  " SS5      e)a$  Validates the gpu_class input.

Args:
  gpu_class: String indicating the GPU class of the instance. Allowed values
    are l4 and t4.
  mode: String indicating the rendering mode of the instance.

Returns:
  True if the GPU class and mode combination is supported by ISXR, False
  otherwise.
t4Tl4r7   z--gpu-classz l4 gpu-class must have --mode=3dzgpu-class must be l4 or t4r9   )	gpu_classr<   s     r   ValidateGpuClassrB   h   sj     oo)$$4::<4'//
;  ++1	 r   c                    0 nU  HG  nX2US   '   UR                  SS5      (       d  M#  SU;   a  SU;   a  M1  [        R                  " S5          g   [        U5      [        U 5      :  a&  [        R                  " SR	                  U5      5        gg)	ax  Validates the region config args do not contain duplicate regions and have valid autoscaling configuration, if enabled.

Args:
  region_configs: Either add_region or update_region ArgList from the
    instance update args
  operation_name: String indicating if operation is an add or update region
    operation

Returns:
  True if the region_configs are valid. False if not.
r   r   Fr   r   z^Must set autoscaling_buffer and autoscaling_min_capacity if enable_autoscaling is set to true.z+Duplicate regions in --{}-region arguments.T)getr   r1   lenformat)region_configsoperation_nameregionsregion_configs       r   ValidateRegionConfigArgsrK      s     '%m'4M(#$-u55-&-7	ii0  & 	\C''II5<<^L 	r   )TT)__doc__
__future__r   r   r   googlecloudsdk.callioper   r   googlecloudsdk.corer   six.moves.urllib.parser+   r    _FALLBACK_URL_HELP_TEXTr   r)   r5   r=   rB   rK   r
   r   r   <module>rR      sN    > &  ' / . #    

.*O 4 r   