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:
parent
88ac7b484e
commit
b6926bb8e5
@ -95,6 +95,16 @@ def _make_unicode(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):
|
||||
"""Filter a list by name/ID and arbitrary meta data.
|
||||
|
||||
|
@ -528,6 +528,20 @@ class OpenStackCloud(_normalize.Normalizer):
|
||||
self._raw_clients['volume'] = self._get_raw_client('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
|
||||
def nova_client(self):
|
||||
if self._nova_client is None:
|
||||
|
Loading…
Reference in New Issue
Block a user