
    k                         d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddl	m
Z
 ddl	mZ dd	l	mZ dd
lmZ ddlZdZdZdZdZdZdZdZdZ G d de
j0                        Zd Zd Zd Zd Zd Zd Zy)z.Utility functions for gcloud spanner emulator.    )absolute_import)division)unicode_literalsN)util)
exceptions)execution_utils)log)	platformsspannerzcloud-spanner-emulatorzGoogle Cloud Spanner Emulatorcloud_spanner_emulatorgateway_mainz-gcr.io/cloud-spanner-emulator/emulator:1.5.28i2#  i<#  c                       e Zd Zy)InvalidHostPortFormatN)__name__
__module____qualname__     8lib/googlecloudsdk/command_lib/emulators/spanner_util.pyr   r   )   s    r   r   c                  4    t        j                  t              S N)r   
GetDataDir SPANNER_EMULATOR_PROPERTY_PREFIXr   r   r   r   r   -   s    	9	::r   c                 Z   | j                   j                  }|dk(  rd}	 t        j                  |       | j                  rkt        j                  ddddj                  || j                   j                  t              ddj                  || j                  t              t        dd	d
d      S t        j                  ddddj                  || j                   j                  t              ddj                  || j                  t              t              S # t        $ r t        d|z         w xY w)z@Builds arguments for starting the spanner emulator under docker.	localhostz	127.0.0.1z]When using docker, hostname specified via --host-port must be an IPV4 or IPV6 address, found dockerrunz-pz{}:{}:{}z./gateway_main
--hostnamez0.0.0.0--enable_fault_injection)	host_porthost	ipaddress
ip_address
ValueErrorr   enable_fault_injectionr   ArgsForExecutableToolformatport"SPANNER_EMULATOR_DEFAULT_GRPC_PORT	rest_port"SPANNER_EMULATOR_DEFAULT_REST_PORTSPANNER_EMULATOR_DOCKER_IMAGE)argshost_ips     r   _BuildStartArgsForDockerr/   1   s&    NN'G=! 
  00%'4>>#6#6<	>?C'4>><	>%'7-/ / 00%'4>>#6#6<	>?C'4>><	>%' ' 
 =
	24;	<= ==s   D D*c                    t         j                  j                  t        j                         dt
        t              }| j                  j                  t        d      t        j                  |d| j                  j                  d| j                  j                  dt        j                  | j                        | j                   rd      S d      S )Nbinz>Invalid value for --host-port. Must be in the format host:portr   z--grpc_portz--http_portr    )ospathjoinr   GetCloudSDKRootSPANNER_EMULATOR_EXECUTABLE_DIR SPANNER_EMULATOR_EXECUTABLE_FILEr    r(   r   r   r&   r!   six	text_typer*   r%   )r-   spanner_executables     r   "_BuildStartArgsForNativeExecutabler<   T   s    ww||D$8$8$:E$C$DF 
^^ 
HJ J		.	.,(;(;]
nn=#--*G%)%@%@!
K K GI
K Kr   c                     t         j                  j                         t         j                  j                  us| j                  rt        |       S t        |       S r   )r
   OperatingSystemCurrentLINUX
use_dockerr/   r<   r-   s    r   _BuildStartArgsrC   a   sB    '')1J1J1P1PP	#D))-d33r   c                 z    ddj                  | j                  j                  | j                  j                        iS )zCReturns an environment variable mapping from an argparse.Namespace.SPANNER_EMULATOR_HOSTz{}:{})r'   r    r!   r(   rB   s    r   GetEnvrF   i   s3     
..,,dnn.A.A
B
 r   c                 j   t        |       }t        j                  j                  dj	                  dj                  |                   t        j                  |      5 }t        j                  t        |       t                      t        j                  |t               d d d        y # 1 sw Y   y xY w)NzExecuting: {0} )rC   r	   statusPrintr'   r5   r   ExecWriteEnvYamlrF   r   PrefixOutputSPANNER_EMULATOR_COMPONENT_ID)r-   spanner_argsspanner_processs      r   StartrQ   q   st     &,**#**388L+ABCyy/fTlJL1o'DE s   AB))B2) __doc__
__future__r   r   r   r"   r3   $googlecloudsdk.command_lib.emulatorsr   googlecloudsdk.corer   r   r	   googlecloudsdk.core.utilr
   r9   r   rN   SPANNER_EMULATOR_TITLEr7   r8   r,   r)   r+   Errorr   r   r/   r<   rC   rF   rQ   r   r   r   <module>rY      s    5 &  '  	 5 * / # . 
#,   8 8 ": #1   O %) "%) "J,, ; 'F
K4Fr   