mirror of https://github.com/docker/docker-py.git
Merge branch 'joshpurvis-jp-cpushares'
This commit is contained in:
commit
3709c709f3
|
@ -620,7 +620,8 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
|
|||
device_write_bps=None, device_read_iops=None,
|
||||
device_write_iops=None, oom_kill_disable=False,
|
||||
shm_size=None, sysctls=None, version=None, tmpfs=None,
|
||||
oom_score_adj=None, dns_opt=None):
|
||||
oom_score_adj=None, dns_opt=None, cpu_shares=None,
|
||||
cpuset_cpus=None):
|
||||
|
||||
host_config = {}
|
||||
|
||||
|
@ -809,6 +810,21 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
|
|||
|
||||
host_config['CpuPeriod'] = cpu_period
|
||||
|
||||
if cpu_shares:
|
||||
if version_lt(version, '1.18'):
|
||||
raise host_config_version_error('cpu_shares', '1.18')
|
||||
|
||||
if not isinstance(cpu_shares, int):
|
||||
raise host_config_type_error('cpu_shares', cpu_shares, 'int')
|
||||
|
||||
host_config['CpuShares'] = cpu_shares
|
||||
|
||||
if cpuset_cpus:
|
||||
if version_lt(version, '1.18'):
|
||||
raise host_config_version_error('cpuset_cpus', '1.18')
|
||||
|
||||
host_config['CpuSetCpus'] = cpuset_cpus
|
||||
|
||||
if blkio_weight:
|
||||
if not isinstance(blkio_weight, int):
|
||||
raise host_config_type_error('blkio_weight', blkio_weight, 'int')
|
||||
|
@ -981,6 +997,14 @@ def create_container_config(
|
|||
'labels were only introduced in API version 1.18'
|
||||
)
|
||||
|
||||
if cpuset is not None or cpu_shares is not None:
|
||||
if version_gte(version, '1.18'):
|
||||
warnings.warn(
|
||||
'The cpuset_cpus and cpu_shares options have been moved to '
|
||||
'host_config in API version 1.18, and will be removed',
|
||||
DeprecationWarning
|
||||
)
|
||||
|
||||
if stop_signal is not None and compare_version('1.21', version) < 0:
|
||||
raise errors.InvalidVersion(
|
||||
'stop_signal was only introduced in API version 1.21'
|
||||
|
@ -1010,6 +1034,7 @@ def create_container_config(
|
|||
|
||||
if mem_limit is not None:
|
||||
mem_limit = parse_bytes(mem_limit)
|
||||
|
||||
if memswap_limit is not None:
|
||||
memswap_limit = parse_bytes(memswap_limit)
|
||||
|
||||
|
|
|
@ -246,7 +246,6 @@ from. Optionally a single string joining container id's with commas
|
|||
* network_disabled (bool): Disable networking
|
||||
* name (str): A name for the container
|
||||
* entrypoint (str or list): An entrypoint
|
||||
* cpu_shares (int): CPU shares (relative weight)
|
||||
* working_dir (str): Path to the working directory
|
||||
* domainname (str or list): Set custom DNS search domains
|
||||
* memswap_limit (int):
|
||||
|
|
|
@ -109,6 +109,8 @@ for example:
|
|||
* cpu_group (int): The length of a CPU period in microseconds.
|
||||
* cpu_period (int): Microseconds of CPU time that the container can get in a
|
||||
CPU period.
|
||||
* cpu_shares (int): CPU shares (relative weight)
|
||||
* cpuset_cpus (str): CPUs in which to allow execution (0-3, 0,1)
|
||||
* blkio_weight: Block IO weight (relative weight), accepts a weight value between 10 and 1000.
|
||||
* blkio_weight_device: Block IO weight (relative device weight) in the form of:
|
||||
`[{"Path": "device_path", "Weight": weight}]`
|
||||
|
|
|
@ -1096,11 +1096,38 @@ class ContainerUpdateTest(helpers.BaseTestCase):
|
|||
container = self.client.create_container(
|
||||
BUSYBOX, 'top', host_config=self.client.create_host_config(
|
||||
mem_limit=old_mem_limit
|
||||
), cpu_shares=102
|
||||
)
|
||||
)
|
||||
self.tmp_containers.append(container)
|
||||
self.client.start(container)
|
||||
self.client.update_container(container, mem_limit=new_mem_limit)
|
||||
inspect_data = self.client.inspect_container(container)
|
||||
self.assertEqual(inspect_data['HostConfig']['Memory'], new_mem_limit)
|
||||
self.assertEqual(inspect_data['HostConfig']['CpuShares'], 102)
|
||||
|
||||
|
||||
class ContainerCPUTest(helpers.BaseTestCase):
|
||||
@requires_api_version('1.18')
|
||||
def test_container_cpu_shares(self):
|
||||
cpu_shares = 512
|
||||
container = self.client.create_container(
|
||||
BUSYBOX, 'ls', host_config=self.client.create_host_config(
|
||||
cpu_shares=cpu_shares
|
||||
)
|
||||
)
|
||||
self.tmp_containers.append(container)
|
||||
self.client.start(container)
|
||||
inspect_data = self.client.inspect_container(container)
|
||||
self.assertEqual(inspect_data['HostConfig']['CpuShares'], 512)
|
||||
|
||||
@requires_api_version('1.18')
|
||||
def test_container_cpuset(self):
|
||||
cpuset_cpus = "0,1"
|
||||
container = self.client.create_container(
|
||||
BUSYBOX, 'ls', host_config=self.client.create_host_config(
|
||||
cpuset_cpus=cpuset_cpus
|
||||
)
|
||||
)
|
||||
self.tmp_containers.append(container)
|
||||
self.client.start(container)
|
||||
inspect_data = self.client.inspect_container(container)
|
||||
self.assertEqual(inspect_data['HostConfig']['CpusetCpus'], cpuset_cpus)
|
||||
|
|
|
@ -286,6 +286,33 @@ class CreateContainerTest(DockerClientTest):
|
|||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
|
||||
@requires_api_version('1.18')
|
||||
def test_create_container_with_host_config_cpu_shares(self):
|
||||
self.client.create_container(
|
||||
'busybox', 'ls', host_config=self.client.create_host_config(
|
||||
cpu_shares=512
|
||||
)
|
||||
)
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(args[0][1],
|
||||
url_prefix + 'containers/create')
|
||||
|
||||
self.assertEqual(json.loads(args[1]['data']),
|
||||
json.loads('''
|
||||
{"Tty": false, "Image": "busybox",
|
||||
"Cmd": ["ls"], "AttachStdin": false,
|
||||
"AttachStderr": true,
|
||||
"AttachStdout": true, "OpenStdin": false,
|
||||
"StdinOnce": false,
|
||||
"NetworkDisabled": false,
|
||||
"HostConfig": {
|
||||
"CpuShares": 512,
|
||||
"NetworkMode": "default"
|
||||
}}'''))
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
|
||||
def test_create_container_with_cpuset(self):
|
||||
self.client.create_container('busybox', 'ls',
|
||||
cpuset='0,1')
|
||||
|
@ -306,6 +333,33 @@ class CreateContainerTest(DockerClientTest):
|
|||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
|
||||
@requires_api_version('1.18')
|
||||
def test_create_container_with_host_config_cpuset(self):
|
||||
self.client.create_container(
|
||||
'busybox', 'ls', host_config=self.client.create_host_config(
|
||||
cpuset_cpus='0,1'
|
||||
)
|
||||
)
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(args[0][1],
|
||||
url_prefix + 'containers/create')
|
||||
|
||||
self.assertEqual(json.loads(args[1]['data']),
|
||||
json.loads('''
|
||||
{"Tty": false, "Image": "busybox",
|
||||
"Cmd": ["ls"], "AttachStdin": false,
|
||||
"AttachStderr": true,
|
||||
"AttachStdout": true, "OpenStdin": false,
|
||||
"StdinOnce": false,
|
||||
"NetworkDisabled": false,
|
||||
"HostConfig": {
|
||||
"CpuSetCpus": "0,1",
|
||||
"NetworkMode": "default"
|
||||
}}'''))
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
|
||||
def test_create_container_with_cgroup_parent(self):
|
||||
self.client.create_container(
|
||||
'busybox', 'ls', host_config=self.client.create_host_config(
|
||||
|
|
Loading…
Reference in New Issue