From b701d5c9991b23cef4b3383827327cf5f85d01d4 Mon Sep 17 00:00:00 2001 From: Piotr Wojciechowski Date: Fri, 25 Dec 2020 16:39:44 +0100 Subject: [PATCH] Support for docker.types.Placement.MaxReplicas (new in API 1.40) in Docker Swarm Service Signed-off-by: WojciechowskiPiotr --- docker/models/services.py | 3 +++ docker/types/services.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docker/models/services.py b/docker/models/services.py index a35687b3..a29ff132 100644 --- a/docker/models/services.py +++ b/docker/models/services.py @@ -157,6 +157,8 @@ class ServiceCollection(Collection): constraints. preferences (list of tuple): :py:class:`~docker.types.Placement` preferences. + maxreplicas (int): :py:class:`~docker.types.Placement` maxreplicas + or (int) representing maximum number of replicas per node. platforms (list of tuple): A list of platform constraints expressed as ``(arch, os)`` tuples. container_labels (dict): Labels to apply to the container. @@ -319,6 +321,7 @@ PLACEMENT_KWARGS = [ 'constraints', 'preferences', 'platforms', + 'maxreplicas', ] diff --git a/docker/types/services.py b/docker/types/services.py index 05dda15d..3cde8592 100644 --- a/docker/types/services.py +++ b/docker/types/services.py @@ -659,10 +659,12 @@ class Placement(dict): are provided in order from highest to lowest precedence and are expressed as ``(strategy, descriptor)`` tuples. See :py:class:`PlacementPreference` for details. + maxreplicas (int): Maximum number of replicas per node platforms (:py:class:`list` of tuple): A list of platforms expressed as ``(arch, os)`` tuples """ - def __init__(self, constraints=None, preferences=None, platforms=None): + def __init__(self, constraints=None, preferences=None, maxreplicas=None, + platforms=None): if constraints is not None: self['Constraints'] = constraints if preferences is not None: @@ -671,6 +673,8 @@ class Placement(dict): if isinstance(pref, tuple): pref = PlacementPreference(*pref) self['Preferences'].append(pref) + if maxreplicas is not None: + self['MaxReplicas'] = maxreplicas if platforms: self['Platforms'] = [] for plat in platforms: