Add pprint and pformat helper methods

Because of munch - using pprint directly is weird. Make a helper
method that does what the user expects.

Change-Id: I617b75034a59118c170895ad20b86fb8a1eab386
This commit is contained in:
Monty Taylor 2017-05-08 09:48:11 -04:00
parent 88ac7b484e
commit b6926bb8e5
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 24 additions and 0 deletions

View File

@ -95,6 +95,16 @@ def _make_unicode(input):
return str(input) return str(input)
def _dictify_resource(resource):
if isinstance(resource, list):
return [_dictify_resource(r) for r in resource]
else:
if hasattr(resource, 'toDict'):
return resource.toDict()
else:
return resource
def _filter_list(data, name_or_id, filters): def _filter_list(data, name_or_id, filters):
"""Filter a list by name/ID and arbitrary meta data. """Filter a list by name/ID and arbitrary meta data.

View File

@ -528,6 +528,20 @@ class OpenStackCloud(_normalize.Normalizer):
self._raw_clients['volume'] = self._get_raw_client('volume') self._raw_clients['volume'] = self._get_raw_client('volume')
return self._raw_clients['volume'] return self._raw_clients['volume']
def pprint(self, resource):
"""Wrapper aroud pprint that groks munch objects"""
# import late since this is a utility function
import pprint
new_resource = _utils._dictify_resource(resource)
pprint.pprint(new_resource)
def pformat(self, resource):
"""Wrapper aroud pformat that groks munch objects"""
# import late since this is a utility function
import pprint
new_resource = _utils._dictify_resource(resource)
return pprint.pformat(new_resource)
@property @property
def nova_client(self): def nova_client(self):
if self._nova_client is None: if self._nova_client is None: