From: Daniel-Pivonka Date: Thu, 20 Feb 2020 15:22:35 +0000 (-0500) Subject: mgr/orchestrator: add ability to parse placementspec from strings X-Git-Tag: v15.1.1~337^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F33441%2Fhead;p=ceph.git mgr/orchestrator: add ability to parse placementspec from strings Signed-off-by: Daniel-Pivonka --- diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 2f04de54e000..ac079579b2c0 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: