mirror of https://github.com/docker/docker-py.git
Added log_config support in host config
This commit is contained in:
parent
8316fa4e03
commit
21d80b16dd
|
@ -5,4 +5,4 @@ from .utils import (
|
|||
create_container_config, parse_bytes, ping_registry
|
||||
) # flake8: noqa
|
||||
|
||||
from .types import Ulimit # flake8: noqa
|
||||
from .types import Ulimit, LogConfig # flake8: noqa
|
|
@ -1,12 +1,63 @@
|
|||
import six
|
||||
|
||||
|
||||
class LogConfigTypesEnum(object):
|
||||
_values = (
|
||||
'json-file',
|
||||
'syslog',
|
||||
'none'
|
||||
)
|
||||
JSON, SYSLOG, NONE = _values
|
||||
|
||||
|
||||
class DictType(dict):
|
||||
def __init__(self, init):
|
||||
for k, v in six.iteritems(init):
|
||||
self[k] = v
|
||||
|
||||
|
||||
class LogConfig(DictType):
|
||||
types = LogConfigTypesEnum
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
type_ = kwargs.get('type', kwargs.get('Type'))
|
||||
config = kwargs.get('config', kwargs.get('Config'))
|
||||
if type_ not in self.types._values:
|
||||
raise ValueError("LogConfig.type must be one of ({0})".format(
|
||||
', '.join(self.types._values)
|
||||
))
|
||||
if config and not isinstance(config, dict):
|
||||
raise ValueError("LogConfig.config must be a dictionary")
|
||||
|
||||
super(LogConfig, self).__init__({
|
||||
'Type': type_,
|
||||
'Config': config or {}
|
||||
})
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
return self['Type']
|
||||
|
||||
@type.setter
|
||||
def type(self, value):
|
||||
if value not in self.types._values:
|
||||
raise ValueError("LogConfig.type must be one of {0}".format(
|
||||
', '.join(self.types._values)
|
||||
))
|
||||
self['Type'] = value
|
||||
|
||||
@property
|
||||
def config(self):
|
||||
return self['Config']
|
||||
|
||||
def set_config_value(self, key, value):
|
||||
self.config[key] = value
|
||||
|
||||
def unset_config(self, key):
|
||||
if key in self.config:
|
||||
del self.config[key]
|
||||
|
||||
|
||||
class Ulimit(DictType):
|
||||
def __init__(self, **kwargs):
|
||||
name = kwargs.get('name', kwargs.get('Name'))
|
||||
|
|
|
@ -28,7 +28,7 @@ import six
|
|||
|
||||
from .. import errors
|
||||
from .. import tls
|
||||
from .types import Ulimit
|
||||
from .types import Ulimit, LogConfig
|
||||
|
||||
|
||||
DEFAULT_HTTP_HOST = "127.0.0.1"
|
||||
|
@ -359,7 +359,7 @@ def create_host_config(
|
|||
dns=None, dns_search=None, volumes_from=None, network_mode=None,
|
||||
restart_policy=None, cap_add=None, cap_drop=None, devices=None,
|
||||
extra_hosts=None, read_only=None, pid_mode=None, ipc_mode=None,
|
||||
security_opt=None, ulimits=None
|
||||
security_opt=None, ulimits=None, log_config=None
|
||||
):
|
||||
host_config = {}
|
||||
|
||||
|
@ -456,13 +456,24 @@ def create_host_config(
|
|||
if not isinstance(ulimits, list):
|
||||
raise errors.DockerException(
|
||||
'Invalid type for ulimits param: expected list but found'
|
||||
' {0}'.format(type(ulimits)))
|
||||
' {0}'.format(type(ulimits))
|
||||
)
|
||||
host_config['Ulimits'] = []
|
||||
for l in ulimits:
|
||||
if not isinstance(l, Ulimit):
|
||||
l = Ulimit(**l)
|
||||
host_config['Ulimits'].append(l)
|
||||
|
||||
if log_config is not None:
|
||||
if not isinstance(log_config, LogConfig):
|
||||
if not isinstance(log_config, dict):
|
||||
raise errors.DockerException(
|
||||
'Invalid type for log_config param: expected LogConfig but'
|
||||
' found {0}'.format(type(log_config))
|
||||
)
|
||||
log_config = LogConfig(**log_config)
|
||||
host_config['LogConfig'] = log_config
|
||||
|
||||
return host_config
|
||||
|
||||
|
||||
|
|
|
@ -85,8 +85,11 @@ for example:
|
|||
* read_only (bool): mount the container's root filesystem as read only
|
||||
* pid_mode (str): if set to "host", use the host PID namespace inside the
|
||||
container
|
||||
* security_opt (list): A list of string values to customize labels for MLS systems, such as SELinux.
|
||||
* ulimits (list): A list of dicts or `docker.utils.Ulimit` objects.
|
||||
* security_opt (list): A list of string values to customize labels for MLS
|
||||
systems, such as SELinux.
|
||||
* ulimits (list): A list of dicts or `docker.utils.Ulimit` objects. A list
|
||||
of ulimits to be set in the container.
|
||||
* log_config (`docker.utils.LogConfig` or dict): Logging configuration to container
|
||||
|
||||
**Returns** (dict) HostConfig dictionary
|
||||
|
||||
|
|
Loading…
Reference in New Issue