diff --git a/cinderclient/openstack/common/apiclient/base.py b/cinderclient/openstack/common/apiclient/base.py index bc4a1588b..82670aa56 100644 --- a/cinderclient/openstack/common/apiclient/base.py +++ b/cinderclient/openstack/common/apiclient/base.py @@ -24,6 +24,7 @@ Base utilities to build API operation managers and objects on top of. # pylint: disable=E1102 import abc +import copy import six from six.moves.urllib import parse @@ -489,3 +490,6 @@ class Resource(object): def set_loaded(self, val): self._loaded = val + + def to_dict(self): + return copy.deepcopy(self._info) diff --git a/cinderclient/tests/unit/test_base.py b/cinderclient/tests/unit/test_base.py index e4eba0dcd..105d9b7c0 100644 --- a/cinderclient/tests/unit/test_base.py +++ b/cinderclient/tests/unit/test_base.py @@ -59,3 +59,7 @@ class BaseTest(utils.TestCase): self.assertRaises(exceptions.NotFound, cs.volumes.find, vegetable='carrot') + + def test_to_dict(self): + r1 = base.Resource(None, {'id': 1, 'name': 'hi'}) + self.assertEqual({'id': 1, 'name': 'hi'}, r1.to_dict())