mirror of https://github.com/docker/docker-py.git
Add version param to utils.create_host_config
Add create_host_config and create_container_config to Client for version awareness Trigger warning when create_host_config is used without version
This commit is contained in:
parent
9bb6a6fd56
commit
4bd3c48ea1
|
|
@ -248,8 +248,8 @@ class Client(clientbase.ClientBase):
|
|||
'host_config is not supported in API < 1.15'
|
||||
)
|
||||
|
||||
config = utils.create_container_config(
|
||||
self._version, image, command, hostname, user, detach, stdin_open,
|
||||
config = self.create_container_config(
|
||||
image, command, hostname, user, detach, stdin_open,
|
||||
tty, mem_limit, ports, environment, dns, volumes, volumes_from,
|
||||
network_disabled, entrypoint, cpu_shares, working_dir, domainname,
|
||||
memswap_limit, cpuset, host_config, mac_address, labels,
|
||||
|
|
@ -257,6 +257,9 @@ class Client(clientbase.ClientBase):
|
|||
)
|
||||
return self.create_container_from_config(config, name)
|
||||
|
||||
def create_container_config(self, *args, **kwargs):
|
||||
return utils.create_container_config(self._version, *args, **kwargs)
|
||||
|
||||
def create_container_from_config(self, config, name=None):
|
||||
u = self._url("/containers/create")
|
||||
params = {
|
||||
|
|
@ -265,6 +268,12 @@ class Client(clientbase.ClientBase):
|
|||
res = self._post_json(u, data=config, params=params)
|
||||
return self._result(res, True)
|
||||
|
||||
def create_host_config(self, *args, **kwargs):
|
||||
if not kwargs:
|
||||
kwargs = {}
|
||||
kwargs['version'] = self._version
|
||||
return utils.create_host_config(*args, **kwargs)
|
||||
|
||||
@check_resource
|
||||
def diff(self, container):
|
||||
return self._result(self._get(self._url("/containers/{0}/changes".
|
||||
|
|
@ -815,7 +824,7 @@ class Client(clientbase.ClientBase):
|
|||
'Please use host_config in create_container instead!',
|
||||
DeprecationWarning
|
||||
)
|
||||
start_config = utils.create_host_config(**start_config_kwargs)
|
||||
start_config = self.create_host_config(**start_config_kwargs)
|
||||
|
||||
url = self._url("/containers/{0}/start".format(container))
|
||||
res = self._post_json(url, data=start_config)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ from datetime import datetime
|
|||
import requests
|
||||
import six
|
||||
|
||||
from .. import constants
|
||||
from .. import errors
|
||||
from .. import tls
|
||||
from .types import Ulimit, LogConfig
|
||||
|
|
@ -395,10 +396,17 @@ def create_host_config(
|
|||
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
|
||||
extra_hosts=None, read_only=None, pid_mode=None, ipc_mode=None,
|
||||
security_opt=None, ulimits=None, log_config=None, mem_limit=None,
|
||||
memswap_limit=None, cgroup_parent=None
|
||||
memswap_limit=None, cgroup_parent=None, version=None
|
||||
):
|
||||
host_config = {}
|
||||
|
||||
if not version:
|
||||
warnings.warn(
|
||||
'docker.utils.create_host_config() is deprecated. Please use '
|
||||
'Client.create_host_config() instead.'
|
||||
)
|
||||
version = constants.DEFAULT_DOCKER_API_VERSION
|
||||
|
||||
if mem_limit is not None:
|
||||
if isinstance(mem_limit, six.string_types):
|
||||
mem_limit = parse_bytes(mem_limit)
|
||||
|
|
@ -433,7 +441,7 @@ def create_host_config(
|
|||
|
||||
if network_mode:
|
||||
host_config['NetworkMode'] = network_mode
|
||||
elif network_mode is None:
|
||||
elif network_mode is None and compare_version('1.19', version) > 0:
|
||||
host_config['NetworkMode'] = 'default'
|
||||
|
||||
if restart_policy:
|
||||
|
|
|
|||
Loading…
Reference in New Issue