#NEWLINE# def get_docker_client( ) : #NEWLINE# #INDENT# '\n    Try to fire up boot2docker and set any environmental variables\n    ' #NEWLINE# try : #NEWLINE# #INDENT# process = [ 'boot2docker' , 'info' ] #NEWLINE# p = subprocess . Popen ( process , stdout = PIPE ) #NEWLINE# boot2docker_info = json . loads ( p . communicate ( ) [ 0 ] ) #NEWLINE# docker_host = '' #NEWLINE# docker_cert_path = '' #NEWLINE# docker_tls_verify = '' #NEWLINE# if ( boot2docker_info [ 'State' ] != 'running' ) : #NEWLINE# #INDENT# print ( 'Starting Boot2Docker VM:' ) #NEWLINE# process = [ 'boot2docker' , 'start' ] #NEWLINE# subprocess . call ( process ) #NEWLINE# #UNINDENT# if ( ( 'DOCKER_HOST' not in os . environ ) or ( 'DOCKER_CERT_PATH' not in os . environ ) or ( 'DOCKER_TLS_VERIFY' not in os . environ ) ) : #NEWLINE# #INDENT# process = [ 'boot2docker' , 'shellinit' ] #NEWLINE# p = subprocess . Popen ( process , stdout = PIPE ) #NEWLINE# boot2docker_envs = p . communicate ( ) [ 0 ] . split ( ) #NEWLINE# for env in boot2docker_envs : #NEWLINE# #INDENT# if ( 'DOCKER_HOST' in env ) : #NEWLINE# #INDENT# docker_host = env . split ( '=' ) [ 1 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'DOCKER_CERT_PATH' in env ) : #NEWLINE# #INDENT# docker_cert_path = env . split ( '=' ) [ 1 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'DOCKER_TLS_VERIFY' in env ) : #NEWLINE# #INDENT# docker_tls_verify = env . split ( '=' ) [ 1 ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# os . environ [ 'DOCKER_TLS_VERIFY' ] = docker_tls_verify #NEWLINE# os . environ [ 'DOCKER_HOST' ] = docker_host #NEWLINE# os . environ [ 'DOCKER_CERT_PATH' ] = docker_cert_path #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# docker_host = os . environ [ 'DOCKER_HOST' ] . split ( '=' ) [ 1 ] #NEWLINE# #UNINDENT# client_kwargs = kwargs_from_env ( assert_hostname = False ) #NEWLINE# client_kwargs [ 'version' ] = MINIMUM_API_VERSION #NEWLINE# version_client = DockerClient ( ** client_kwargs ) #NEWLINE# client_kwargs [ 'version' ] = get_api_version ( MAX_CLIENT_DOCKER_API_VERSION , version_client . version ( ) [ 'ApiVersion' ] ) #NEWLINE# docker_client = DockerClient ( ** client_kwargs ) #NEWLINE# docker_client . host = docker_host . split ( ':' ) [ 1 ] . strip ( '//' ) #NEWLINE# return docker_client #NEWLINE# #UNINDENT# except OSError : #NEWLINE# #INDENT# version_client = DockerClient ( base_url = 'unix://var/run/docker.sock' , version = MINIMUM_API_VERSION ) #NEWLINE# version = get_api_version ( MAX_CLIENT_DOCKER_API_VERSION , version_client . version ( ) [ 'ApiVersion' ] ) #NEWLINE# docker_client = DockerClient ( base_url = 'unix://var/run/docker.sock' , version = version ) #NEWLINE# docker_client . host = DEFAULT_DOCKER_HOST #NEWLINE# return docker_client #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# raise