[openstack-dev] [charms] evolving the ha interface type

Dmitrii Shcherbakov dmitrii.shcherbakov at canonical.com
Tue Nov 28 20:50:50 UTC 2017

Hi James,

The side effect of using JSON is that we will lose type information:

In [0]: json.loads(json.dumps([{1: 2}]))
Out[0]: [{'1': 2}]

In [1]: ast.literal_eval(repr([{1: 2}]))
Out[1]: [{1: 2}]

This is a hard requirement in the JSON spec:

"An object structure is represented as a pair of curly brackets
surrounding zero or more name/value pairs (or members).  A name is
a string. "

I wonder if we could use some type-aware serialization format but I do
not have any suggestions without trade-offs because we need to keep in
mind that, in general, charms may not be python charms, may run on
hosts with different protocol parsing libraries etc.

If we only cared about python I would suggest using "pickle" but this
is not universal and not human-readable:

"JSON, by default, can only represent a subset of the Python built-in
types, and no custom classes; pickle can represent an extremely large
number of Python types"

JSON has an advantage of being readable as opposed to a binary protocol
so we can explore what's available in relation data by doing relation-
get without additional tools. It is also ubiquitous so we don't have to
worry about spec changes, parsing bugs and other potential problems.

Thanks for bringing this topic up.

Dmitrii Shcherbakov

More information about the OpenStack-dev mailing list