
    *                         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	 rS
 rS r   SS jrS rS rS rg)zHCommands for interacting with Immersive Stream for XR service instances.    )absolute_import)division)unicode_literals)api_util)
exceptions)log)
propertiesc                 $    SR                  X5      $ )Nzprojects/{}/locations/{})format)projectlocations     ;lib/googlecloudsdk/api_lib/immersive_stream/xr/instances.pyProjectLocationr      s    	#	*	*7	==    c                   ^ Ub?  UR                   R                  nU Vs0 s H  nUR                  UR                  _M     snmO0 mU(       a=  [	        U4S jU 5       5      (       a   [
        R                  R                  S5        gUnOU(       aD  [	        U4S jU 5       5      (       a   [
        R                  R                  S5        gS U 5       nOCU(       a<  [	        U4S jU 5       5      (       a   [
        R                  R                  S5        gUn[        R                  " U 5      nUR                  R                  5       n	W H  n
U
S	   n[        U
S
   5      nU
R                  SS5      nUR                  UUUS9nU(       a&  [        U
S   5      Ul        [        U
S   5      Ul        U	R                  R#                  UR                  R                  R%                  XS95        M     U	R                   H[  nU(       a8  UR                  R&                  S:X  a  TR)                  UR                  S5        MB  UR                  TUR                  '   M]     UR                  R                  5       n[+        TR-                  5       5       HA  u  pUR                  R#                  UR                  R                  R%                  XS95        MC     U$ s  snf )a  Generates the target location configs.

Args:
  release_track: ALPHA or GA release track
  add_region_configs: List of region config dicts of the form: [{'region':
    region1, 'capacity': capacity1, 'enable_autoscaling': enable_autoscaling1,
    'autoscaling_buffer': autoscaling_buffer1, 'autoscaling_min_capacity':
    autoscaling_min_capacity1}] that specifies the regions to add to the
    service instance
  update_region_configs: List of region config dicts of the form: [{'region':
    region1, 'capacity': capacity1}] that specifies the regions to update to
    the service instance
  remove_regions: List of regions to remove
  current_instance: instance object - current state of the service instance
    before update

Returns:
  A LocationConfigsValue, with entries sorted by location
Nc              3   4   >#    U  H  nUS    T;   v   M     g7fregionN .0region_configlocation_configss     r   	<genexpr>0GenerateTargetLocationConfigs.<locals>.<genexpr>D   s#      /M 	h#33/   zOnly new regions can be added.c              3   ,   >#    U  H	  oT;  v   M     g 7f)Nr   )r   r   r   s     r   r   r   M   s     
Gf))s   z%Only existing regions can be removed.c              3   .   #    U  H  nUS SS.v   M     g7f)r   F)r   capacityenable_autoscalingNr   )r   r   s     r   r   r   R   s      $F qF$s   c              3   4   >#    U  H  nUS    T;  v   M     g7fr   r   r   s     r   r   r   X   s#      2M 	h'772r   z%Only existing regions can be updated.r   r   r    F)r   r   enableAutoscalingautoscaling_bufferautoscaling_min_capacity)keyvaluer   )locationConfigsadditionalPropertiesr%   r&   anyr   statusPrintr   GetMessagesStreamInstanceLocationConfigsValueintgetLocationConfigautoscalingBufferautoscalingMinCapacityappendAdditionalPropertyr   popsorteditems)release_trackadd_region_configsupdate_region_configsremove_regionscurrent_instanceadditonal_propertieslocation_configregion_configs_diffmessageslocation_configs_diffr   r   r   r    target_location_configsr%   r   s                   @r   GenerateTargetLocationConfigsrD      s   6 !+;;PP  43O 	_2223
 
 /   
jj78,

G
GGG	jj>?$
 
 2   
jj>? 0!!-0("11FFH*m8$F=,-H&**+?G--, . O
 *-
,
-+o' 03
2
30o, ..5544GG 	H 	
# +0 /CCo///88A=?..5 />.C.C**+ D %33HHJ %%5%;%;%=>c007744GG 	H 	
 ? 
! gs   !Kc                     [         R                  " U 5      n[         R                  " U 5      nUR                  U5      nUR	                  UR                  US95      $ )zGet resource details of an Immersive Stream for XR service instance.

Args:
  release_track: ALPHA or GA release track
  instance_relative_name: string - canonical resource name of the instance

Returns:
  A service instance resource object.
)name)r   	GetClientr,   'ProjectsLocationsStreamInstancesServiceGet0StreamProjectsLocationsStreamInstancesGetRequest)r9   instance_relative_nameclientrA   services        r   rI   rI      s\     m,&!!-0(::6B'	??% @ 
 r   Nc	           	         [         R                  " U 5      n	[         R                  " U 5      n
U
R                  US9nU
R	                  UUUUUUS9nU(       a  U
R                  US9nXl        U	R                  U	5      nUR                  U
R                  [        [        R                  R                  R                  R                  5       U5      UUS95      $ )aL  Create a new Immersive Stream for XR service instance.

Args:
  release_track: ALPHA or GA release track
  instance_name: string - name of the service instance
  content: string - resource path of the content resource that is served by
    the instance
  location: string - location where the resource will be created
  version: string - content build version tag
  target_location_configs: A LocationConfigsValue proto message represents the
    target location configs to achieve
  fallback_url: string - A url to redirect users to when the instance is
    unable to provide the streaming experience
  mode: string - The rendering mode supported by the service instance
  gpu_class: string - The class of GPU used by this instance

Returns:
  An Operation object which can be used to check on the progress of the
  service instance creation.
contentVersionTag)contentcontentBuildVersionrF   r'   modegpuClassfallbackUri)parentstreamInstancestreamInstanceId)r   rG   r,   BuildVersionr-   StreamConfigstreamConfigrH   Create3StreamProjectsLocationsStreamInstancesCreateRequestr   r	   VALUEScorer   rI   )r9   instance_namerQ   r   versionrC   fallback_urlrS   	gpu_classrL   rA   build_versioninstancestream_configrM   s                  r   r]   r]      s    > m,&!!-0(''''B-$$'- % ( ))l)CM)::6B'	BB $$,,002H "( C 
 r   c                 R   U(       a  UR                   (       d  [        R                  " S5      e[        R                  " U 5      n[        R
                  " U 5      nUR                  US9nUR                  U5      nUR                  UR                  UR                  5       USS95      $ )a  Updates the location configs for a service instance.

Args:
  release_track: ALPHA or GA release track
  instance_ref: resource object - service instance to be updated
  target_location_configs: A LocationConfigsValue proto message represents the
    target location configs to achieve

Returns:
  An Operation object which can be used to check on the progress of the
  service instance update.
z(Target location configs must be provided)r'   r   rF   rX   
updateMask)r(   r   Errorr   rG   r,   r-   rH   Patch2StreamProjectsLocationsStreamInstancesPatchRequestRelativeName)r9   instance_refrC   rL   rA   rf   rM   s          r   UpdateLocationConfigsrp      s     "$99


E
FFm,&!!-0($$5L$M(::6B'	AA((*!' B 
 r   c                    [         R                  " U 5      n[         R                  " U 5      nUR                  US9nUR	                  US9nUR                  U5      nUR                  UR                  UR                  5       USS95      $ )aR  Update content build version of an Immersive Stream for XR service instance.

Args:
  release_track: ALPHA or GA release track
  instance_ref: resource object - service instance to be updated
  version: content build version tag

Returns:
  An Operation object which can be used to check on the progress of the
  service instance update.
rO   )rR   content_build_versionri   )	r   rG   r,   rZ   r-   rH   rl   rm   rn   )r9   ro   rb   rL   rA   re   rf   rM   s           r   UpdateContentBuildVersionrs     s     m,&!!-0(''''B-$$$G(::6B'	AA((*!, B 
 r   c                 "   [         R                  " U 5      n[         R                  " U 5      nUR                  U5      nUR	                  US9nUR                  5       nXgl        UR                  UR                  UR                  5       USS95      $ )a  Update fallback url of an Immersive Stream for XR service instance.

Args:
  release_track: ALPHA or GA release track
  instance_ref: resource object - service instance to be updated
  fallback_url: string - fallback url to redirect users to when the instance
    is not available

Returns:
  An Operation object which can be used to check on the progress of the
  service instance update.
rU   rg   ri   )
r   rG   r,   rH   r[   r-   r\   rl   rm   rn   )r9   ro   rc   rL   rA   rM   rg   rf   s           r   UpdateFallbackUrlru     s     m,&!!-0(::6B'''L'A-$$&('	AA((*!$ B 
 r   )NNN)__doc__
__future__r   r   r   *googlecloudsdk.api_lib.immersive_stream.xrr   googlecloudsdk.corer   r   r	   r   rD   rI   r]   rp   rs   ru   r   r   r   <module>rz      sR    O &  ' ? * # *>p!f8 	8vD6r   