# in the orchestrator backend.
self.hosts = hosts
- def __repr__(self):
+ def pretty_str(self):
kv = []
if self.count:
kv.append('count=%d' % self.count)
if self.label:
kv.append('label=%s' % self.label)
if self.hosts:
- kv.append('hosts=%s' % self.hosts)
+ kv.append('hosts=%s' % ','.join([str(h) for h in self.hosts]))
if self.all_hosts:
kv.append('all=true')
- return "PlacementSpec(%s)" % (' '.join(kv))
+ return ' '.join(kv)
+
+ def __repr__(self):
+ return "PlacementSpec(%s)" % self.pretty_str()
@classmethod
def from_dict(cls, data):
else:
now = datetime.datetime.utcnow()
table = PrettyTable(
- ['NAME', 'RUNNING', 'REFRESHED', 'IMAGE NAME', 'IMAGE ID', 'SPEC'],
+ ['NAME', 'RUNNING', 'REFRESHED', 'IMAGE NAME', 'IMAGE ID', 'SPEC', 'PLACEMENT'],
border=False)
table.align['NAME'] = 'l'
table.align['RUNNING'] = 'r'
table.align['IMAGE NAME'] = 'l'
table.align['IMAGE ID'] = 'l'
table.align['SPEC'] = 'l'
+ table.align['PLACEMENT'] = 'l'
table.left_padding_width = 0
table.right_padding_width = 2
for s in sorted(services, key=lambda s: s.service_name):
ukn(s.container_image_name),
ukn(s.container_image_id)[0:12],
'present' if s.spec else '-',
+ s.spec.placement.pretty_str() if s.spec else '-',
))
return HandleCommandResult(stdout=table.get_string())
[
('', "PlacementSpec()"),
("3", "PlacementSpec(count=3)"),
- ("host1 host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
- ('2 host1 host2', "PlacementSpec(count=2 hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"),
+ ("host1 host2", "PlacementSpec(hosts=host1,host2)"),
+ ("host1=a host2=b", "PlacementSpec(hosts=host1=a,host2=b)"),
+ ("host1:1.2.3.4=a host2:1.2.3.5=b", "PlacementSpec(hosts=host1:1.2.3.4=a,host2:1.2.3.5=b)"),
+ ('2 host1 host2', "PlacementSpec(count=2 hosts=host1,host2)"),
('label:foo', "PlacementSpec(label=foo)"),
('3 label:foo', "PlacementSpec(count=3 label=foo)"),
('*', 'PlacementSpec(all=true)'),