Преглед на файлове

Added support for cpu_quota flag

Signed-off-by: Dimitar Bonev <[email protected]>
Dimitar Bonev преди 9 години
родител
ревизия
a542041264
променени са 5 файла, в които са добавени 12 реда и са изтрити 1 реда
  1. 1 0
      compose/config/config.py
  2. 1 0
      compose/config/fields_schema.json
  3. 2 0
      compose/service.py
  4. 2 1
      docs/compose-file.md
  5. 6 0
      tests/integration/service_test.py

+ 1 - 0
compose/config/config.py

@@ -31,6 +31,7 @@ DOCKER_CONFIG_KEYS = [
     'cap_drop',
     'cgroup_parent',
     'command',
+    'cpu_quota',
     'cpu_shares',
     'cpuset',
     'detach',

+ 1 - 0
compose/config/fields_schema.json

@@ -29,6 +29,7 @@
         },
         "container_name": {"type": "string"},
         "cpu_shares": {"type": ["number", "string"]},
+        "cpu_quota": {"type": ["number", "string"]},
         "cpuset": {"type": "string"},
         "devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
         "dns": {"$ref": "#/definitions/string_or_list"},

+ 2 - 0
compose/service.py

@@ -59,6 +59,7 @@ DOCKER_START_KEYS = [
     'restart',
     'volumes_from',
     'security_opt',
+    'cpu_quota',
 ]
 
 
@@ -610,6 +611,7 @@ class Service(object):
             security_opt=options.get('security_opt'),
             ipc_mode=options.get('ipc'),
             cgroup_parent=options.get('cgroup_parent'),
+            cpu_quota=options.get('cpu_quota'),
         )
 
     def build(self, no_cache=False, pull=False, force_rm=False):

+ 2 - 1
docs/compose-file.md

@@ -385,12 +385,13 @@ specifying read-only access(``ro``) or read-write(``rw``).
      - container_name
      - service_name:rw
 
-### cpu\_shares, cpuset, domainname, entrypoint, hostname, ipc, mac\_address, mem\_limit, memswap\_limit, privileged, read\_only, restart, stdin\_open, tty, user, working\_dir
+### cpu\_shares, cpu\_quota, cpuset, domainname, entrypoint, hostname, ipc, mac\_address, mem\_limit, memswap\_limit, privileged, read\_only, restart, stdin\_open, tty, user, working\_dir
 
 Each of these is a single value, analogous to its
 [docker run](https://docs.docker.com/reference/run/) counterpart.
 
     cpu_shares: 73
+    cpu_quota: 50000
     cpuset: 0,1
 
     entrypoint: /code/entrypoint.sh

+ 6 - 0
tests/integration/service_test.py

@@ -102,6 +102,12 @@ class ServiceTest(DockerClientTestCase):
         container.start()
         self.assertEqual(container.get('HostConfig.CpuShares'), 73)
 
+    def test_create_container_with_cpu_quota(self):
+        service = self.create_service('db', cpu_quota=40000)
+        container = service.create_container()
+        container.start()
+        self.assertEqual(container.get('HostConfig.CpuQuota'), 40000)
+
     def test_create_container_with_extra_hosts_list(self):
         extra_hosts = ['somehost:162.242.195.82', 'otherhost:50.31.209.229']
         service = self.create_service('db', extra_hosts=extra_hosts)