Comment 2 for bug 1314018

Revision history for this message
John Stanford (jxstanford) wrote :

My tendency would be to keep the __repr__ simple, and just use the name. This aligns with the pattern used by nova:

In [64]: c.services.list()
Out[64]:
[<Service: nova-consoleauth>,
 <Service: nova-conductor>,
 <Service: nova-scheduler>,
 <Service: nova-compute>,
 <Service: nova-cert>,
 <Service: nova-console>,
 <Service: nova-compute>]

Keystone has gone exactly the opposite way and uses what looks like the entire dict. I think that's way overkill. If you want the detail, process the list:

In [69]: c.services.list()
Out[69]:
[<Service {u'type': u'image', u'description': u'Openstack Image Service', u'enabled': True, u'id': u'0b0fe44b60564da492070941db2f160f', u'name': u'glance'}>,
 <Service {u'type': u'metering', u'description': u'Openstack Metering Service', u'enabled': True, u'id': u'3417cbf8ca7c40c69a191f9610d0ef30', u'name': u'ceilometer'}>,
 <Service {u'type': u'volume', u'description': u'Cinder Service', u'enabled': True, u'id': u'3833e9efab5d413e9588f1a33f61a11d', u'name': u'cinder'}>,
 <Service {u'type': u'ec2', u'description': u'EC2 Service', u'enabled': True, u'id': u'39130798096b4214980bf8aa8bc66e5a', u'name': u'nova_ec2'}>,
 <Service {u'type': u'object-store', u'description': u'Openstack Object-Store Service', u'enabled': True, u'id': u'6fc024ea4317407f8e32b80847e3bbff', u'name': u'swift'}>,
 <Service {u'type': u'network', u'description': u'Neutron Networking Service', u'enabled': True, u'id': u'7b8eb446fff84f11b6bb648738eee5c1', u'name': u'neutron'}>,
 <Service {u'type': u's3', u'description': u'Openstack S3 Service', u'enabled': True, u'id': u'99e6ab7404a34974af0b61cb1bed9e57', u'name': u'swift_s3'}>,
 <Service {u'type': u'orchestration', u'description': u'Openstack Orchestration Service', u'enabled': True, u'id': u'c8d574752dfa4c9e979e73aa99c9fdf6', u'name': u'heat'}>,
 <Service {u'type': u'identity', u'description': u'OpenStack Identity Service', u'enabled': True, u'id': u'd931233edecd460fb7e988803062271e', u'name': u'keystone'}>,
 <Service {u'type': u'compute', u'description': u'Openstack Compute Service', u'enabled': True, u'id': u'efb8e2617e8c4ac1bed2aa1072aa6e42', u'name': u'nova'}>]

I guess the question I would ask is are you going to use the repr for decision making via the API, and the answer I lean toward is no. In that case, does the addition of a hostname in __repr__ provide any value over something like this in your code which doesn't rely on a magic method directly, rather uses the API as intended:

[str(s['name'] + "@" + s['host'] for s in c.services.list()]

I have a patch submitted that just uses the binary field on https://bugs.launchpad.net/python-cinderclient/+bug/1315606. I'm curious why this got a new bug number. I'm relatively new to the process, so if anyone could help me understand, I would appreciate. Should one of them be marked as a duplicate?