mirror of https://github.com/docker/compose.git
move cpus validation to validation.py
Signed-off-by: Alexey Rokhin <arokhin@mail.ru>
This commit is contained in:
parent
b7c688cc37
commit
61e54514c4
|
@ -38,6 +38,7 @@ from .types import VolumeSpec
|
|||
from .validation import match_named_volumes
|
||||
from .validation import validate_against_config_schema
|
||||
from .validation import validate_config_section
|
||||
from .validation import validate_cpu
|
||||
from .validation import validate_depends_on
|
||||
from .validation import validate_extends_file_path
|
||||
from .validation import validate_links
|
||||
|
@ -643,6 +644,7 @@ def validate_service(service_config, service_names, config_file):
|
|||
validate_service_constraints(service_dict, service_name, config_file)
|
||||
validate_paths(service_dict)
|
||||
|
||||
validate_cpu(service_config)
|
||||
validate_ulimits(service_config)
|
||||
validate_network_mode(service_config, service_names)
|
||||
validate_depends_on(service_config, service_names)
|
||||
|
|
|
@ -15,6 +15,7 @@ from jsonschema import RefResolver
|
|||
from jsonschema import ValidationError
|
||||
|
||||
from ..const import COMPOSEFILE_V1 as V1
|
||||
from ..const import NANOCPUS_SCALE
|
||||
from .errors import ConfigurationError
|
||||
from .errors import VERSION_EXPLANATION
|
||||
from .sort_services import get_service_name_from_network_mode
|
||||
|
@ -387,6 +388,16 @@ def validate_service_constraints(config, service_name, config_file):
|
|||
handle_errors(validator.iter_errors(config), handler, None)
|
||||
|
||||
|
||||
def validate_cpu(service_config):
|
||||
cpus = service_config.config.get('cpus')
|
||||
if not cpus:
|
||||
return
|
||||
nano_cpus = cpus * NANOCPUS_SCALE
|
||||
if isinstance(nano_cpus, float) and not nano_cpus.is_integer():
|
||||
raise ConfigurationError(
|
||||
"cpus must have nine or less digits after decimal point")
|
||||
|
||||
|
||||
def get_schema_path():
|
||||
return os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ LABEL_NETWORK = 'com.docker.compose.network'
|
|||
LABEL_VERSION = 'com.docker.compose.version'
|
||||
LABEL_VOLUME = 'com.docker.compose.volume'
|
||||
LABEL_CONFIG_HASH = 'com.docker.compose.config-hash'
|
||||
NANOCPUS_SCALE = 1000000000
|
||||
|
||||
SECRETS_PATH = '/run/secrets'
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ from .const import LABEL_ONE_OFF
|
|||
from .const import LABEL_PROJECT
|
||||
from .const import LABEL_SERVICE
|
||||
from .const import LABEL_VERSION
|
||||
from .const import NANOCPUS_SCALE
|
||||
from .container import Container
|
||||
from .errors import HealthCheckFailed
|
||||
from .errors import NoHealthCheckConfigured
|
||||
|
@ -803,10 +804,7 @@ class Service(object):
|
|||
|
||||
nano_cpus = None
|
||||
if 'cpus' in options:
|
||||
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)
|
||||
nano_cpus = int(options.get('cpus') * NANOCPUS_SCALE)
|
||||
|
||||
return self.client.create_host_config(
|
||||
links=self._get_links(link_to_self=one_off),
|
||||
|
|
Loading…
Reference in New Issue