From 3d3e1f69a3aefbda3eacebf55ff337228a8f564f Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Mon, 9 Mar 2020 17:08:57 +0100 Subject: [PATCH] python-common: Add `host_pattern` to `PlacementSpec.from_string()` Signed-off-by: Sebastian Wagner --- .../ceph/deployment/service_spec.py | 42 +++++++++++++++---- .../ceph/tests/test_service_spec.py | 18 ++++---- src/python-common/tox.ini | 4 +- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/python-common/ceph/deployment/service_spec.py b/src/python-common/ceph/deployment/service_spec.py index 481bad7254cb8..35d01facc4ba2 100644 --- a/src/python-common/ceph/deployment/service_spec.py +++ b/src/python-common/ceph/deployment/service_spec.py @@ -159,7 +159,18 @@ class PlacementSpec(object): return ' '.join(kv) def __repr__(self): - return "PlacementSpec(%s)" % self.pretty_str() + kv = [] + if self.count: + kv.append('count=%d' % self.count) + if self.label: + kv.append('label=%s' % repr(self.label)) + if self.hosts: + kv.append('hosts={!r}'.format(self.hosts)) + if self.all_hosts: + kv.append('all_hosts=True') + if self.host_pattern: + kv.append('host_pattern={!r}'.format(self.host_pattern)) + return "PlacementSpec(%s)" % ', '.join(kv) @classmethod def from_json(cls, data): @@ -196,18 +207,29 @@ class PlacementSpec(object): A single integer is parsed as a count: >>> PlacementSpec.from_string('3') PlacementSpec(count=3) + A list of names is parsed as host specifications: >>> PlacementSpec.from_string('host1 host2') - PlacementSpec(label=[HostSpec(hostname='host1', network='', name=''), HostSpec(hostname='host2', network='', name='')]) + PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacemen\ +tSpec(hostname='host2', network='', name='')]) + You can also prefix the hosts with a count as follows: >>> PlacementSpec.from_string('2 host1 host2') - PlacementSpec(label=[HostSpec(hostname='host1', network='', name=''), HostSpec(hostname='host2', network='', name='')], count=2) + PlacementSpec(count=2, hosts=[HostPlacementSpec(hostname='host1', network='', name=''), Hos\ +tPlacementSpec(hostname='host2', network='', name='')]) + You can spefify labels using `label: