本文整理汇总了Python中docker.utils.kwargs_from_env方法的典型用法代码示例。如果您正苦于以下问题:Python utils.kwargs_from_env方法的具体用法?Python utils.kwargs_from_env怎么用?Python utils.kwargs_from_env使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docker.utils
的用法示例。
在下文中一共展示了utils.kwargs_from_env方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dirty_fails_without_flag
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def test_dirty_fails_without_flag(tmpdir):
tmp = tmpdir.join('shipwright-sample')
path = str(tmp)
source = pkg_resources.resource_filename(
__name__,
'examples/shipwright-sample',
)
create_repo(path, source)
tmp.join('service1/base.txt').write('Some text')
client_cfg = docker_utils.kwargs_from_env()
args = get_defaults()
result = shipw_cli.run(
path=path,
client_cfg=client_cfg,
arguments=args,
environ={},
)
assert '--dirty' in result
assert 'Abort' in result
示例2: client
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def client(self):
"""single global client instance"""
cls = self.__class__
if cls._client is None:
kwargs = {"version": "auto"}
if self.tls_config:
kwargs["tls"] = docker.tls.TLSConfig(**self.tls_config)
kwargs.update(kwargs_from_env())
kwargs.update(self.client_kwargs)
client = docker.APIClient(**kwargs)
cls._client = client
return cls._client
# notice when user has set the command
# default command is that of the container,
# but user can override it via config
示例3: init_docker_client
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def init_docker_client(timeout=2):
"""
Init docker-py client.
"""
if sys.platform.startswith('darwin') \
or sys.platform.startswith('win32'):
# mac or win
kwargs = kwargs_from_env()
if 'tls' in kwargs:
kwargs['tls'].assert_hostname = False
kwargs['timeout'] = timeout
client = DockerAPIClient(**kwargs)
else:
# unix-based
client = DockerAPIClient(
timeout=timeout,
base_url='unix://var/run/docker.sock')
return client
示例4: docker_client
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def docker_client():
client_cfg = docker_utils.kwargs_from_env()
return docker.Client(version='1.21', **client_cfg)
示例5: docker_client
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def docker_client(args):
"""
Attempts to create a docker client.
- args: The arguments parsed on the command line.
- returns: a docker-py client
"""
if _platform == 'linux' or _platform == 'linux2':
# linux
if "docker_url" in args:
return Client(
base_url=args.docker_url,
timeout=args.timeout,
version='auto')
else:
# TODO: test to see if this does the right thing by default.
return Client(
version='auto',
timeout=args.timeout,
**kwargs_from_env())
elif _platform == 'darwin':
# OS X.
kwargs = kwargs_from_env()
if not args.strict_docker_tls and 'tls' in kwargs:
kwargs['tls'].assert_hostname = False
try:
return Client(version='auto', timeout=args.timeout, **kwargs)
except:
logging.error(
'Could not connect to the docker daemon. ' +
'Please make sure docker is running.'
)
sys.exit(2)
elif _platform == 'win32' or _platform == 'cygwin':
# Windows.
logging.fatal("Sorry, windows is not currently supported!")
sys.exit(2)
示例6: client
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def client(self):
"""single global client instance"""
cls = self.__class__
if cls._client is None:
kwargs = {}
if self.tls_config:
kwargs['tls'] = docker.tls.TLSConfig(**self.tls_config)
kwargs.update(kwargs_from_env())
client = docker.APIClient(version='auto', **kwargs)
cls._client = client
return cls._client
示例7: get_api_client
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def get_api_client():
"""Return the API client or initialize it."""
if 'api_client' not in __st__:
from docker import APIClient, utils
params = utils.kwargs_from_env()
base_url = None if 'base_url' not in params else params['base_url']
tls = None if 'tls' not in params else params['tls']
__st__['api_client'] = APIClient(base_url=base_url, tls=tls)
return __st__['api_client']
示例8: docker_client
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def docker_client(environment, version=None, tls_config=None, host=None,
tls_version=None):
"""
Returns a docker-py client configured using environment variables
according to the same logic as the official Docker client.
"""
try:
kwargs = kwargs_from_env(environment=environment, ssl_version=tls_version)
except TLSParameterError:
raise UserError(
"TLS configuration is invalid - make sure your DOCKER_TLS_VERIFY "
"and DOCKER_CERT_PATH are set correctly.\n"
"You might need to run `eval \"$(docker-machine env default)\"`")
if host:
kwargs['base_url'] = host
if tls_config:
kwargs['tls'] = tls_config
if version:
kwargs['version'] = version
timeout = environment.get('COMPOSE_HTTP_TIMEOUT')
if timeout:
kwargs['timeout'] = int(timeout)
else:
kwargs['timeout'] = HTTP_TIMEOUT
kwargs['user_agent'] = generate_user_agent()
# Workaround for
# https://pyinstaller.readthedocs.io/en/v3.3.1/runtime-information.html#ld-library-path-libpath-considerations
if 'LD_LIBRARY_PATH_ORIG' in environment:
kwargs['credstore_env'] = {
'LD_LIBRARY_PATH': environment.get('LD_LIBRARY_PATH_ORIG'),
}
client = APIClient(**kwargs)
client._original_base_url = kwargs.get('base_url')
return client
示例9: test_sample
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def test_sample(tmpdir, capsys):
path = str(tmpdir.join('shipwright-sample'))
source = pkg_resources.resource_filename(
__name__,
'examples/shipwright-sample',
)
repo = create_repo(path, source)
tag = repo.head.ref.commit.hexsha[:12]
client_cfg = docker_utils.kwargs_from_env()
args = get_defaults()
args['images'] = True
shipw_cli.run(
path=path,
client_cfg=client_cfg,
arguments=args,
environ={},
)
out, err = capsys.readouterr()
images = {'base', 'shared', 'service1'}
tmpl = 'shipwright/{img}:{tag}'
expected = {tmpl.format(img=i, tag=tag) for i in images}
assert {l for l in out.split('\n') if l} == expected
示例10: test_dump_file
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def test_dump_file(tmpdir, docker_client):
dump_file = tmpdir.join('dump.txt')
tmp = tmpdir.join('shipwright-sample')
path = str(tmp)
source = pkg_resources.resource_filename(
__name__,
'examples/shipwright-sample',
)
create_repo(path, source)
client_cfg = docker_utils.kwargs_from_env()
cli = docker_client
try:
args = get_defaults()
args['--dump-file'] = str(dump_file)
shipw_cli.run(
path=path,
client_cfg=client_cfg,
arguments=args,
environ={},
)
assert ' : FROM busybox' in dump_file.read()
finally:
old_images = (
cli.images(name='shipwright/service1', quiet=True) +
cli.images(name='shipwright/shared', quiet=True) +
cli.images(name='shipwright/base', quiet=True)
)
for image in old_images:
cli.remove_image(image, force=True)
示例11: test_exclude
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def test_exclude(tmpdir, docker_client):
path = str(tmpdir.join('shipwright-sample'))
source = pkg_resources.resource_filename(
__name__,
'examples/shipwright-sample',
)
create_repo(path, source)
client_cfg = docker_utils.kwargs_from_env()
cli = docker_client
args = get_defaults()
args['--exclude'] = [
'shipwright/service1',
'shipwright/shared',
]
try:
shipw_cli.run(
path=path,
client_cfg=client_cfg,
arguments=args,
environ={},
)
base, = (
cli.images(name='shipwright/service1') +
cli.images(name='shipwright/shared') +
cli.images(name='shipwright/base')
)
assert 'shipwright/base:master' in base['RepoTags']
assert 'shipwright/base:latest' in base['RepoTags']
finally:
old_images = (
cli.images(name='shipwright/base', quiet=True)
)
for image in old_images:
cli.remove_image(image, force=True)
示例12: docker_client
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def docker_client():
client_cfg = docker_utils.kwargs_from_env()
return docker.APIClient(version='1.21', **client_cfg)
示例13: get_docker_client
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def get_docker_client() -> Client:
client_opts = kwargs_from_env(assert_hostname=False)
if "base_url" in client_opts:
return Client(**client_opts)
else:
return Client(base_url=get_docker_host(), **client_opts)
示例14: setup_machine_client
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def setup_machine_client(self, verbose):
try:
# try secure connection first
kw = kwargs_from_env(assert_hostname=False)
return docker_py.Client(version='auto', **kw)
except docker_py.errors.DockerException as e:
# shit - some weird boot2docker, python, docker-py, requests, and ssl error
# https://github.com/docker/docker-py/issues/465
if verbose:
log.debug(e)
log.warn("Cannot connect securely to Docker, trying insecurely")
kw = kwargs_from_env(assert_hostname=False)
if 'tls' in kw:
kw['tls'].verify = False
return docker_py.Client(version='auto', **kw)
示例15: main
# 需要导入模块: from docker import utils [as 别名]
# 或者: from docker.utils import kwargs_from_env [as 别名]
def main():
logging.basicConfig(
level=logging.INFO,
format="%(message)s",
stream=sys.stdout)
args = get_args()
client = docker.APIClient(version='auto',
timeout=args.timeout,
**kwargs_from_env())
exclude_container_labels = format_exclude_labels(
args.exclude_container_label
)
if args.max_container_age:
cleanup_containers(
client,
args.max_container_age,
args.dry_run,
exclude_container_labels,
)
if args.max_image_age:
exclude_set = build_exclude_set(
args.exclude_image,
args.exclude_image_file)
cleanup_images(client, args.max_image_age, args.dry_run, exclude_set)
if args.dangling_volumes:
cleanup_volumes(client, args.dry_run)