mirror of https://github.com/docker/compose.git
Add support for 'cpu_period' for compose v2.1-v2.3.
Signed-off-by: Matthieu Nottale <matthieu.nottale@docker.com>
This commit is contained in:
parent
eee55231b8
commit
b9f9643d24
|
@ -67,6 +67,7 @@ DOCKER_CONFIG_KEYS = [
|
|||
'command',
|
||||
'cpu_count',
|
||||
'cpu_percent',
|
||||
'cpu_period',
|
||||
'cpu_quota',
|
||||
'cpu_shares',
|
||||
'cpus',
|
||||
|
|
|
@ -106,6 +106,7 @@
|
|||
"container_name": {"type": "string"},
|
||||
"cpu_shares": {"type": ["number", "string"]},
|
||||
"cpu_quota": {"type": ["number", "string"]},
|
||||
"cpu_period": {"type": ["number", "string"]},
|
||||
"cpuset": {"type": "string"},
|
||||
"depends_on": {
|
||||
"oneOf": [
|
||||
|
|
|
@ -110,6 +110,7 @@
|
|||
"cpu_percent": {"type": "integer", "minimum": 0, "maximum": 100},
|
||||
"cpu_shares": {"type": ["number", "string"]},
|
||||
"cpu_quota": {"type": ["number", "string"]},
|
||||
"cpu_period": {"type": ["number", "string"]},
|
||||
"cpus": {"type": "number", "minimum": 0},
|
||||
"cpuset": {"type": "string"},
|
||||
"depends_on": {
|
||||
|
|
|
@ -113,6 +113,7 @@
|
|||
"cpu_percent": {"type": "integer", "minimum": 0, "maximum": 100},
|
||||
"cpu_shares": {"type": ["number", "string"]},
|
||||
"cpu_quota": {"type": ["number", "string"]},
|
||||
"cpu_period": {"type": ["number", "string"]},
|
||||
"cpus": {"type": "number", "minimum": 0},
|
||||
"cpuset": {"type": "string"},
|
||||
"depends_on": {
|
||||
|
|
|
@ -10,6 +10,7 @@ import six
|
|||
from .errors import ConfigurationError
|
||||
from compose.const import COMPOSEFILE_V2_0 as V2_0
|
||||
from compose.utils import parse_bytes
|
||||
from compose.utils import parse_nanoseconds_int
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -223,6 +224,12 @@ def bytes_to_int(s):
|
|||
return v
|
||||
|
||||
|
||||
def to_microseconds(v):
|
||||
if not isinstance(v, six.string_types):
|
||||
return v
|
||||
return int(parse_nanoseconds_int(v) / 1000)
|
||||
|
||||
|
||||
class ConversionMap(object):
|
||||
map = {
|
||||
service_path('blkio_config', 'weight'): to_int,
|
||||
|
@ -230,6 +237,8 @@ class ConversionMap(object):
|
|||
service_path('build', 'labels', FULL_JOKER): to_str,
|
||||
service_path('cpus'): to_float,
|
||||
service_path('cpu_count'): to_int,
|
||||
service_path('cpu_quota'): to_microseconds,
|
||||
service_path('cpu_period'): to_microseconds,
|
||||
service_path('configs', 'mode'): to_int,
|
||||
service_path('secrets', 'mode'): to_int,
|
||||
service_path('healthcheck', 'retries'): to_int,
|
||||
|
|
|
@ -62,6 +62,7 @@ HOST_CONFIG_KEYS = [
|
|||
'cgroup_parent',
|
||||
'cpu_count',
|
||||
'cpu_percent',
|
||||
'cpu_period',
|
||||
'cpu_quota',
|
||||
'cpu_shares',
|
||||
'cpus',
|
||||
|
@ -948,6 +949,7 @@ class Service(object):
|
|||
device_write_iops=blkio_config.get('device_write_iops'),
|
||||
mounts=options.get('mounts'),
|
||||
device_cgroup_rules=options.get('device_cgroup_rules'),
|
||||
cpu_period=options.get('cpu_period'),
|
||||
)
|
||||
|
||||
def get_secret_volumes(self):
|
||||
|
|
|
@ -121,10 +121,11 @@ class ServiceTest(DockerClientTestCase):
|
|||
assert container.get('HostConfig.CpuShares') == 73
|
||||
|
||||
def test_create_container_with_cpu_quota(self):
|
||||
service = self.create_service('db', cpu_quota=40000)
|
||||
service = self.create_service('db', cpu_quota=40000, cpu_period=150000)
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
assert container.get('HostConfig.CpuQuota') == 40000
|
||||
assert container.get('HostConfig.CpuPeriod') == 150000
|
||||
|
||||
@v2_2_only()
|
||||
def test_create_container_with_cpu_count(self):
|
||||
|
|
Loading…
Reference in New Issue