Skip to content

Commit 161bfba

Browse files
committed
Add support for storage_opt in host_config
Signed-off-by: Joffrey F <[email protected]>
1 parent 7382eb1 commit 161bfba

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

docker/api/container.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ def create_host_config(self, *args, **kwargs):
549549
security_opt (:py:class:`list`): A list of string values to
550550
customize labels for MLS systems, such as SELinux.
551551
shm_size (str or int): Size of /dev/shm (e.g. ``1G``).
552+
storage_opt (dict): Storage driver options per container as a
553+
key-value mapping.
552554
sysctls (dict): Kernel parameters to set in the container.
553555
tmpfs (dict): Temporary filesystems to mount, as a dictionary
554556
mapping a path inside the container to options for that path.

docker/models/containers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ def run(self, image, command=None, stdout=True, stderr=False,
586586
Default: ``False``.
587587
stop_signal (str): The stop signal to use to stop the container
588588
(e.g. ``SIGINT``).
589+
storage_opt (dict): Storage driver options per container as a
590+
key-value mapping.
589591
sysctls (dict): Kernel parameters to set in the container.
590592
tmpfs (dict): Temporary filesystems to mount, as a dictionary
591593
mapping a path inside the container to options for that path.
@@ -833,6 +835,7 @@ def prune(self, filters=None):
833835
'restart_policy',
834836
'security_opt',
835837
'shm_size',
838+
'storage_opt',
836839
'sysctls',
837840
'tmpfs',
838841
'ulimits',

docker/types/containers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __init__(self, version, binds=None, port_bindings=None,
117117
oom_kill_disable=False, shm_size=None, sysctls=None,
118118
tmpfs=None, oom_score_adj=None, dns_opt=None, cpu_shares=None,
119119
cpuset_cpus=None, userns_mode=None, pids_limit=None,
120-
isolation=None, auto_remove=False):
120+
isolation=None, auto_remove=False, storage_opt=None):
121121

122122
if mem_limit is not None:
123123
self['Memory'] = parse_bytes(mem_limit)
@@ -412,6 +412,11 @@ def __init__(self, version, binds=None, port_bindings=None,
412412
raise host_config_version_error('auto_remove', '1.25')
413413
self['AutoRemove'] = auto_remove
414414

415+
if storage_opt is not None:
416+
if version_lt(version, '1.24'):
417+
raise host_config_version_error('storage_opt', '1.24')
418+
self['StorageOpt'] = storage_opt
419+
415420

416421
def host_config_type_error(param, param_value, expected):
417422
error_msg = 'Invalid type for {0} param: expected {1} but found {2}'

tests/integration/api_container_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,22 @@ def test_create_with_stop_timeout(self):
422422
config = self.client.inspect_container(container)
423423
assert config['Config']['StopTimeout'] == 25
424424

425+
@requires_api_version('1.24')
426+
def test_create_with_storage_opt(self):
427+
if self.client.info()['Driver'] == 'aufs':
428+
return pytest.skip('Not supported on AUFS')
429+
host_config = self.client.create_host_config(
430+
storage_opt={'size': '120G'}
431+
)
432+
container = self.client.create_container(
433+
BUSYBOX, ['echo', 'test'], host_config=host_config
434+
)
435+
self.tmp_containers.append(container)
436+
config = self.client.inspect_container(container)
437+
assert config['HostConfig']['StorageOpt'] == {
438+
'size': '120G'
439+
}
440+
425441

426442
class VolumeBindTest(BaseAPIIntegrationTest):
427443
def setUp(self):

tests/integration/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def setUp(self):
7575
version=TEST_API_VERSION, timeout=60, **kwargs_from_env()
7676
)
7777

78+
def tearDown(self):
79+
super(BaseAPIIntegrationTest, self).tearDown()
80+
self.client.close()
81+
7882
def run_container(self, *args, **kwargs):
7983
container = self.client.create_container(*args, **kwargs)
8084
self.tmp_containers.append(container)

0 commit comments

Comments
 (0)