Add curly config renderer
Open, NormalPublic


Since we have a parser, we need a renderer too.

Some considerations:

First, the renderer should be usable both with and without a reference tree. The first reason is that migration scripts that are used to convert config from an old version to a new one in case of forward-incompatible syntax changes have to work with configs that are, from the current reference tree's point of view, invalid, so they have to be standalone. The second reason is that people may want to use the vyconf library for writing utilities such as config analyzers and convertors from other systems, and they may want them to be usable outside the appliance, and admin's desktop obviously has no reason to have interface definitions from the appliance on it. Configs formatted without the help of reference tree will look less pretty of course, but the parser doesn't care.

The renderer should have the following type:

val render : ?reftree:Reference_tree.t  -> ?indent:int ->?cmp:('a -> 'a -> int) -> ?showephemeral:bool -> ?showinactive:bool -> Config_tree.t -> string

If the reference tree is given, then:
Tag nodes and their immediate children should appear on the same line, together, separated by space, that is, assuming "ethernet" is a tag node, output should look like "interfaces { ethernet eth0 { ... } ethernet eth1 { } }" as opposed to "interfaces { ethernet { eth0 { } eth1 { ... } }".
Nodes that are not supposed to keep child order (i.e. "get_keep_order rt path" evaluates to false) should be sorted by name, using the function given in the ?cmp argument (until we implement "intuitive" comparison that doesn't put eth10 before eth9, we can use that does lexicographic sort for strings).

If reference tree is not given, then all non-leaf nodes should be rendered as normal nodes, and all children should appear in the same order as in the config tree.

If showephemeral=false, then ephemeral nodes should be excluded from the output. if showinactive=false, then inactive nodes should also be excluded.

The indent argument defines the number of spaces per indentation level.


Difficulty level
Normal (likely a few hours)
dmbaturin created this object with edit policy "Subscribers".
shon claimed this task.Jan 18 2017, 3:23 AM

Following a discussion with @dmbaturin in #vyos, I'm to work on this puppy.

shon added a comment.EditedFeb 8 2017, 1:03 PM
This comment has been deleted.