Przeglądaj źródła

Implement review suggestions.

Signed-off-by: Alexey Rokhin <[email protected]>
Alexey Rokhin 8 lat temu
rodzic
commit
b7c688cc37
2 zmienionych plików z 5 dodań i 2 usunięć
  1. 1 1
      compose/config/config_schema_v2.2.json
  2. 4 1
      compose/service.py

+ 1 - 1
compose/config/config_schema_v2.2.json

@@ -78,7 +78,7 @@
         "cpu_percent": {"type": "integer", "minimum": 0, "maximum": 100},
         "cpu_shares": {"type": ["number", "string"]},
         "cpu_quota": {"type": ["number", "string"]},
-        "cpus": {"type": ["number", "string"], "minimum": 0},
+        "cpus": {"type": "number", "minimum": 0},
         "cpuset": {"type": "string"},
         "depends_on": {
           "oneOf": [

+ 4 - 1
compose/service.py

@@ -803,7 +803,10 @@ class Service(object):
 
         nano_cpus = None
         if 'cpus' in options:
-            nano_cpus = int(options.get('cpus') * 1000000000)
+            nano_cpus = options.get('cpus') * 1000000000
+            if isinstance(nano_cpus, float) and not nano_cpus.is_integer():
+                raise ValueError("cpus is too precise")
+            nano_cpus = int(nano_cpus)
 
         return self.client.create_host_config(
             links=self._get_links(link_to_self=one_off),