Support for docker.types.Placement.MaxReplicas (new in API 1.40) in Docker Swarm Service

Signed-off-by: WojciechowskiPiotr <devel@it-playground.pl>
This commit is contained in:
Piotr Wojciechowski 2020-12-25 16:39:44 +01:00 committed by aiordache
parent 3679ffcca8
commit b701d5c999
2 changed files with 8 additions and 1 deletions

View File

@ -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',
]

View File

@ -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: