[kea-dev] Converting configuration back to JSON (unparsing)

Tomek Mrugalski tomasz at isc.org
Thu Feb 23 15:44:39 UTC 2017


One of the features of upcoming 1.2 release will be the ability to
retrieve (get-config command) and store (write-config command) current
configuration. This problem is currently scoped to DHCPv4 and DHCPv6,
but the solution should also cover D2 and CA if possible.

There was some discussion in #1205 (http://kea.isc.org/ticket/1205), in
particular Francis said in comment 17:

---------------------------
To summary the current point of the discussion:

- the textual configuration T is a string in JSON format
- the configuration itself is a ConstElementPtr C
- the configuration state is a tree of Cfg structures SrvConfigPtr S
- the parser is a function: C -> S
- a valid configuration is a configuration which can be parsed without
throwing an exception
- we want to define an unparse function: S -> C with the property:

   for all valid C parse(unparse(parse(C)) == parse(C)

Even it is not strictly needed a basic JSON pretty printer should output
C in a human readable form (this applies to C -> T)
--------------------------

I discussed this with Thomas and we're leaning towards the unparse
method to return C. The actual method should have the following interface:

ElementPtr toElement() const;

The reason why it should return ElementPtr rather than ConstElementPtr
is that whoever called this, may want to further edit the configuration.
We don't have that capability now, but it seems likely that one day we
will get a hook that handles configuration.

Also, usage of "parser" and "parse" words is overloaded in Kea project.
We use the same word to describe text to Element tree conversion (done
with bison) and also to describe Element tree to configuration
structures (done with SimpleParser derivatives). As such, unparse would
be confusing whether it undoes the second or both steps. Therefore
calling the method toElement() seems better.

Finally, converting from Element to text is trivial, because there are
Element::str() and << operators defined.

Any thoughts? Comments? If I don't hear any objections in couple days,
the 1205 ticket will be closed and we'll start with the implementation.

Tomek


More information about the kea-dev mailing list