Skip to content

Commit

Permalink
Moved mem_limit and memswap_limit to host_config for API version >= 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
shin- committed Jun 19, 2015
1 parent e5485fb commit 427e3a6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
6 changes: 3 additions & 3 deletions docker/client.py
Expand Up @@ -464,11 +464,11 @@ def copy(self, container, resource):

def create_container(self, image, command=None, hostname=None, user=None,
detach=False, stdin_open=False, tty=False,
mem_limit=0, ports=None, environment=None, dns=None,
volumes=None, volumes_from=None,
mem_limit=None, ports=None, environment=None,
dns=None, volumes=None, volumes_from=None,
network_disabled=False, name=None, entrypoint=None,
cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=0, cpuset=None, host_config=None,
memswap_limit=None, cpuset=None, host_config=None,
mac_address=None, labels=None, volume_driver=None):

if isinstance(volumes, six.string_types):
Expand Down
39 changes: 32 additions & 7 deletions docker/utils/utils.py
Expand Up @@ -378,10 +378,21 @@ def create_host_config(
dns=None, dns_search=None, volumes_from=None, network_mode=None,
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
security_opt=None, ulimits=None, log_config=None, mem_limit=None,
memswap_limit=None
):
host_config = {}

if mem_limit is not None:
if isinstance(mem_limit, six.string_types):
mem_limit = parse_bytes(mem_limit)
host_config['Memory'] = mem_limit

if memswap_limit is not None:
if isinstance(memswap_limit, six.string_types):
memswap_limit = parse_bytes(memswap_limit)
host_config['MemorySwap'] = memswap_limit

if pid_mode not in (None, 'host'):
raise errors.DockerException(
'Invalid value for pid param: {0}'.format(pid_mode)
Expand Down Expand Up @@ -498,10 +509,10 @@ def create_host_config(

def create_container_config(
version, image, command, hostname=None, user=None, detach=False,
stdin_open=False, tty=False, mem_limit=0, ports=None, environment=None,
stdin_open=False, tty=False, mem_limit=None, ports=None, environment=None,
dns=None, volumes=None, volumes_from=None, network_disabled=False,
entrypoint=None, cpu_shares=None, working_dir=None, domainname=None,
memswap_limit=0, cpuset=None, host_config=None, mac_address=None,
memswap_limit=None, cpuset=None, host_config=None, mac_address=None,
labels=None, volume_driver=None
):
if isinstance(command, six.string_types):
Expand All @@ -517,10 +528,24 @@ def create_container_config(
'labels were only introduced in API version 1.18'
)

if volume_driver is not None and compare_version('1.19', version) < 0:
raise errors.InvalidVersion(
'Volume drivers were only introduced in API version 1.19'
)
if compare_version('1.19', version) < 0:
if volume_driver is not None:
raise errors.InvalidVersion(
'Volume drivers were only introduced in API version 1.19'
)
mem_limit = mem_limit if mem_limit is not None else 0
memswap_limit = memswap_limit if memswap_limit is not None else 0
else:
if mem_limit is not None:
raise errors.InvalidVersion(
'mem_limit has been moved to host_config in API version 1.19'
)

if memswap_limit is not None:
raise errors.InvalidVersion(
'memswap_limit has been moved to host_config in API '
'version 1.19'
)

if isinstance(labels, list):
labels = dict((lbl, six.text_type('')) for lbl in labels)
Expand Down

0 comments on commit 427e3a6

Please sign in to comment.