From bf20436244410b8c9b35dfeb51882d550434c3f4 Mon Sep 17 00:00:00 2001 From: Daniel-Pivonka Date: Thu, 20 Feb 2020 10:22:35 -0500 Subject: [PATCH] mgr/orchestrator: add ability to parse placementspec from strings Signed-off-by: Daniel-Pivonka --- src/pybind/mgr/orchestrator/_interface.py | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 2f04de54e0004..ac079579b2c0b 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -1164,6 +1164,47 @@ class PlacementSpec(object): if self.count is not None and self.count <= 0: raise Exception("num/count must be > 1") + @classmethod + def from_strings(cls, strings): + # type: (Optional[List[str]]) -> PlacementSpec + """ + A single integer is parsed as a count: + >>> PlacementSpec.from_strings('3'.split()) + PlacementSpec(count=3) + A list of names is parsed as host specifications: + >>> PlacementSpec.from_strings('host1 host2'.split()) + PlacementSpec(label=[HostSpec(hostname='host1', network='', name=''), HostSpec(hostname='host2', network='', name='')]) + You can also prefix the hosts with a count as follows: + >>> PlacementSpec.from_strings('2 host1 host2'.split()) + PlacementSpec(label=[HostSpec(hostname='host1', network='', name=''), HostSpec(hostname='host2', network='', name='')], count=2) + You can spefify labels using `label: