diff --git a/shade/_utils.py b/shade/_utils.py index 76b9f2ed3..340b63c08 100644 --- a/shade/_utils.py +++ b/shade/_utils.py @@ -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. diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index aa845383c..8a5ca5457 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -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: