diff options
author | Dan Smith <danms@us.ibm.com> | 2013-06-25 10:19:42 -0700 |
---|---|---|
committer | Dan Smith <danms@us.ibm.com> | 2013-06-27 06:38:16 -0700 |
commit | 7b7566bac8e2df14e17631980a7fbf2df68cf116 (patch) | |
tree | 1871bf93bbecc3876bd283aad32651a7f9098fb4 /openstack | |
parent | 42931aaee80a18c855a4b350342f7aa376eb024c (diff) | |
download | oslo-7b7566bac8e2df14e17631980a7fbf2df68cf116.tar.gz oslo-7b7566bac8e2df14e17631980a7fbf2df68cf116.tar.xz oslo-7b7566bac8e2df14e17631980a7fbf2df68cf116.zip |
Add netaddr.IPAddress support to to_primitive()
This enlightens jsonutils.to_primitive() about how to serialize
netaddr.IPAddress objects. Since these types are serializable
in their native form with just string coercion, just do that here.
Fixes bug 1195097
Change-Id: I358b0731e4d3774e5b36aefb5384fdfb75fd31b6
Diffstat (limited to 'openstack')
-rw-r--r-- | openstack/common/jsonutils.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/openstack/common/jsonutils.py b/openstack/common/jsonutils.py index bf23403..9c72376 100644 --- a/openstack/common/jsonutils.py +++ b/openstack/common/jsonutils.py @@ -41,6 +41,7 @@ import json import types import xmlrpclib +import netaddr import six from openstack.common import timeutils @@ -137,6 +138,8 @@ def to_primitive(value, convert_instances=False, convert_datetime=True, # Likely an instance of something. Watch for cycles. # Ignore class member vars. return recursive(value.__dict__, level=level + 1) + elif isinstance(value, netaddr.IPAddress): + return six.text_type(value) else: if any(test(value) for test in _nasty_type_tests): return six.text_type(value) |