Add ability to set 'Hostname' on a Service.

Signed-off-by: Nils Krabshuis <nils.krabshuis@redwood.com>
This commit is contained in:
Nils Krabshuis 2017-02-19 06:18:26 +01:00
parent b791aa10fa
commit 44c31e47e0
3 changed files with 11 additions and 5 deletions

View File

@ -96,6 +96,7 @@ class ServiceCollection(Collection):
access and load balance a service. Default: ``None``.
env (list of str): Environment variables, in the form
``KEY=val``.
hostname (string): Hostname to set on the container.
labels (dict): Labels to apply to the service.
log_driver (str): Log driver to use for containers.
log_driver_options (dict): Log driver options.
@ -176,6 +177,7 @@ CONTAINER_SPEC_KWARGS = [
'command',
'args',
'env',
'hostname',
'workdir',
'user',
'labels',

View File

@ -70,6 +70,7 @@ class ContainerSpec(dict):
image (string): The image name to use for the container.
command (string or list): The command to be run in the image.
args (:py:class:`list`): Arguments to the command.
hostname (string): The hostname to set on the container.
env (dict): Environment variables.
dir (string): The working directory for commands to run in.
user (string): The user inside the container.
@ -82,9 +83,9 @@ class ContainerSpec(dict):
secrets (list of py:class:`SecretReference`): List of secrets to be
made available inside the containers.
"""
def __init__(self, image, command=None, args=None, env=None, workdir=None,
user=None, labels=None, mounts=None, stop_grace_period=None,
secrets=None):
def __init__(self, image, command=None, args=None, hostname=None, env=None,
workdir=None, user=None, labels=None, mounts=None,
stop_grace_period=None, secrets=None):
self['Image'] = image
if isinstance(command, six.string_types):
@ -92,6 +93,8 @@ class ContainerSpec(dict):
self['Command'] = command
self['Args'] = args
if hostname is not None:
self['Hostname'] = hostname
if env is not None:
if isinstance(env, dict):
self['Env'] = format_environment(env)

View File

@ -9,6 +9,7 @@ class CreateServiceKwargsTest(unittest.TestCase):
'command': 'true',
'name': 'somename',
'labels': {'key': 'value'},
'hostname': 'test_host',
'mode': 'global',
'update_config': {'update': 'config'},
'networks': ['somenet'],
@ -47,6 +48,6 @@ class CreateServiceKwargsTest(unittest.TestCase):
'Options': {'foo': 'bar'}
}
assert set(task_template['ContainerSpec'].keys()) == set([
'Image', 'Command', 'Args', 'Env', 'Dir', 'User', 'Labels',
'Mounts', 'StopGracePeriod'
'Image', 'Command', 'Args', 'Hostname', 'Env', 'Dir', 'User',
'Labels', 'Mounts', 'StopGracePeriod'
])