@@ -648,18 +648,24 @@ class Placement(dict):
648
648
Placement constraints to be used as part of a :py:class:`TaskTemplate`
649
649
650
650
Args:
651
- constraints (:py:class:`list`): A list of constraints
652
- preferences (:py:class:`list`): Preferences provide a way to make
653
- the scheduler aware of factors such as topology. They are
654
- provided in order from highest to lowest precedence.
655
- platforms (:py:class:`list`): A list of platforms expressed as
656
- ``(arch, os)`` tuples
651
+ constraints (:py:class:`list` of str): A list of constraints
652
+ preferences (:py:class:`list` of tuple): Preferences provide a way
653
+ to make the scheduler aware of factors such as topology. They
654
+ are provided in order from highest to lowest precedence and
655
+ are expressed as ``(strategy, descriptor)`` tuples. See
656
+ :py:class:`PlacementPreference` for details.
657
+ platforms (:py:class:`list` of tuple): A list of platforms
658
+ expressed as ``(arch, os)`` tuples
657
659
"""
658
660
def __init__ (self , constraints = None , preferences = None , platforms = None ):
659
661
if constraints is not None :
660
662
self ['Constraints' ] = constraints
661
663
if preferences is not None :
662
- self ['Preferences' ] = preferences
664
+ self ['Preferences' ] = []
665
+ for pref in preferences :
666
+ if isinstance (pref , tuple ):
667
+ pref = PlacementPreference (* pref )
668
+ self ['Preferences' ].append (pref )
663
669
if platforms :
664
670
self ['Platforms' ] = []
665
671
for plat in platforms :
@@ -668,6 +674,27 @@ def __init__(self, constraints=None, preferences=None, platforms=None):
668
674
})
669
675
670
676
677
+ class PlacementPreference (dict ):
678
+ """
679
+ Placement preference to be used as an element in the list of
680
+ preferences for :py:class:`Placement` objects.
681
+
682
+ Args:
683
+ strategy (string): The placement strategy to implement. Currently,
684
+ the only supported strategy is ``spread``.
685
+ descriptor (string): A label descriptor. For the spread strategy,
686
+ the scheduler will try to spread tasks evenly over groups of
687
+ nodes identified by this label.
688
+ """
689
+ def __init__ (self , strategy , descriptor ):
690
+ if strategy != 'spread' :
691
+ raise errors .InvalidArgument (
692
+ 'PlacementPreference strategy value is invalid ({}):'
693
+ ' must be "spread".' .format (strategy )
694
+ )
695
+ self ['SpreadOver' ] = descriptor
696
+
697
+
671
698
class DNSConfig (dict ):
672
699
"""
673
700
Specification for DNS related configurations in resolver configuration
0 commit comments