diff options
| author | Joffrey F <f.joffrey@gmail.com> | 2019-08-27 00:21:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-27 00:21:27 -0700 |
| commit | 8fea5738d32cfb712fcb05f541bc63eaf1d7ed71 (patch) | |
| tree | c43b4dda4f28e18a27f65bd8ed8e641365d1b2d7 /docker | |
| parent | 1fc62e6a32c2d3257d5d033fcf924fabb16190ac (diff) | |
| parent | bcd61e40ddb80735fd6b479c96aaa18cf392020d (diff) | |
| download | docker-py-8fea5738d32cfb712fcb05f541bc63eaf1d7ed71.tar.gz | |
Merge pull request #2333 from hannseman/network-attachment-config
Add NetworkAttachmentConfig for service create/update
Diffstat (limited to 'docker')
| -rw-r--r-- | docker/api/service.py | 10 | ||||
| -rw-r--r-- | docker/models/services.py | 12 | ||||
| -rw-r--r-- | docker/types/__init__.py | 2 | ||||
| -rw-r--r-- | docker/types/services.py | 22 |
4 files changed, 34 insertions, 12 deletions
diff --git a/docker/api/service.py b/docker/api/service.py index 372dd10..e9027bf 100644 --- a/docker/api/service.py +++ b/docker/api/service.py @@ -135,8 +135,9 @@ class ServiceApiMixin(object): of the service. Default: ``None`` rollback_config (RollbackConfig): Specification for the rollback strategy of the service. Default: ``None`` - networks (:py:class:`list`): List of network names or IDs to attach - the service to. Default: ``None``. + networks (:py:class:`list`): List of network names or IDs or + :py:class:`~docker.types.NetworkAttachmentConfig` to attach the + service to. Default: ``None``. endpoint_spec (EndpointSpec): Properties that can be configured to access and load balance a service. Default: ``None``. @@ -383,8 +384,9 @@ class ServiceApiMixin(object): of the service. Default: ``None``. rollback_config (RollbackConfig): Specification for the rollback strategy of the service. Default: ``None`` - networks (:py:class:`list`): List of network names or IDs to attach - the service to. Default: ``None``. + networks (:py:class:`list`): List of network names or IDs or + :py:class:`~docker.types.NetworkAttachmentConfig` to attach the + service to. Default: ``None``. endpoint_spec (EndpointSpec): Properties that can be configured to access and load balance a service. Default: ``None``. fetch_current_spec (boolean): Use the undefined settings from the diff --git a/docker/models/services.py b/docker/models/services.py index 2b6479f..a35687b 100644 --- a/docker/models/services.py +++ b/docker/models/services.py @@ -178,11 +178,12 @@ class ServiceCollection(Collection): ``source:target:options``, where options is either ``ro`` or ``rw``. name (str): Name to give to the service. - networks (list of str): List of network names or IDs to attach - the service to. Default: ``None``. + networks (:py:class:`list`): List of network names or IDs or + :py:class:`~docker.types.NetworkAttachmentConfig` to attach the + service to. Default: ``None``. resources (Resources): Resource limits and reservations. restart_policy (RestartPolicy): Restart policy for containers. - secrets (list of :py:class:`docker.types.SecretReference`): List + secrets (list of :py:class:`~docker.types.SecretReference`): List of secrets accessible to containers for this service. stop_grace_period (int): Amount of time to wait for containers to terminate before forcefully killing them. @@ -205,8 +206,9 @@ class ServiceCollection(Collection): the container's `hosts` file. dns_config (DNSConfig): Specification for DNS related configurations in resolver configuration file. - configs (:py:class:`list`): List of :py:class:`ConfigReference` - that will be exposed to the service. + configs (:py:class:`list`): List of + :py:class:`~docker.types.ConfigReference` that will be exposed + to the service. privileges (Privileges): Security options for the service's containers. diff --git a/docker/types/__init__.py b/docker/types/__init__.py index f3cac1b..5db330e 100644 --- a/docker/types/__init__.py +++ b/docker/types/__init__.py @@ -7,6 +7,6 @@ from .services import ( ConfigReference, ContainerSpec, DNSConfig, DriverConfig, EndpointSpec, Mount, Placement, PlacementPreference, Privileges, Resources, RestartPolicy, RollbackConfig, SecretReference, ServiceMode, TaskTemplate, - UpdateConfig + UpdateConfig, NetworkAttachmentConfig ) from .swarm import SwarmSpec, SwarmExternalCA diff --git a/docker/types/services.py b/docker/types/services.py index 5722b0e..05dda15 100644 --- a/docker/types/services.py +++ b/docker/types/services.py @@ -26,8 +26,8 @@ class TaskTemplate(dict): placement (Placement): Placement instructions for the scheduler. If a list is passed instead, it is assumed to be a list of constraints as part of a :py:class:`Placement` object. - networks (:py:class:`list`): List of network names or IDs to attach - the containers to. + networks (:py:class:`list`): List of network names or IDs or + :py:class:`NetworkAttachmentConfig` to attach the service to. force_update (int): A counter that triggers an update even if no relevant parameters have been changed. """ @@ -770,3 +770,21 @@ class Privileges(dict): if len(selinux_context) > 0: self['SELinuxContext'] = selinux_context + + +class NetworkAttachmentConfig(dict): + """ + Network attachment options for a service. + + Args: + target (str): The target network for attachment. + Can be a network name or ID. + aliases (:py:class:`list`): A list of discoverable alternate names + for the service. + options (:py:class:`dict`): Driver attachment options for the + network target. + """ + def __init__(self, target, aliases=None, options=None): + self['Target'] = target + self['Aliases'] = aliases + self['DriverOpts'] = options |
